Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
    • Reflection
    • Security
    • Utils
  • none
  • Tracy
    • Bridges
      • Nette

Classes

  • ClassType
  • Helpers
  • Method
  • Parameter
  • PhpFile
  • PhpLiteral
  • PhpNamespace
  • 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 (https://davidgrudl.com)
  6:  */
  7: 
  8: namespace Nette\PhpGenerator;
  9: 
 10: use Nette;
 11: 
 12: 
 13: /**
 14:  * Class property description.
 15:  */
 16: class Property extends Nette\Object
 17: {
 18:     /** @var string */
 19:     private $name = '';
 20: 
 21:     /** @var mixed */
 22:     public $value;
 23: 
 24:     /** @var bool */
 25:     private $static = FALSE;
 26: 
 27:     /** @var string  public|protected|private */
 28:     private $visibility = 'public';
 29: 
 30:     /** @var string[] */
 31:     private $documents = array();
 32: 
 33: 
 34:     /**
 35:      * @return self
 36:      */
 37:     public static function from(\ReflectionProperty $from)
 38:     {
 39:         $prop = new static($from->getName());
 40:         $defaults = $from->getDeclaringClass()->getDefaultProperties();
 41:         $prop->value = isset($defaults[$prop->name]) ? $defaults[$prop->name] : NULL;
 42:         $prop->static = $from->isStatic();
 43:         $prop->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : 'public');
 44:         $prop->documents = $from->getDocComment() ? array(preg_replace('#^\s*\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
 45:         return $prop;
 46:     }
 47: 
 48: 
 49:     /**
 50:      * @param  string  without $
 51:      */
 52:     public function __construct($name = '')
 53:     {
 54:         $this->setName($name);
 55:     }
 56: 
 57: 
 58:     /**
 59:      * @param  string  without $
 60:      * @return self
 61:      */
 62:     public function setName($name)
 63:     {
 64:         $this->name = (string) $name;
 65:         return $this;
 66:     }
 67: 
 68: 
 69:     /**
 70:      * @return string
 71:      */
 72:     public function getName()
 73:     {
 74:         return $this->name;
 75:     }
 76: 
 77: 
 78:     /**
 79:      * @return self
 80:      */
 81:     public function setValue($val)
 82:     {
 83:         $this->value = $val;
 84:         return $this;
 85:     }
 86: 
 87: 
 88:     /**
 89:      * @return mixed
 90:      */
 91:     public function getValue()
 92:     {
 93:         return $this->value;
 94:     }
 95: 
 96: 
 97:     /**
 98:      * @param  bool
 99:      * @return self
100:      */
101:     public function setStatic($state = TRUE)
102:     {
103:         $this->static = (bool) $state;
104:         return $this;
105:     }
106: 
107: 
108:     /**
109:      * @return bool
110:      */
111:     public function isStatic()
112:     {
113:         return $this->static;
114:     }
115: 
116: 
117:     /**
118:      * @param  string  public|protected|private
119:      * @return self
120:      */
121:     public function setVisibility($val)
122:     {
123:         if (!in_array($val, array('public', 'protected', 'private'), TRUE)) {
124:             throw new Nette\InvalidArgumentException('Argument must be public|protected|private.');
125:         }
126:         $this->visibility = (string) $val;
127:         return $this;
128:     }
129: 
130: 
131:     /**
132:      * @return string
133:      */
134:     public function getVisibility()
135:     {
136:         return $this->visibility;
137:     }
138: 
139: 
140:     /**
141:      * @param  string|NULL
142:      * @return self
143:      */
144:     public function setComment($val)
145:     {
146:         $this->documents = $val ? array((string) $val) : array();
147:         return $this;
148:     }
149: 
150: 
151:     /**
152:      * @return string|NULL
153:      */
154:     public function getComment()
155:     {
156:         return implode($this->documents) ?: NULL;
157:     }
158: 
159: 
160:     /**
161:      * @param  string
162:      * @return self
163:      */
164:     public function addComment($val)
165:     {
166:         return $this->addDocument($val);
167:     }
168: 
169: 
170:     /**
171:      * @param  string[]
172:      * @return self
173:      */
174:     public function setDocuments(array $s)
175:     {
176:         $this->documents = $s;
177:         return $this;
178:     }
179: 
180: 
181:     /**
182:      * @return string[]
183:      */
184:     public function getDocuments()
185:     {
186:         return $this->documents;
187:     }
188: 
189: 
190:     /**
191:      * @param  string
192:      * @return self
193:      */
194:     public function addDocument($s)
195:     {
196:         $this->documents[] = (string) $s;
197:         return $this;
198:     }
199: 
200: }
201: 
Nette 2.3-20161221 API API documentation generated by ApiGen 2.8.0