1 | <?php |
||
11 | class Method extends AbstractModel |
||
12 | { |
||
13 | /** |
||
14 | * Type of the parameter for the operation |
||
15 | * @var string |
||
16 | */ |
||
17 | private $parameterType = ''; |
||
18 | /** |
||
19 | * Type of the return value for the operation |
||
20 | * @var string |
||
21 | */ |
||
22 | private $returnType = ''; |
||
23 | /** |
||
24 | * Indicates function is not alone with this name, then its name is contextualized based on its parameter(s) |
||
25 | * @var bool |
||
26 | */ |
||
27 | private $isUnique = true; |
||
28 | /** |
||
29 | * Generated method name stored as soon as it has been defined once |
||
30 | * @var string |
||
31 | */ |
||
32 | private $methodName = null; |
||
33 | /** |
||
34 | * Main constructor |
||
35 | * @see AbstractModel::__construct() |
||
36 | * @uses Method::setParameterType() |
||
37 | * @uses Method::setReturnType() |
||
38 | * @uses AbstractModel::setOwner() |
||
39 | * @param Generator $generator |
||
40 | * @param string $name the function name |
||
41 | * @param string|array $parameterType the type/name of the parameter |
||
42 | * @param string|array $returnType the type/name of the return value |
||
43 | * @param Service $service defines the struct which owns this value |
||
44 | * @param bool $isUnique defines if the method is unique or not |
||
45 | */ |
||
46 | 798 | public function __construct(Generator $generator, $name, $parameterType, $returnType, Service $service, $isUnique = true) |
|
51 | /** |
||
52 | * Method name can't starts with numbers |
||
53 | * @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::getCleanName() |
||
54 | * @return string |
||
55 | */ |
||
56 | 798 | public function getCleanName($keepMultipleUnderscores = true) |
|
60 | /** |
||
61 | * Returns the name of the method that is used to call the operation |
||
62 | * It takes care of the fact that the method might not be the only one named as it is. |
||
63 | * @uses Method::getCleanName() |
||
64 | * @uses AbstractModel::replacePhpReservedKeyword() |
||
65 | * @uses AbstractModel::getOwner() |
||
66 | * @uses AbstractModel::getPackagedName() |
||
67 | * @uses AbstractModel::uniqueName() |
||
68 | * @uses Method::getOwner() |
||
69 | * @uses Method::getParameterType() |
||
70 | * @uses Method::isUnique() |
||
71 | * @return string |
||
72 | */ |
||
73 | 798 | public function getMethodName() |
|
74 | { |
||
75 | 798 | if (empty($this->methodName)) { |
|
76 | 798 | $methodName = $this->getCleanName(); |
|
77 | 798 | if (!$this->isUnique()) { |
|
78 | 24 | if (is_string($this->getParameterType())) { |
|
79 | 24 | $methodName .= ucfirst($this->getParameterType()); |
|
80 | 16 | } else { |
|
81 | 6 | $methodName .= '_' . md5(var_export($this->getParameterType(), true)); |
|
82 | } |
||
83 | 16 | } |
|
84 | 798 | $context = $this->getOwner()->getPackagedName(); |
|
85 | 798 | $methodName = $this->replaceReservedMethod($methodName, $context); |
|
86 | 798 | $methodName = self::replacePhpReservedKeyword($methodName, $context); |
|
87 | 798 | $this->methodName = self::uniqueName($methodName, $this->getOwner()->getPackagedName()); |
|
88 | 532 | } |
|
89 | 798 | return $this->methodName; |
|
90 | } |
||
91 | /** |
||
92 | * Returns the parameter type |
||
93 | * @return string|string[] |
||
94 | */ |
||
95 | 570 | public function getParameterType() |
|
99 | /** |
||
100 | * Set the parameter type |
||
101 | * @param string|string[] |
||
102 | * @return Method |
||
103 | */ |
||
104 | 798 | public function setParameterType($parameterType) |
|
109 | /** |
||
110 | * Returns the retrun type |
||
111 | * @return string |
||
112 | */ |
||
113 | 468 | public function getReturnType() |
|
117 | /** |
||
118 | * Set the retrun type |
||
119 | * @param string|string[] |
||
120 | * @return Method |
||
121 | */ |
||
122 | 798 | public function setReturnType($returnType) |
|
127 | /** |
||
128 | * Returns the isUnique property |
||
129 | * @return bool |
||
130 | */ |
||
131 | 798 | public function isUnique() |
|
132 | { |
||
133 | 798 | return $this->isUnique; |
|
134 | } |
||
135 | /** |
||
136 | * Set the isUnique property |
||
137 | * @param bool |
||
138 | * @return Method |
||
139 | */ |
||
140 | 798 | public function setUnique($isUnique) |
|
141 | { |
||
142 | 798 | $this->isUnique = $isUnique; |
|
143 | 798 | return $this; |
|
144 | } |
||
145 | /** |
||
146 | * Returns the owner model object, meaning a Service object |
||
147 | * @see AbstractModel::getOwner() |
||
148 | * @uses AbstractModel::getOwner() |
||
149 | * @return Service |
||
150 | */ |
||
151 | 798 | public function getOwner() |
|
155 | /** |
||
156 | * @param $filename |
||
157 | * @return ServiceReservedMethod |
||
158 | */ |
||
159 | 798 | public function getReservedMethodsInstance($filename = null) |
|
163 | } |
||
164 |