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