1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2013-2016 |
4
|
|
|
* Piotr Olaszewski <[email protected]> |
5
|
|
|
* |
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
8
|
|
|
* in the Software without restriction, including without limitation the rights |
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
11
|
|
|
* furnished to do so, subject to the following conditions: |
12
|
|
|
* |
13
|
|
|
* The above copyright notice and this permission notice shall be included in |
14
|
|
|
* all copies or substantial portions of the Software. |
15
|
|
|
* |
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22
|
|
|
* SOFTWARE. |
23
|
|
|
*/ |
24
|
|
|
namespace WSDL\Builder; |
25
|
|
|
|
26
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
27
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
28
|
|
|
use Ouzo\Utilities\Path; |
29
|
|
|
use ReflectionClass; |
30
|
|
|
use WSDL\Annotation\ClassAnnotation; |
31
|
|
|
use WSDL\Annotation\MethodAnnotation; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* AnnotationWSDLBuilder |
35
|
|
|
* |
36
|
|
|
* @author Piotr Olaszewski <[email protected]> |
37
|
|
|
*/ |
38
|
|
|
class AnnotationWSDLBuilder |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $class; |
44
|
|
|
/** |
45
|
|
|
* @var WSDLBuilder |
46
|
|
|
*/ |
47
|
|
|
private $builder; |
48
|
|
|
/** |
49
|
|
|
* @var AnnotationReader |
50
|
|
|
*/ |
51
|
|
|
private $annotationReader; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $class |
55
|
|
|
*/ |
56
|
5 |
|
public function __construct($class) |
57
|
1 |
|
{ |
58
|
5 |
|
AnnotationRegistry::registerAutoloadNamespace('WSDL\Annotation', Path::join(__DIR__, '..', '..')); |
59
|
5 |
|
$this->class = $class; |
60
|
5 |
|
$this->builder = WSDLBuilder::instance(); |
61
|
5 |
|
$this->annotationReader = new AnnotationReader(); |
62
|
5 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return ReflectionClass |
66
|
|
|
*/ |
67
|
5 |
|
private function reflectionClass() |
68
|
|
|
{ |
69
|
5 |
|
return new ReflectionClass($this->class); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return $this |
74
|
|
|
*/ |
75
|
5 |
|
public function build() |
76
|
|
|
{ |
77
|
5 |
|
$this->buildForClass(); |
78
|
5 |
|
$this->buildForMethods(); |
79
|
5 |
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
5 |
|
private function buildForClass() |
86
|
|
|
{ |
87
|
5 |
|
$class = $this->reflectionClass(); |
88
|
|
|
/** @var ClassAnnotation[] $classAnnotations */ |
89
|
5 |
|
$classAnnotations = $this->annotationReader->getClassAnnotations($class); |
90
|
5 |
|
foreach ($classAnnotations as $classAnnotation) { |
91
|
5 |
|
$classAnnotation->build($this->builder, $class); |
92
|
5 |
|
} |
93
|
5 |
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
5 |
|
private function buildForMethods() |
99
|
|
|
{ |
100
|
5 |
|
$classMethods = $this->reflectionClass()->getMethods(); |
101
|
5 |
|
$methods = []; |
102
|
5 |
|
foreach ($classMethods as $classMethod) { |
103
|
4 |
|
$methodBuilder = MethodBuilder::instance(); |
104
|
|
|
/** @var MethodAnnotation[] $methodAnnotations */ |
105
|
4 |
|
$methodAnnotations = $this->annotationReader->getMethodAnnotations($classMethod); |
106
|
4 |
|
foreach ($methodAnnotations as $methodAnnotation) { |
107
|
4 |
|
$methodAnnotation->build($methodBuilder, $classMethod); |
108
|
4 |
|
} |
109
|
4 |
|
$methods[] = $methodBuilder->build(); |
110
|
5 |
|
} |
111
|
5 |
|
$this->builder->setMethods($methods); |
112
|
5 |
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return WSDLBuilder |
116
|
|
|
*/ |
117
|
5 |
|
public function getBuilder() |
118
|
|
|
{ |
119
|
5 |
|
return $this->builder; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|