1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
namespace Nette\Reflection;
use Nette;
/**
* Reports information about a class.
* @property-read Method $constructor
* @property-read Extension $extension
* @property-read ClassType[] $interfaces
* @property-read Method[] $methods
* @property-read ClassType $parentClass
* @property-read Property[] $properties
* @property-read IAnnotation[][] $annotations
* @property-read string $description
* @property-read string $name
* @property-read bool $internal
* @property-read bool $userDefined
* @property-read bool $instantiable
* @property-read string $fileName
* @property-read int $startLine
* @property-read int $endLine
* @property-read string $docComment
* @property-read mixed[] $constants
* @property-read string[] $interfaceNames
* @property-read bool $interface
* @property-read bool $abstract
* @property-read bool $final
* @property-read int $modifiers
* @property-read array $staticProperties
* @property-read array $defaultProperties
* @property-read bool $iterateable
* @property-read string $extensionName
* @property-read string $namespaceName
* @property-read string $shortName
*/
class ClassType extends \ReflectionClass
{
use Nette\SmartObject;
/**
* @param string|object
* @return self
*/
public static function from($class)
{
return new static($class);
}
public function __toString()
{
return $this->getName();
}
/**
* @param string
* @return bool
*/
public function is($type)
{
return is_a($this->getName(), $type, TRUE);
}
/********************* Reflection layer ****************d*g**/
/**
* @return Method|NULL
*/
public function getConstructor()
{
return ($ref = parent::getConstructor()) ? Method::from($this->getName(), $ref->getName()) : NULL;
}
/**
* @return Extension|NULL
*/
public function getExtension()
{
return ($name = $this->getExtensionName()) ? new Extension($name) : NULL;
}
/**
* @return self[]
*/
public function getInterfaces()
{
$res = [];
foreach (parent::getInterfaceNames() as $val) {
$res[$val] = new static($val);
}
return $res;
}
/**
* @return Method
*/
public function getMethod($name)
{
return new Method($this->getName(), $name);
}
/**
* @return Method[]
*/
public function getMethods($filter = -1)
{
foreach ($res = parent::getMethods($filter) as $key => $val) {
$res[$key] = new Method($this->getName(), $val->getName());
}
return $res;
}
/**
* @return self|NULL
*/
public function getParentClass()
{
return ($ref = parent::getParentClass()) ? new static($ref->getName()) : NULL;
}
/**
* @return Property[]
*/
public function getProperties($filter = -1)
{
foreach ($res = parent::getProperties($filter) as $key => $val) {
$res[$key] = new Property($this->getName(), $val->getName());
}
return $res;
}
/**
* @return Property
*/
public function getProperty($name)
{
return new Property($this->getName(), $name);
}
/********************* Nette\Annotations support ****************d*g**/
/**
* Has class specified annotation?
* @param string
* @return bool
*/
public function hasAnnotation($name)
{
$res = AnnotationsParser::getAll($this);
return !empty($res[$name]);
}
/**
* Returns an annotation value.
* @param string
* @return IAnnotation
*/
public function getAnnotation($name)
{
$res = AnnotationsParser::getAll($this);
return isset($res[$name]) ? end($res[$name]) : NULL;
}
/**
* Returns all annotations.
* @return IAnnotation[][]
*/
public function getAnnotations()
{
return AnnotationsParser::getAll($this);
}
/**
* Returns value of annotation 'description'.
* @return string
*/
public function getDescription()
{
return $this->getAnnotation('description');
}
}
|