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

Classes

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