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

Classes

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