Packages

  • 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

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