1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2013-2015 |
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\Parser; |
25
|
|
|
|
26
|
|
|
use Ouzo\Utilities\Strings; |
27
|
|
|
use ReflectionClass; |
28
|
|
|
use ReflectionMethod; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* ClassParser |
32
|
|
|
* |
33
|
|
|
* @author Piotr Olaszewski <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class ClassParser |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var ReflectionClass |
39
|
|
|
*/ |
40
|
|
|
private $reflectedClass; |
41
|
|
|
/** |
42
|
|
|
* @var MethodParser[] |
43
|
|
|
*/ |
44
|
|
|
private $methodDocComments = array(); |
45
|
|
|
|
46
|
9 |
|
public function __construct($className) |
47
|
|
|
{ |
48
|
9 |
|
$this->reflectedClass = new ReflectionClass($className); |
49
|
9 |
|
} |
50
|
|
|
|
51
|
9 |
|
public function parse() |
52
|
|
|
{ |
53
|
9 |
|
$this->allPublicMethodDocComment(); |
54
|
9 |
|
} |
55
|
|
|
|
56
|
9 |
|
private function allPublicMethodDocComment() |
57
|
|
|
{ |
58
|
9 |
|
$reflectionClassMethods = $this->reflectedClass->getMethods(); |
59
|
9 |
|
foreach ($reflectionClassMethods as $reflectionMethod) { |
60
|
9 |
|
if ($this->canParseMethod($reflectionMethod)) { |
61
|
9 |
|
$methodName = $reflectionMethod->getName(); |
|
|
|
|
62
|
9 |
|
$methodDocComment = $reflectionMethod->getDocComment(); |
63
|
9 |
|
$this->methodDocComments[] = new MethodParser($methodName, $methodDocComment); |
64
|
9 |
|
} |
65
|
9 |
|
} |
66
|
9 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param ReflectionMethod $method |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
9 |
|
private function canParseMethod(ReflectionMethod $method) |
73
|
|
|
{ |
74
|
|
|
return |
75
|
9 |
|
Strings::contains($method->getDocComment(), '@WebMethod') && |
76
|
9 |
|
$method->isPublic() && |
77
|
9 |
|
!$method->isConstructor() && |
78
|
9 |
|
!$method->isDestructor() && |
79
|
9 |
|
!Strings::contains($method->getName(), '__'); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return MethodParser[] |
84
|
|
|
*/ |
85
|
9 |
|
public function getMethods() |
86
|
|
|
{ |
87
|
9 |
|
return $this->methodDocComments; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|