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/Interface/Trait description.
 20:  *
 21:  * @author     David Grudl
 22:  *
 23:  * @method ClassType setName(string $name)
 24:  * @method ClassType setType(string $type)
 25:  * @method ClassType setFinal(bool $on)
 26:  * @method ClassType setAbstract(bool $on)
 27:  * @method ClassType addExtend(string $class)
 28:  * @method ClassType addImplement(string $interface)
 29:  * @method ClassType addTrait(string $trait)
 30:  * @method ClassType addDocument(string $doc)
 31:  */
 32: class ClassType extends Nette\Object
 33: {
 34:     /** @var string */
 35:     public $name;
 36: 
 37:     /** @var string  class|interface|trait */
 38:     public $type = 'class';
 39: 
 40:     /** @var bool */
 41:     public $final;
 42: 
 43:     /** @var bool */
 44:     public $abstract;
 45: 
 46:     /** @var string[] */
 47:     public $extends = array();
 48: 
 49:     /** @var string[] */
 50:     public $implements = array();
 51: 
 52:     /** @var string[] */
 53:     public $traits = array();
 54: 
 55:     /** @var string[] */
 56:     public $documents = array();
 57: 
 58:     /** @var mixed[] name => value */
 59:     public $consts = array();
 60: 
 61:     /** @var Property[] name => Property */
 62:     public $properties = array();
 63: 
 64:     /** @var Method[] name => Method */
 65:     public $methods = array();
 66: 
 67: 
 68:     public function __construct($name)
 69:     {
 70:         $this->name = $name;
 71:     }
 72: 
 73: 
 74: 
 75:     /** @return ClassType */
 76:     public function addConst($name, $value)
 77:     {
 78:         $this->consts[$name] = $value;
 79:         return $this;
 80:     }
 81: 
 82: 
 83: 
 84:     /** @return Property */
 85:     public function addProperty($name, $value = NULL)
 86:     {
 87:         $property = new Property;
 88:         return $this->properties[$name] = $property->setName($name)->setValue($value);
 89:     }
 90: 
 91: 
 92: 
 93:     /** @return Method */
 94:     public function addMethod($name)
 95:     {
 96:         $method = new Method;
 97:         if ($this->type === 'interface') {
 98:             $method->setVisibility('')->setBody(FALSE);
 99:         } else {
100:             $method->setVisibility('public');
101:         }
102:         return $this->methods[$name] = $method->setName($name);
103:     }
104: 
105: 
106: 
107:     public function __call($name, $args)
108:     {
109:         return Nette\ObjectMixin::callProperty($this, $name, $args);
110:     }
111: 
112: 
113: 
114:     /** @return string  PHP code */
115:     public function __toString()
116:     {
117:         $consts = array();
118:         foreach ($this->consts as $name => $value) {
119:             $consts[] = "const $name = " . Helpers::dump($value) . ";\n";
120:         }
121:         $properties = array();
122:         foreach ($this->properties as $property) {
123:             $properties[] = ($property->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $property->documents)) . "\n */\n" : '')
124:                 . $property->visibility . ($property->static ? ' static' : '') . ' $' . $property->name
125:                 . ($property->value === NULL ? '' : ' = ' . Helpers::dump($property->value))
126:                 . ";\n";
127:         }
128:         return Nette\Utils\Strings::normalize(
129:             ($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '')
130:             . ($this->abstract ? 'abstract ' : '')
131:             . ($this->final ? 'final ' : '')
132:             . $this->type . ' '
133:             . $this->name . ' '
134:             . ($this->extends ? 'extends ' . implode(', ', (array) $this->extends) . ' ' : '')
135:             . ($this->implements ? 'implements ' . implode(', ', (array) $this->implements) . ' ' : '')
136:             . "\n{\n\n"
137:             . Nette\Utils\Strings::indent(
138:                 ($this->traits ? "use " . implode(', ', (array) $this->traits) . ";\n\n" : '')
139:                 . ($this->consts ? implode('', $consts) . "\n\n" : '')
140:                 . ($this->properties ? implode("\n", $properties) . "\n\n" : '')
141:                 . implode("\n\n\n", $this->methods), 1)
142:             . "\n\n}") . "\n";
143:     }
144: 
145: }
146: 
Nette Framework 2.0.6 API API documentation generated by ApiGen 2.7.0