|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AppserverIo\Routlt\Description\ResultDescriptor |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link http://github.com/appserver-io/routlt |
|
18
|
|
|
* @link http://www.appserver.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Routlt\Description; |
|
22
|
|
|
|
|
23
|
|
|
use AppserverIo\Lang\Reflection\AnnotationInterface; |
|
24
|
|
|
use AppserverIo\Configuration\Interfaces\NodeInterface; |
|
25
|
|
|
use AppserverIo\Description\DescriptorReferencesTrait; |
|
26
|
|
|
use AppserverIo\Description\AbstractNameAwareDescriptor; |
|
27
|
|
|
use AppserverIo\Lang\Reflection\ClassInterface; |
|
28
|
|
|
use AppserverIo\Routlt\Annotations\Result; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Descriptor implementation for a action result. |
|
32
|
|
|
* |
|
33
|
|
|
* @author Tim Wagner <[email protected]> |
|
34
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
35
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
36
|
|
|
* @link http://github.com/appserver-io/routlt |
|
37
|
|
|
* @link http://www.appserver.io |
|
38
|
|
|
*/ |
|
39
|
|
|
class ResultDescriptor extends AbstractNameAwareDescriptor implements ResultDescriptorInterface |
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The trait with the references descriptors. |
|
44
|
|
|
* |
|
45
|
|
|
* @var AppserverIo\Description\DescriptorReferencesTrait |
|
46
|
|
|
*/ |
|
47
|
|
|
use DescriptorReferencesTrait; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* The beans class name. |
|
51
|
|
|
* |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $className; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Sets the beans class name. |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $className The beans class name |
|
60
|
|
|
* |
|
61
|
|
|
* @return void |
|
62
|
|
|
*/ |
|
63
|
|
|
public function setClassName($className) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->className = $className; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Returns the beans class name. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string The beans class name |
|
72
|
|
|
*/ |
|
73
|
6 |
|
public function getClassName() |
|
74
|
|
|
{ |
|
75
|
6 |
|
return $this->className; |
|
76
|
6 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Returns a new descriptor instance. |
|
80
|
|
|
* |
|
81
|
|
|
* @return \AppserverIo\Routlt\Description\ResultDescriptorInterface The descriptor instance |
|
82
|
|
|
*/ |
|
83
|
6 |
|
public static function newDescriptorInstance() |
|
84
|
|
|
{ |
|
85
|
6 |
|
return new ResultDescriptor(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Returns a new annotation instance for the passed reflection class. |
|
90
|
|
|
* |
|
91
|
|
|
* @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the bean configuration |
|
92
|
|
|
* |
|
93
|
|
|
* @return \AppserverIo\Lang\Reflection\AnnotationInterface The reflection annotation |
|
94
|
|
|
*/ |
|
95
|
6 |
|
protected function newAnnotationInstance(ClassInterface $reflectionClass) |
|
96
|
|
|
{ |
|
97
|
6 |
|
return $reflectionClass->getAnnotation(Result::ANNOTATION); |
|
98
|
6 |
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Initializes the bean configuration instance from the passed reflection class instance. |
|
102
|
|
|
* |
|
103
|
|
|
* @param \AppserverIo\Lang\Reflection\ClassInterface $reflectionClass The reflection class with the bean configuration |
|
104
|
|
|
* |
|
105
|
1 |
|
* @return \AppserverIo\Routlt\Description\PathDescriptorInterface The initialized descriptor |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function fromReflectionClass(ClassInterface $reflectionClass) |
|
108
|
|
|
{ |
|
109
|
|
|
|
|
110
|
|
|
// add the annotation alias to the reflection class |
|
111
|
|
|
$reflectionClass->addAnnotationAlias(Result::ANNOTATION, Result::__getClass()); |
|
112
|
|
|
|
|
113
|
|
|
// query if we've an action |
|
114
|
|
|
if ($reflectionClass->implementsInterface('AppserverIo\Routlt\Results\ResultInterface') === false && |
|
115
|
|
|
$reflectionClass->toPhpReflectionClass()->isAbstract() === false |
|
116
|
|
|
) { |
|
117
|
6 |
|
// if not, do nothing |
|
118
|
|
|
return; |
|
119
|
6 |
|
} |
|
120
|
6 |
|
|
|
121
|
|
|
// query if we've a servlet with a @Path annotation |
|
122
|
|
|
if ($reflectionClass->hasAnnotation(Result::ANNOTATION) === false) { |
|
123
|
|
|
// if not, do nothing |
|
124
|
|
|
return; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
1 |
|
// create a new annotation instance |
|
128
|
|
|
$reflectionAnnotation = $this->newAnnotationInstance($reflectionClass); |
|
129
|
1 |
|
|
|
130
|
|
|
// load class name |
|
131
|
|
|
$this->setClassName($reflectionClass->getName()); |
|
132
|
|
|
|
|
133
|
|
|
// initialize the annotation instance |
|
134
|
|
|
$annotationInstance = $reflectionAnnotation->newInstance( |
|
135
|
|
|
$reflectionAnnotation->getAnnotationName(), |
|
136
|
|
|
$reflectionAnnotation->getValues() |
|
137
|
|
|
); |
|
138
|
|
|
|
|
139
|
1 |
|
// load the default name to register in naming directory |
|
140
|
|
|
if ($nameAttribute = $annotationInstance->getName()) { |
|
141
|
1 |
|
$name = $nameAttribute; |
|
142
|
1 |
|
} else { |
|
143
|
|
|
// if @Annotation(name=****) is NOT set, we use the class name by default |
|
144
|
|
|
$name = $reflectionClass->getShortName(); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
// prepare and set the name |
|
148
|
|
|
$this->setName($name); |
|
149
|
1 |
|
|
|
150
|
|
|
// initialize the shared flag @Result(shared=true) |
|
151
|
1 |
|
$this->setShared($annotationInstance->getShared()); |
|
152
|
|
|
|
|
153
|
|
|
// initialize references from the passed reflection class |
|
154
|
|
|
$this->referencesFromReflectionClass($reflectionClass); |
|
155
|
|
|
|
|
156
|
|
|
// return the instance |
|
157
|
|
|
return $this; |
|
158
|
|
|
} |
|
159
|
3 |
|
|
|
160
|
|
|
/** |
|
161
|
3 |
|
* Initializes the result configuration instance from the passed reflection annotation instance. |
|
162
|
|
|
* |
|
163
|
|
|
* @param \AppserverIo\Lang\Reflection\AnnotationInterface $reflectionAnnotation The reflection annotation with the result configuration |
|
164
|
|
|
* |
|
165
|
|
|
* @return \AppserverIo\Routlt\Description\ResultDescriptorInterface The initialized descriptor |
|
166
|
|
|
*/ |
|
167
|
|
|
public function fromReflectionAnnotation(AnnotationInterface $reflectionAnnotation) |
|
|
|
|
|
|
168
|
|
|
{ |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
6 |
|
/** |
|
172
|
|
|
* Initializes a action configuration instance from the passed deployment descriptor node. |
|
173
|
|
|
* |
|
174
|
|
|
* @param \SimpleXmlElement $node The deployment node with the action configuration |
|
175
|
6 |
|
* |
|
176
|
6 |
|
* @return \AppserverIo\Routlt\Description\ActionDescriptorInterface The initialized descriptor |
|
177
|
6 |
|
*/ |
|
178
|
6 |
|
public function fromDeploymentDescriptor(\SimpleXmlElement $node) |
|
|
|
|
|
|
179
|
|
|
{ |
|
180
|
|
|
} |
|
181
|
6 |
|
|
|
182
|
6 |
|
/** |
|
183
|
6 |
|
* Initializes a action configuration instance from the passed configuration node. |
|
184
|
|
|
* |
|
185
|
|
|
* @param \AppserverIo\Configuration\Interfaces\NodeInterface $node The configuration node with the action configuration |
|
186
|
6 |
|
* |
|
187
|
|
|
* @return \AppserverIo\Routlt\Description\ActionDescriptorInterface The initialized descriptor |
|
188
|
|
|
*/ |
|
189
|
|
|
public function fromConfiguration(NodeInterface $node) |
|
|
|
|
|
|
190
|
|
|
{ |
|
191
|
6 |
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Merges the passed configuration into this one. Configuration values |
|
195
|
|
|
* of the passed configuration will overwrite the this one. |
|
196
|
|
|
* |
|
197
|
|
|
* @param \AppserverIo\Routlt\Description\ResultDescriptorInterface $resultDescriptor The configuration to merge |
|
198
|
|
|
* |
|
199
|
|
|
* @return void |
|
200
|
|
|
* @throws \AppserverIo\Routlt\Description\DescriptorException Is thrown if the passed descriptor has a different method name |
|
201
|
1 |
|
*/ |
|
202
|
|
|
public function merge(ResultDescriptorInterface $resultDescriptor) |
|
203
|
1 |
|
{ |
|
204
|
|
|
|
|
205
|
|
|
// check if the classes are equal |
|
206
|
|
|
if ($this->getName() !== $resultDescriptor->getName()) { |
|
207
|
|
|
throw new DescriptorException( |
|
208
|
|
|
sprintf('You try to merge a result configuration for % with %s', $resultDescriptor->getName(), $this->getName()) |
|
209
|
|
|
); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
// merge the class name |
|
213
|
|
|
if ($className = $resultDescriptor->getClassName()) { |
|
214
|
|
|
$this->setClassName($className); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
// merge the shared flag |
|
218
|
|
|
$this->setShared($resultDescriptor->isShared()); |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.