|
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\DocumentBlockInterface; |
|
15
|
|
|
use ClassGeneration\Element\ElementAbstract; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Namespace ClassGeneration |
|
19
|
|
|
* @author Antonio Spinelli <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class NamespaceClass extends ElementAbstract implements NamespaceInterface, DocumentBlockInterface |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var mixed |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $path; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Documentation Block |
|
31
|
|
|
* @var DocBlockInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $docBlock; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param array|string $options |
|
37
|
|
|
*/ |
|
38
|
41 |
|
public function __construct($options = array()) |
|
39
|
|
|
{ |
|
40
|
41 |
|
if (is_string($options)) { |
|
41
|
2 |
|
$options = array('path' => $options); |
|
42
|
2 |
|
} |
|
43
|
41 |
|
parent::__construct($options); |
|
44
|
41 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
41 |
|
public function init() |
|
50
|
|
|
{ |
|
51
|
41 |
|
$this->setTabulation(0); |
|
52
|
41 |
|
$this->setDocBlock(new DocBlock()); |
|
53
|
41 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Gets the path. |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
13 |
|
public function getPath() |
|
60
|
|
|
{ |
|
61
|
13 |
|
return $this->path; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Sets the Path. |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $path |
|
68
|
|
|
* |
|
69
|
|
|
* @return NamespaceClass |
|
70
|
|
|
*/ |
|
71
|
6 |
|
public function setPath($path) |
|
72
|
|
|
{ |
|
73
|
6 |
|
$this->path = $path; |
|
74
|
|
|
|
|
75
|
6 |
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Sets the namespace's description. |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $description |
|
82
|
|
|
* |
|
83
|
|
|
* @return NamespaceClass |
|
84
|
|
|
*/ |
|
85
|
3 |
|
public function setDescription($description) |
|
86
|
|
|
{ |
|
87
|
3 |
|
$this->getDocBlock()->setDescription($description); |
|
88
|
|
|
|
|
89
|
3 |
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Gets the namespace's description. |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
2 |
|
public function getDescription() |
|
97
|
|
|
{ |
|
98
|
2 |
|
return $this->getDocBlock()->getDescription(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* {@inheritdoc} |
|
103
|
|
|
*/ |
|
104
|
4 |
|
public function getDocBlock() |
|
105
|
|
|
{ |
|
106
|
4 |
|
return $this->docBlock; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* {@inheritdoc} |
|
111
|
|
|
* @return NamespaceClass |
|
112
|
|
|
*/ |
|
113
|
41 |
|
public function setDocBlock(DocBlockInterface $docBlock) |
|
114
|
|
|
{ |
|
115
|
41 |
|
$this->docBlock = $docBlock; |
|
116
|
|
|
|
|
117
|
41 |
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Parse the namespace string; |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
10 |
|
public function toString() |
|
125
|
|
|
{ |
|
126
|
10 |
|
if (!$this->getPath()) { |
|
127
|
8 |
|
return ''; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
2 |
|
$path = preg_replace('/^\\\/', '', $this->getPath()); |
|
131
|
|
|
|
|
132
|
2 |
|
$namespace = $this->getDocBlock()->setTabulation($this->getTabulation())->toString() |
|
133
|
2 |
|
. $this->getTabulationFormatted() |
|
134
|
2 |
|
. 'namespace ' |
|
135
|
2 |
|
. $path |
|
136
|
2 |
|
. ';' . PHP_EOL; |
|
137
|
|
|
|
|
138
|
2 |
|
return $namespace; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|