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

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