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
  • 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 NPhpClassType extends NObject
 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 NPhpProperty[] name => Property */
 60:     public $properties = array();
 61: 
 62:     /** @var NPhpMethod[] name => Method */
 63:     public $methods = array();
 64: 
 65: 
 66:     public function __construct($name = NULL)
 67:     {
 68:         $this->name = $name;
 69:     }
 70: 
 71: 
 72:     /** @return NPhpClassType */
 73:     public function addConst($name, $value)
 74:     {
 75:         $this->consts[$name] = $value;
 76:         return $this;
 77:     }
 78: 
 79: 
 80:     /** @return NPhpProperty */
 81:     public function addProperty($name, $value = NULL)
 82:     {
 83:         $property = new NPhpProperty;
 84:         return $this->properties[$name] = $property->setName($name)->setValue($value);
 85:     }
 86: 
 87: 
 88:     /** @return NPhpMethod */
 89:     public function addMethod($name)
 90:     {
 91:         $method = new NPhpMethod;
 92:         if ($this->type === 'interface') {
 93:             $method->setVisibility('')->setBody(FALSE);
 94:         } else {
 95:             $method->setVisibility('public');
 96:         }
 97:         return $this->methods[$name] = $method->setName($name);
 98:     }
 99: 
100: 
101:     public function __call($name, $args)
102:     {
103:         return NObjectMixin::callProperty($this, $name, $args);
104:     }
105: 
106: 
107:     /** @return string  PHP code */
108:     public function __toString()
109:     {
110:         $consts = array();
111:         foreach ($this->consts as $name => $value) {
112:             $consts[] = "const $name = " . NPhpHelpers::dump($value) . ";\n";
113:         }
114:         $properties = array();
115:         foreach ($this->properties as $property) {
116:             $properties[] = ($property->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $property->documents)) . "\n */\n" : '')
117:                 . $property->visibility . ($property->static ? ' static' : '') . ' $' . $property->name
118:                 . ($property->value === NULL ? '' : ' = ' . NPhpHelpers::dump($property->value))
119:                 . ";\n";
120:         }
121:         return NStrings::normalize(
122:             ($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '')
123:             . ($this->abstract ? 'abstract ' : '')
124:             . ($this->final ? 'final ' : '')
125:             . $this->type . ' '
126:             . $this->name . ' '
127:             . ($this->extends ? 'extends ' . implode(', ', (array) $this->extends) . ' ' : '')
128:             . ($this->implements ? 'implements ' . implode(', ', (array) $this->implements) . ' ' : '')
129:             . "\n{\n\n"
130:             . NStrings::indent(
131:                 ($this->traits ? "use " . implode(', ', (array) $this->traits) . ";\n\n" : '')
132:                 . ($this->consts ? implode('', $consts) . "\n\n" : '')
133:                 . ($this->properties ? implode("\n", $properties) . "\n\n" : '')
134:                 . implode("\n\n\n", $this->methods), 1)
135:             . "\n\n}") . "\n";
136:     }
137: 
138: }
139: 
Nette Framework 2.0.13 (for PHP 5.2, prefixed) API API documentation generated by ApiGen 2.8.0