1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WsdlToPhp\PackageGenerator\Model; |
4
|
|
|
|
5
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Utils; |
6
|
|
|
use WsdlToPhp\PackageGenerator\Container\Model\Method as MethodContainer; |
7
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Generator; |
8
|
|
|
use WsdlToPhp\PackageGenerator\ConfigurationReader\ServiceReservedMethod; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Service stands for an available service containing the methods/operations described in the WSDL |
12
|
|
|
*/ |
13
|
|
|
class Service extends AbstractModel |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
const DEFAULT_SERVICE_CLASS_NAME = 'Service'; |
19
|
|
|
/** |
20
|
|
|
* Store the methods of the service |
21
|
|
|
* @var MethodContainer |
22
|
|
|
*/ |
23
|
|
|
private $methods; |
24
|
|
|
/** |
25
|
|
|
* Main constructor |
26
|
|
|
* @see AbstractModel::__construct() |
27
|
|
|
* @uses Service::setMethods() |
28
|
|
|
* @param Generator $generator |
29
|
|
|
* @param string $name the service name |
30
|
|
|
*/ |
31
|
810 |
|
public function __construct(Generator $generator, $name) |
32
|
|
|
{ |
33
|
810 |
|
parent::__construct($generator, $name); |
34
|
810 |
|
$this->setMethods(new MethodContainer($generator)); |
35
|
810 |
|
} |
36
|
|
|
/** |
37
|
|
|
* Returns the contextual part of the class name for the package |
38
|
|
|
* @see AbstractModel::getContextualPart() |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
798 |
|
public function getContextualPart() |
42
|
|
|
{ |
43
|
798 |
|
return $this->getGenerator()->getOptionServicesFolder(); |
44
|
|
|
} |
45
|
|
|
/** |
46
|
|
|
* Returns the sub package name which the model belongs to |
47
|
|
|
* Must be overridden by sub classes |
48
|
|
|
* @see AbstractModel::getDocSubPackages() |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
132 |
|
public function getDocSubPackages() |
52
|
|
|
{ |
53
|
|
|
return array( |
54
|
132 |
|
'Services', |
55
|
88 |
|
); |
56
|
|
|
} |
57
|
|
|
/** |
58
|
|
|
* Returns the methods of the service |
59
|
|
|
* @return MethodContainer |
60
|
|
|
*/ |
61
|
204 |
|
public function getMethods() |
62
|
|
|
{ |
63
|
204 |
|
return $this->methods; |
64
|
|
|
} |
65
|
|
|
/** |
66
|
|
|
* Sets the methods container |
67
|
|
|
* @param MethodContainer $methodContainer |
68
|
|
|
* @return Service |
69
|
|
|
*/ |
70
|
810 |
|
private function setMethods(MethodContainer $methodContainer) |
71
|
|
|
{ |
72
|
810 |
|
$this->methods = $methodContainer; |
73
|
810 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
/** |
76
|
|
|
* Adds a method to the service |
77
|
|
|
* @uses Method::setUnique() |
78
|
|
|
* @param string $methodName original method name |
79
|
|
|
* @param string|array $methodParameterType original parameter type/name |
80
|
|
|
* @param string|array $methodReturnType original return type/name |
81
|
|
|
* @param bool $methodIsUnique original isUnique value |
82
|
|
|
* @return Method |
83
|
|
|
*/ |
84
|
792 |
|
public function addMethod($methodName, $methodParameterType, $methodReturnType, $methodIsUnique = true) |
85
|
|
|
{ |
86
|
792 |
|
$method = new Method($this->getGenerator(), $methodName, $methodParameterType, $methodReturnType, $this, $methodIsUnique); |
87
|
792 |
|
$this->methods->add($method); |
88
|
792 |
|
return $method; |
89
|
|
|
} |
90
|
|
|
/** |
91
|
|
|
* Returns the method by its original name |
92
|
|
|
* @uses Service::getMethods() |
93
|
|
|
* @uses AbstractModel::getName() |
94
|
|
|
* @param string $methodName the original method name |
95
|
|
|
* @return Method|null |
96
|
|
|
*/ |
97
|
804 |
|
public function getMethod($methodName) |
98
|
|
|
{ |
99
|
804 |
|
return $this->methods->getMethodByName($methodName); |
100
|
|
|
} |
101
|
|
|
/** |
102
|
|
|
* Allows to define from which class the curent model extends |
103
|
|
|
* @param bool $short |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
132 |
|
public function getExtends($short = false) |
107
|
|
|
{ |
108
|
132 |
|
$extends = $this->getGenerator()->getOptionSoapClientClass(); |
109
|
132 |
|
return $short ? Utils::removeNamespace($extends) : $extends; |
110
|
|
|
} |
111
|
|
|
/** |
112
|
|
|
* @param $filename |
113
|
|
|
* @return ServiceReservedMethod |
114
|
|
|
*/ |
115
|
6 |
|
public function getReservedMethodsInstance($filename = null) |
116
|
|
|
{ |
117
|
6 |
|
return ServiceReservedMethod::instance($filename); |
118
|
|
|
} |
119
|
|
|
/** |
120
|
|
|
* {@inheritDoc} |
121
|
|
|
* @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::toJsonSerialize() |
122
|
|
|
*/ |
123
|
|
|
protected function toJsonSerialize() |
124
|
|
|
{ |
125
|
|
|
return array( |
126
|
|
|
'methods' => $this->methods, |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
/** |
130
|
|
|
* @param array $methods |
131
|
|
|
*/ |
132
|
|
|
public function setMethodsFromSerializedJson(array $methods) |
133
|
|
|
{ |
134
|
|
|
foreach ($methods as $method) { |
135
|
|
|
$this->methods->add(self::instanceFromSerializedJson($this->generator, $method)->setOwner($this)); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|