1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright 2011 Johannes M. Schmitt <[email protected]> |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
namespace gossi\codegen\model; |
19
|
|
|
|
20
|
|
|
use gossi\codegen\model\parts\DefaultValueTrait; |
21
|
|
|
use gossi\codegen\model\parts\TypeDocblockGeneratorTrait; |
22
|
|
|
use gossi\docblock\Docblock; |
23
|
|
|
use gossi\docblock\tags\VarTag; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Represents a PHP property. |
27
|
|
|
* |
28
|
|
|
* @author Johannes M. Schmitt <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class PhpProperty extends AbstractPhpMember { |
31
|
|
|
|
32
|
|
|
use DefaultValueTrait; |
33
|
|
|
use TypeDocblockGeneratorTrait; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string|null $name |
37
|
|
|
*/ |
38
|
10 |
|
public static function create($name) { |
39
|
10 |
|
return new static($name); |
40
|
|
|
} |
41
|
|
|
|
42
|
4 |
|
public static function fromReflection(\ReflectionProperty $ref) { |
43
|
4 |
|
$property = new static($ref->name); |
44
|
4 |
|
$property->setStatic($ref->isStatic()) |
45
|
4 |
|
->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE)); |
46
|
|
|
|
47
|
4 |
|
$docblock = new Docblock($ref); |
48
|
4 |
|
$property->setDocblock($docblock); |
49
|
4 |
|
$property->setDescription($docblock->getShortDescription()); |
50
|
4 |
|
$property->setLongDescription($docblock->getLongDescription()); |
51
|
|
|
|
52
|
4 |
|
$vars = $docblock->getTags('var'); |
53
|
4 |
|
if ($vars->size() > 0) { |
54
|
2 |
|
$var = $vars->get(0); |
55
|
2 |
|
$property->setType($var->getType(), $var->getDescription()); |
56
|
2 |
|
} |
57
|
|
|
|
58
|
4 |
|
$defaultProperties = $ref->getDeclaringClass()->getDefaultProperties(); |
59
|
4 |
|
if (isset($defaultProperties[$ref->name])) { |
60
|
2 |
|
$property->setDefaultValue($defaultProperties[$ref->name]); |
61
|
2 |
|
} |
62
|
|
|
|
63
|
4 |
|
return $property; |
64
|
|
|
} |
65
|
|
|
|
66
|
8 |
|
public function generateDocblock() { |
67
|
8 |
|
$docblock = $this->getDocblock(); |
68
|
8 |
|
$docblock->setShortDescription($this->getDescription()); |
69
|
8 |
|
$docblock->setLongDescription($this->getLongDescription()); |
70
|
|
|
|
71
|
|
|
// var tag |
72
|
8 |
|
$this->generateTypeTag(new VarTag()); |
73
|
8 |
|
} |
74
|
|
|
} |
75
|
|
|
|