1: <?php
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: class PhpClassType extends Object
27: {
28:
29: public $name;
30:
31:
32: public $type = 'class';
33:
34:
35: public $final;
36:
37:
38: public $abstract;
39:
40:
41: public $extends = array();
42:
43:
44: public $implements = array();
45:
46:
47: public $traits = array();
48:
49:
50: public $documents = array();
51:
52:
53: public $consts = array();
54:
55:
56: public $properties = array();
57:
58:
59: public $methods = array();
60:
61:
62: public function __construct($name = NULL)
63: {
64: $this->name = $name;
65: }
66:
67:
68:
69: public function addConst($name, $value)
70: {
71: $this->consts[$name] = $value;
72: return $this;
73: }
74:
75:
76:
77: public function addProperty($name, $value = NULL)
78: {
79: $property = new PhpProperty;
80: return $this->properties[$name] = $property->setName($name)->setValue($value);
81: }
82:
83:
84:
85: public function addMethod($name)
86: {
87: $method = new PhpMethod;
88: if ($this->type === 'interface') {
89: $method->setVisibility('')->setBody(FALSE);
90: } else {
91: $method->setVisibility('public');
92: }
93: return $this->methods[$name] = $method->setName($name);
94: }
95:
96:
97: public function __call($name, $args)
98: {
99: return ObjectMixin::callProperty($this, $name, $args);
100: }
101:
102:
103:
104: public function __toString()
105: {
106: $consts = array();
107: foreach ($this->consts as $name => $value) {
108: $consts[] = "const $name = " . PhpHelpers::dump($value) . ";\n";
109: }
110: $properties = array();
111: foreach ($this->properties as $property) {
112: $properties[] = ($property->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $property->documents)) . "\n */\n" : '')
113: . $property->visibility . ($property->static ? ' static' : '') . ' $' . $property->name
114: . ($property->value === NULL ? '' : ' = ' . PhpHelpers::dump($property->value))
115: . ";\n";
116: }
117: return Strings::normalize(
118: ($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '')
119: . ($this->abstract ? 'abstract ' : '')
120: . ($this->final ? 'final ' : '')
121: . $this->type . ' '
122: . $this->name . ' '
123: . ($this->extends ? 'extends ' . implode(', ', (array) $this->extends) . ' ' : '')
124: . ($this->implements ? 'implements ' . implode(', ', (array) $this->implements) . ' ' : '')
125: . "\n{\n\n"
126: . Strings::indent(
127: ($this->traits ? "use " . implode(', ', (array) $this->traits) . ";\n\n" : '')
128: . ($this->consts ? implode('', $consts) . "\n\n" : '')
129: . ($this->properties ? implode("\n", $properties) . "\n\n" : '')
130: . implode("\n\n\n", $this->methods), 1)
131: . "\n\n}") . "\n";
132: }
133:
134: }
135: