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
  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: /**
 19:  * Class method description.
 20:  *
 21:  * @author     David Grudl
 22:  *
 23:  * @method Method setName(string $name)
 24:  * @method Method setBody(string $body)
 25:  * @method Method setStatic(bool $on)
 26:  * @method Method setVisibility(string $access)
 27:  * @method Method setFinal(bool $on)
 28:  * @method Method setAbstract(bool $on)
 29:  * @method Method setReturnReference(bool $on)
 30:  * @method Method addDocument(string $doc)
 31:  */
 32: class Method extends Nette\Object
 33: {
 34:     /** @var string */
 35:     public $name;
 36: 
 37:     /** @var array of name => Parameter */
 38:     public $parameters = array();
 39: 
 40:     /** @var array of name => bool */
 41:     public $uses = array();
 42: 
 43:     /** @var string|FALSE */
 44:     public $body;
 45: 
 46:     /** @var bool */
 47:     public $static;
 48: 
 49:     /** @var string  public|protected|private or none */
 50:     public $visibility;
 51: 
 52:     /** @var bool */
 53:     public $final;
 54: 
 55:     /** @var bool */
 56:     public $abstract;
 57: 
 58:     /** @var bool */
 59:     public $returnReference;
 60: 
 61:     /** @var array of string */
 62:     public $documents = array();
 63: 
 64: 
 65:     /** @return Parameter */
 66:     public function addParameter($name, $defaultValue = NULL)
 67:     {
 68:         $param = new Parameter;
 69:         if (func_num_args() > 1) {
 70:             $param->setOptional(TRUE)->setDefaultValue($defaultValue);
 71:         }
 72:         return $this->parameters[] = $param->setName($name);
 73:     }
 74: 
 75: 
 76: 
 77:     /** @return Parameter */
 78:     public function addUse($name)
 79:     {
 80:         $param = new Parameter;
 81:         return $this->uses[] = $param->setName($name);
 82:     }
 83: 
 84: 
 85: 
 86:     /** @return Method */
 87:     public function setBody($statement, array $args = NULL)
 88:     {
 89:         $this->body = func_num_args() > 1 ? Helpers::formatArgs($statement, $args) : $statement;
 90:         return $this;
 91:     }
 92: 
 93: 
 94: 
 95:     /** @return Method */
 96:     public function addBody($statement, array $args = NULL)
 97:     {
 98:         $this->body .= (func_num_args() > 1 ? Helpers::formatArgs($statement, $args) : $statement) . "\n";
 99:         return $this;
100:     }
101: 
102: 
103: 
104:     public function __call($name, $args)
105:     {
106:         return Nette\ObjectMixin::callProperty($this, $name, $args);
107:     }
108: 
109: 
110: 
111:     /** @return string  PHP code */
112:     public function __toString()
113:     {
114:         $parameters = array();
115:         foreach ($this->parameters as $param) {
116:             $parameters[] = ($param->typeHint ? $param->typeHint . ' ' : '')
117:                 . ($param->reference ? '&' : '')
118:                 . '$' . $param->name
119:                 . ($param->optional ? ' = ' . Helpers::dump($param->defaultValue) : '');
120:         }
121:         $uses = array();
122:         foreach ($this->uses as $param) {
123:             $uses[] = ($param->reference ? '&' : '') . '$' . $param->name;
124:         }
125:         return ($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '')
126:             . ($this->abstract ? 'abstract ' : '')
127:             . ($this->final ? 'final ' : '')
128:             . ($this->visibility ? $this->visibility . ' ' : '')
129:             . ($this->static ? 'static ' : '')
130:             . 'function'
131:             . ($this->returnReference ? ' &' : '')
132:             . ($this->name ? ' ' . $this->name : '')
133:             . '(' . implode(', ', $parameters) . ')'
134:             . ($this->uses ? ' use (' . implode(', ', $uses) . ')' : '')
135:             . ($this->abstract || $this->body === FALSE ? ';'
136:                 : ($this->name ? "\n" : ' ') . "{\n" . Nette\Utils\Strings::indent(trim($this->body), 1) . "\n}");
137:     }
138: 
139: }
140: 
Nette Framework 2.0.0 API API documentation generated by ApiGen 2.7.0