1 | <?php |
||
30 | class PhpProperty extends AbstractPhpMember { |
||
31 | |||
32 | use TypeDocblockGeneratorPart; |
||
33 | use ValuePart; |
||
34 | |||
35 | /** |
||
36 | * Creates a new PHP property |
||
37 | * |
||
38 | * @param string $name the properties name |
||
39 | * @return static |
||
40 | */ |
||
41 | 11 | public static function create($name) { |
|
44 | |||
45 | |||
46 | /** |
||
47 | * Export array as php 5.4 |
||
48 | * |
||
49 | * @param $var |
||
50 | * @param string $indent |
||
51 | * @return string |
||
52 | */ |
||
53 | static public function export($var, $indent="") { |
||
54 | switch (gettype($var)) { |
||
55 | case "string": |
||
56 | return '"' . addcslashes($var, "\\\$\"\r\n\t\v\f") . '"'; |
||
57 | case "array": |
||
58 | $indexed = array_keys($var) === range(0, count($var) - 1); |
||
59 | $r = []; |
||
60 | foreach ($var as $key => $value) { |
||
61 | $r[] = "$indent " |
||
62 | . ($indexed ? "" : static::export($key) . " => ") |
||
63 | . static::export($value, "$indent "); |
||
64 | } |
||
65 | return "[\n" . implode(",\n", $r) . "\n" . $indent . "]"; |
||
66 | case "boolean": |
||
67 | return $var ? "TRUE" : "FALSE"; |
||
68 | default: |
||
69 | return var_export($var, TRUE); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Creates a new PHP property from reflection |
||
75 | * |
||
76 | * @param \ReflectionProperty $ref |
||
77 | * @return static |
||
78 | */ |
||
79 | 1 | public static function fromReflection(\ReflectionProperty $ref) { |
|
80 | 1 | $property = new static($ref->name); |
|
81 | 1 | $property->setStatic($ref->isStatic()) |
|
82 | 1 | ->setVisibility($ref->isPublic() ? self::VISIBILITY_PUBLIC : ($ref->isProtected() ? self::VISIBILITY_PROTECTED : self::VISIBILITY_PRIVATE)); |
|
83 | |||
84 | 1 | $docblock = new Docblock($ref); |
|
85 | 1 | $property->setDocblock($docblock); |
|
86 | 1 | $property->setDescription($docblock->getShortDescription()); |
|
87 | 1 | $property->setLongDescription($docblock->getLongDescription()); |
|
88 | |||
89 | 1 | $vars = $docblock->getTags('var'); |
|
90 | 1 | if ($vars->size() > 0) { |
|
91 | $var = $vars->get(0); |
||
92 | $property->setType($var->getType(), $var->getDescription()); |
||
93 | } |
||
94 | |||
95 | 1 | $defaultProperties = $ref->getDeclaringClass()->getDefaultProperties(); |
|
96 | |||
97 | 1 | if (isset($defaultProperties[$ref->name])) { |
|
98 | $default = $defaultProperties[$ref->name]; |
||
99 | if (is_string($default)) { |
||
100 | $property->setValue($default); |
||
101 | } elseif(is_array($default)) { |
||
102 | $property->setValue(static::export($default)); |
||
103 | } elseif(is_object($default)) { |
||
104 | } else { |
||
105 | $property->setExpression($default); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | 1 | return $property; |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * Generates docblock based on provided information |
||
114 | */ |
||
115 | 8 | public function generateDocblock() { |
|
123 | } |
||
124 |