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
|
|
|
public function getClassName() |
74
|
|
|
{ |
75
|
|
|
return $this->className; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns a new descriptor instance. |
80
|
|
|
* |
81
|
|
|
* @return \AppserverIo\Routlt\Description\ResultDescriptorInterface The descriptor instance |
82
|
|
|
*/ |
83
|
|
|
public static function newDescriptorInstance() |
84
|
|
|
{ |
85
|
|
|
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
|
|
|
protected function newAnnotationInstance(ClassInterface $reflectionClass) |
96
|
|
|
{ |
97
|
|
|
return $reflectionClass->getAnnotation(Result::ANNOTATION); |
98
|
|
|
} |
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
|
|
|
* @return \AppserverIo\Routlt\Description\PathDescriptorInterface The initialized descriptor |
106
|
|
|
*/ |
107
|
|
|
public function fromReflectionClass(ClassInterface $reflectionClass) |
108
|
|
|
{ |
109
|
|
|
|
110
|
|
|
// query if we've an action |
111
|
|
|
if ($reflectionClass->implementsInterface('AppserverIo\Routlt\Results\ResultInterface') === false && |
112
|
|
|
$reflectionClass->toPhpReflectionClass()->isAbstract() === false |
113
|
|
|
) { |
114
|
|
|
// if not, do nothing |
115
|
|
|
return; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
// create a new annotation instance |
119
|
|
|
$annotationInstance = $this->getClassAnnotation($reflectionClass, Result::class); |
120
|
|
|
|
121
|
|
|
// query if we've a servlet with a @Path annotation |
122
|
|
|
if ($annotationInstance === null) { |
123
|
|
|
// if not, do nothing |
124
|
|
|
return; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// load class name |
128
|
|
|
$this->setClassName($reflectionClass->getName()); |
129
|
|
|
|
130
|
|
|
// load the default name to register in naming directory |
131
|
|
|
if ($nameAttribute = $annotationInstance->getName()) { |
132
|
|
|
$name = $nameAttribute; |
133
|
|
|
} else { |
134
|
|
|
// if @Annotation(name=****) is NOT set, we use the class name by default |
135
|
|
|
$name = $reflectionClass->getShortName(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
// prepare and set the name |
139
|
|
|
$this->setName($name); |
140
|
|
|
|
141
|
|
|
// initialize the shared flag @Result(shared=true) |
142
|
|
|
$this->setShared($annotationInstance->getShared()); |
143
|
|
|
|
144
|
|
|
// initialize references from the passed reflection class |
145
|
|
|
$this->referencesFromReflectionClass($reflectionClass); |
146
|
|
|
|
147
|
|
|
// return the instance |
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Initializes the result configuration instance from the passed reflection annotation instance. |
153
|
|
|
* |
154
|
|
|
* @param \AppserverIo\Lang\Reflection\AnnotationInterface $reflectionAnnotation The reflection annotation with the result configuration |
155
|
|
|
* |
156
|
|
|
* @return \AppserverIo\Routlt\Description\ResultDescriptorInterface The initialized descriptor |
157
|
|
|
*/ |
158
|
|
|
public function fromReflectionAnnotation(AnnotationInterface $reflectionAnnotation) |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Initializes a action configuration instance from the passed deployment descriptor node. |
164
|
|
|
* |
165
|
|
|
* @param \SimpleXmlElement $node The deployment node with the action configuration |
166
|
|
|
* |
167
|
|
|
* @return \AppserverIo\Routlt\Description\ActionDescriptorInterface The initialized descriptor |
168
|
|
|
*/ |
169
|
|
|
public function fromDeploymentDescriptor(\SimpleXmlElement $node) |
|
|
|
|
170
|
|
|
{ |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Initializes a action configuration instance from the passed configuration node. |
175
|
|
|
* |
176
|
|
|
* @param \AppserverIo\Configuration\Interfaces\NodeInterface $node The configuration node with the action configuration |
177
|
|
|
* |
178
|
|
|
* @return \AppserverIo\Routlt\Description\ActionDescriptorInterface The initialized descriptor |
179
|
|
|
*/ |
180
|
|
|
public function fromConfiguration(NodeInterface $node) |
|
|
|
|
181
|
|
|
{ |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Merges the passed configuration into this one. Configuration values |
186
|
|
|
* of the passed configuration will overwrite the this one. |
187
|
|
|
* |
188
|
|
|
* @param \AppserverIo\Routlt\Description\ResultDescriptorInterface $resultDescriptor The configuration to merge |
189
|
|
|
* |
190
|
|
|
* @return void |
191
|
|
|
* @throws \AppserverIo\Routlt\Description\DescriptorException Is thrown if the passed descriptor has a different method name |
192
|
|
|
*/ |
193
|
|
|
public function merge(ResultDescriptorInterface $resultDescriptor) |
194
|
|
|
{ |
195
|
|
|
|
196
|
|
|
// check if the classes are equal |
197
|
|
|
if ($this->getName() !== $resultDescriptor->getName()) { |
198
|
|
|
throw new DescriptorException( |
199
|
|
|
sprintf('You try to merge a result configuration for % with %s', $resultDescriptor->getName(), $this->getName()) |
200
|
|
|
); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
// merge the class name |
204
|
|
|
if ($className = $resultDescriptor->getClassName()) { |
205
|
|
|
$this->setClassName($className); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
// merge the shared flag |
209
|
|
|
$this->setShared($resultDescriptor->isShared()); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.