1 | <?php |
||
20 | class PhpClass extends AbstractPhpStruct implements GenerateableInterface, TraitsInterface, ConstantsInterface { |
||
21 | |||
22 | use AbstractPart; |
||
23 | use ConstantsPart; |
||
24 | use FinalPart; |
||
25 | use InterfacesPart; |
||
26 | use PropertiesPart; |
||
27 | use TraitsPart; |
||
28 | |||
29 | /** @var string */ |
||
30 | private $parentClassName; |
||
31 | |||
32 | /** |
||
33 | * Creates a PHP class from reflection |
||
34 | * |
||
35 | * @param \ReflectionClass $ref |
||
36 | * @return PhpClass |
||
37 | */ |
||
38 | 3 | public static function fromReflection(\ReflectionClass $ref) { |
|
39 | |||
40 | /**@var PhpClass $class */ |
||
41 | 3 | $class = new static(); |
|
42 | |||
43 | 3 | $class->setQualifiedName($ref->name) |
|
44 | 3 | ->setAbstract($ref->isAbstract()) |
|
45 | 3 | ->setFinal($ref->isFinal()) |
|
46 | 3 | ->setParentClassName($ref->getParentClass()->name) |
|
47 | ->setUseStatements(ReflectionUtils::getUseStatements($ref)); |
||
48 | |||
49 | if ($ref->getDocComment()) { |
||
50 | $docblock = new Docblock($ref); |
||
51 | $class->setDocblock($docblock); |
||
52 | $class->setDescription($docblock->getShortDescription()); |
||
53 | $class->setLongDescription($docblock->getLongDescription()); |
||
54 | } |
||
55 | |||
56 | // methods |
||
57 | foreach ($ref->getMethods() as $method) { |
||
58 | if ($method->class == $ref->name) { |
||
59 | $class->setMethod(static::createMethod($method)); |
||
60 | } |
||
61 | } |
||
62 | |||
63 | // properties |
||
64 | foreach ($ref->getProperties() as $property) { |
||
65 | if ($property->class == $ref->name) { |
||
66 | $class->setProperty(static::createProperty($property)); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | // traits |
||
71 | foreach ($ref->getTraits() as $trait) { |
||
72 | if ($trait->class == $ref->name) { |
||
|
|||
73 | $class->addTrait(PhpTrait::fromReflection($trait)); |
||
74 | } |
||
75 | 1 | } |
|
76 | |||
77 | // constants |
||
78 | // TODO: https://github.com/gossi/php-code-generator/issues/19 |
||
79 | foreach ($ref->getConstants() as $name => $value) { |
||
80 | $const = new PhpConstant($name); |
||
81 | |||
82 | if (is_string($value)) { |
||
83 | $const->setValue($value); |
||
84 | } else { |
||
85 | $const->setExpression($value); |
||
86 | } |
||
87 | $class->setConstant($const); |
||
88 | } |
||
89 | |||
90 | return $class; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Creates a PHP class from file |
||
95 | * |
||
96 | * @param string $filename |
||
97 | * @return PhpClass |
||
98 | */ |
||
99 | 6 | public static function fromFile($filename) { |
|
104 | |||
105 | /** |
||
106 | * Creates a new PHP class |
||
107 | * |
||
108 | * @param string $name the qualified name |
||
109 | */ |
||
110 | 42 | public function __construct($name = null) { |
|
113 | |||
114 | /** |
||
115 | * Returns the parent class name |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | 12 | public function getParentClassName() { |
|
122 | |||
123 | /** |
||
124 | * Sets the parent class name |
||
125 | * |
||
126 | * @param string|null $name the new parent |
||
127 | * @return $this |
||
128 | */ |
||
129 | 1 | public function setParentClassName($name) { |
|
134 | |||
135 | 5 | public function generateDocblock() { |
|
146 | |||
147 | } |
||
148 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.