1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace WsdlToPhp\PackageGenerator\Model; |
||
6 | |||
7 | use WsdlToPhp\PackageGenerator\ConfigurationReader\ServiceReservedMethod; |
||
8 | use WsdlToPhp\PackageGenerator\Container\Model\Method as MethodContainer; |
||
9 | use WsdlToPhp\PackageGenerator\Generator\Generator; |
||
10 | use WsdlToPhp\PackageGenerator\Generator\Utils; |
||
11 | |||
12 | /** |
||
13 | * Class Service stands for an available service containing the methods/operations described in the WSDL. |
||
14 | */ |
||
15 | class Service extends AbstractModel |
||
16 | { |
||
17 | public const DEFAULT_SERVICE_CLASS_NAME = 'Service'; |
||
18 | |||
19 | protected MethodContainer $methods; |
||
20 | |||
21 | 372 | public function __construct(Generator $generator, string $name) |
|
22 | { |
||
23 | 372 | parent::__construct($generator, $name); |
|
24 | 372 | $this->setMethods(new MethodContainer($generator)); |
|
25 | } |
||
26 | |||
27 | 368 | public function getContextualPart(): string |
|
28 | { |
||
29 | 368 | return $this->getGenerator()->getOptionServicesFolder(); |
|
30 | } |
||
31 | |||
32 | 46 | public function getDocSubPackages(): array |
|
33 | { |
||
34 | 46 | return [ |
|
35 | 46 | 'Services', |
|
36 | 46 | ]; |
|
37 | } |
||
38 | |||
39 | 78 | public function getMethods(): MethodContainer |
|
40 | { |
||
41 | 78 | return $this->methods; |
|
42 | } |
||
43 | |||
44 | 148 | public function addMethod(string $methodName, $methodParameterType, $methodReturnType, $methodIsUnique = true): Method |
|
45 | { |
||
46 | 148 | $method = new Method($this->getGenerator(), $methodName, $methodParameterType, $methodReturnType, $this, $methodIsUnique); |
|
47 | 148 | $this->methods->add($method); |
|
48 | |||
49 | 148 | return $method; |
|
50 | } |
||
51 | |||
52 | 180 | public function getMethod(string $methodName): ?Method |
|
53 | { |
||
54 | 180 | return $this->methods->getMethodByName($methodName); |
|
55 | } |
||
56 | |||
57 | 46 | public function getExtends(bool $short = false): string |
|
58 | { |
||
59 | 46 | $extends = $this->getGenerator()->getOptionSoapClientClass(); |
|
60 | |||
61 | 46 | return $short ? Utils::removeNamespace($extends) : $extends; |
|
62 | } |
||
63 | |||
64 | 2 | public function getReservedMethodsInstance(?string $filename = null): ServiceReservedMethod |
|
65 | { |
||
66 | 2 | return ServiceReservedMethod::instance($filename); |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
67 | } |
||
68 | |||
69 | 214 | public function setMethodsFromSerializedJson(array $methods): void |
|
70 | { |
||
71 | 214 | foreach ($methods as $method) { |
|
72 | 214 | $this->methods->add(self::instanceFromSerializedJson($this->generator, $method)->setOwner($this)); |
|
73 | } |
||
74 | } |
||
75 | |||
76 | 372 | protected function setMethods(MethodContainer $methodContainer): self |
|
77 | { |
||
78 | 372 | $this->methods = $methodContainer; |
|
79 | |||
80 | 372 | return $this; |
|
81 | } |
||
82 | |||
83 | 2 | protected function toJsonSerialize(): array |
|
84 | { |
||
85 | 2 | return [ |
|
86 | 2 | 'methods' => $this->methods, |
|
87 | 2 | ]; |
|
88 | } |
||
89 | } |
||
90 |