-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicClass.php
137 lines (96 loc) · 3.95 KB
/
BasicClass.php
1
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
namespace Sf2gen\Component\PhpCoder;
class BasicClass extends VisibleStaticCode {
protected $classNamespace = false;
protected $classname;
protected $classType = false;
protected $extendedClass = false;
protected $interfaces = false;
protected $properties = array();
protected $functions = array();
protected $classTypes = array('abstract', 'final');
public function setNamespace($namespace){
$this->classNamespace = $namespace;
$this->isStatic = false;
$this->visibility = false;
return $this;
}
public function setStatic($static) {
//not possible to change static on CLASS
return $this;
}
public function setExtendedClass($extendedClass, $alias = false){
if($alias)
$extendedClass = $this->addUse($extendedClass, $alias);
$this->extendedClass = $extendedClass;
return $this;
}
public function addInterface($interface, $alias = false) {
if($alias)
$interface = $this->addUse($interface, $alias);
$this->interfaces[] = $interface;
return $this;
}
public function addFunction(ClassFunction $function) {
if($function->getFunctionName()){
$this->functions[$function->getFunctionName()] = $function;
}
return $this;
}
public function addProperty(Property $property) {
if($property->getVarName()){
$this->properties[$property->getVarName()] = $property;
}
return $this;
}
public function issetProperty($name){
return (isset($this->properties[$name]));
}
public function getProperty($name){
return (isset($this->properties[$name]) ? $this->properties[$name] : false);
}
public function setClassname($classname){
$this->classname = $classname;
return $this;
}
public function getClassType(){
return ($this->classType ? $this->classTypes[ $this->classType ] . ' ' : '');
}
public function setClassType($classType){
$values = array_flip($this->classTypes);
if(isset($values[ $classType ]))
$this->classType = $values[ $classType ];
else
$this->classType = false;
return $this;
}
public function output() {
$content = '';
$content .= ($this->classNamespace !== false ? 'namespace ' . $this->classNamespace . ';' . self::$newline : '' );
$content .= self::$newline;
if(!empty($this->uses)){
foreach($this->uses as $k => $v)
$content .= 'use ' . $k . ( ($v && (self::getAlias($k) != $v)) ? ' as ' . $v : '') . ';' . self::$newline;
$content .= self::$newline;
}
$content .= $this->outputComment();
$content .= $this->getClassType()
. 'class '
. $this->classname . ' '
;
$content .= ($this->extendedClass !== false ? 'extends ' . $this->extendedClass . ' ' : '' );
if(!empty($this->interfaces)){
$content .= 'implements ' . implode(', ', $this->interfaces) . ' ';
}
$content .= '{';
if(!empty($this->properties) || !empty($this->functions)){
$content .= self::$newline;
foreach($this->properties as $property)
$content .= self::$newline . self::$indent . $property->output() . self::$newline;
foreach($this->functions as $function)
$content .= self::$newline . self::indent( self::$indent, self::$newline, $function->output()) . self::$newline;
}
$content .= '}' . self::$newline;
return $content;
}
}