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
  • PHP

Classes

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