Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • none

Classes

  • ClassType
  • Helpers
  • Method
  • Parameter
  • PhpLiteral
  • Property
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\Utils\PhpGenerator;
  9: 
 10: use Nette;
 11: 
 12: 
 13: /**
 14:  * Class method description.
 15:  *
 16:  * @author     David Grudl
 17:  *
 18:  * @method Method setName(string $name)
 19:  * @method Method setBody(string $body)
 20:  * @method Method setStatic(bool $on)
 21:  * @method Method setVisibility(string $access)
 22:  * @method Method setFinal(bool $on)
 23:  * @method Method setAbstract(bool $on)
 24:  * @method Method setReturnReference(bool $on)
 25:  * @method Method addDocument(string $doc)
 26:  */
 27: class Method extends Nette\Object
 28: {
 29:     /** @var string */
 30:     public $name;
 31: 
 32:     /** @var array of name => Parameter */
 33:     public $parameters = array();
 34: 
 35:     /** @var array of name => bool */
 36:     public $uses = array();
 37: 
 38:     /** @var string|FALSE */
 39:     public $body;
 40: 
 41:     /** @var bool */
 42:     public $static;
 43: 
 44:     /** @var string  public|protected|private or none */
 45:     public $visibility;
 46: 
 47:     /** @var bool */
 48:     public $final;
 49: 
 50:     /** @var bool */
 51:     public $abstract;
 52: 
 53:     /** @var bool */
 54:     public $returnReference;
 55: 
 56:     /** @var array of string */
 57:     public $documents = array();
 58: 
 59: 
 60:     /** @return Parameter */
 61:     public function addParameter($name, $defaultValue = NULL)
 62:     {
 63:         $param = new Parameter;
 64:         if (func_num_args() > 1) {
 65:             $param->setOptional(TRUE)->setDefaultValue($defaultValue);
 66:         }
 67:         return $this->parameters[] = $param->setName($name);
 68:     }
 69: 
 70: 
 71:     /** @return Parameter */
 72:     public function addUse($name)
 73:     {
 74:         $param = new Parameter;
 75:         return $this->uses[] = $param->setName($name);
 76:     }
 77: 
 78: 
 79:     /** @return Method */
 80:     public function setBody($statement, array $args = NULL)
 81:     {
 82:         $this->body = func_num_args() > 1 ? Helpers::formatArgs($statement, $args) : $statement;
 83:         return $this;
 84:     }
 85: 
 86: 
 87:     /** @return Method */
 88:     public function addBody($statement, array $args = NULL)
 89:     {
 90:         $this->body .= (func_num_args() > 1 ? Helpers::formatArgs($statement, $args) : $statement) . "\n";
 91:         return $this;
 92:     }
 93: 
 94: 
 95:     public function __call($name, $args)
 96:     {
 97:         return Nette\ObjectMixin::callProperty($this, $name, $args);
 98:     }
 99: 
100: 
101:     /** @return string  PHP code */
102:     public function __toString()
103:     {
104:         $parameters = array();
105:         foreach ($this->parameters as $param) {
106:             $parameters[] = ($param->typeHint ? $param->typeHint . ' ' : '')
107:                 . ($param->reference ? '&' : '')
108:                 . '$' . $param->name
109:                 . ($param->optional ? ' = ' . Helpers::dump($param->defaultValue) : '');
110:         }
111:         $uses = array();
112:         foreach ($this->uses as $param) {
113:             $uses[] = ($param->reference ? '&' : '') . '$' . $param->name;
114:         }
115:         return ($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '')
116:             . ($this->abstract ? 'abstract ' : '')
117:             . ($this->final ? 'final ' : '')
118:             . ($this->visibility ? $this->visibility . ' ' : '')
119:             . ($this->static ? 'static ' : '')
120:             . 'function'
121:             . ($this->returnReference ? ' &' : '')
122:             . ($this->name ? ' ' . $this->name : '')
123:             . '(' . implode(', ', $parameters) . ')'
124:             . ($this->uses ? ' use (' . implode(', ', $uses) . ')' : '')
125:             . ($this->abstract || $this->body === FALSE ? ';'
126:                 : ($this->name ? "\n" : ' ') . "{\n" . Nette\Utils\Strings::indent(trim($this->body), 1) . "\n}");
127:     }
128: 
129: }
130: 
Nette 2.0 API documentation generated by ApiGen 2.8.0