1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ClassGeneration package. |
5
|
|
|
* |
6
|
|
|
* (c) Antonio Spinelli <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ClassGeneration; |
13
|
|
|
|
14
|
|
|
use ClassGeneration\Element\ElementAbstract; |
15
|
|
|
use ClassGeneration\Element\ElementInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Use ClassGeneration |
19
|
|
|
* @author Antonio Spinelli <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class UseClass extends ElementAbstract implements UseInterface |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The class name. |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $className; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The alias for class name. |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $alias; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritdoc |
38
|
|
|
*/ |
39
|
7 |
|
public function init() |
40
|
|
|
{ |
41
|
7 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritdoc |
45
|
|
|
* @return PhpClassInterface |
46
|
|
|
*/ |
47
|
1 |
|
public function getParent() |
48
|
|
|
{ |
49
|
1 |
|
return $this->parent; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
* @return UseInterface |
55
|
|
|
*/ |
56
|
1 |
|
public function setParent(ElementInterface $parent) |
57
|
|
|
{ |
58
|
1 |
|
if (!$parent instanceof PhpClassInterface) { |
59
|
1 |
|
throw new \InvalidArgumentException('Only accept instances from ClassGeneration\PhpClassInterface'); |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
return parent::setParent($parent); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @inheritdoc |
67
|
|
|
*/ |
68
|
2 |
|
public function setAlias($alias) |
69
|
|
|
{ |
70
|
2 |
|
$this->alias = (string)$alias; |
71
|
|
|
|
72
|
2 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Gets the alias name. |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
4 |
|
public function getAlias() |
80
|
|
|
{ |
81
|
4 |
|
return $this->alias; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @inheritdoc |
86
|
|
|
*/ |
87
|
4 |
|
public function hasAlias() |
88
|
|
|
{ |
89
|
4 |
|
$alias = $this->getAlias(); |
90
|
|
|
|
91
|
4 |
|
return (!is_null($alias) && !empty($alias)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @inheritdoc |
96
|
|
|
*/ |
97
|
4 |
|
public function setClassName($className) |
98
|
|
|
{ |
99
|
4 |
|
$this->className = (string)$className; |
100
|
|
|
|
101
|
4 |
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @inheritdoc |
106
|
|
|
*/ |
107
|
4 |
|
public function getClassName() |
108
|
|
|
{ |
109
|
4 |
|
return $this->className; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @inheritdoc |
114
|
|
|
*/ |
115
|
4 |
|
public function toString() |
116
|
|
|
{ |
117
|
|
|
|
118
|
|
|
$implements = 'use ' |
119
|
4 |
|
. $this->getClassName() |
120
|
4 |
|
. ($this->hasAlias() ? ' as ' . $this->getAlias() : '') |
121
|
4 |
|
. ';' . PHP_EOL; |
122
|
|
|
|
123
|
4 |
|
return $implements; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|