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