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; |
25
|
|
|
|
26
|
|
|
use BadMethodCallException; |
27
|
|
|
use Ouzo\Utilities\Arrays; |
28
|
|
|
use Ouzo\Utilities\Functions; |
29
|
|
|
use ReflectionMethod; |
30
|
|
|
use stdClass; |
31
|
|
|
use WSDL\Parser\MethodParser; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Provide a wrapper for |
35
|
|
|
* Provider helper class handlers serving wrapped document/literal method can |
36
|
|
|
* extend to automatically wrap the response in an appropriate wrapper |
37
|
|
|
*/ |
38
|
|
|
class DocumentLiteralWrapper |
39
|
|
|
{ |
40
|
|
|
private $_obj = null; |
41
|
|
|
|
42
|
2 |
|
public function __construct($obj) |
43
|
|
|
{ |
44
|
2 |
|
$this->_obj = $obj; |
45
|
2 |
|
} |
46
|
|
|
|
47
|
2 |
|
public function __call($method, $args) |
48
|
|
|
{ |
49
|
2 |
|
if (!method_exists($this->_obj, $method)) { |
50
|
|
|
throw new BadMethodCallException('Unknown method [' . $method . ']'); |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
$reflectedMethod = new ReflectionMethod($this->_obj, $method); |
54
|
2 |
|
$parsedMethod = new MethodParser($method, $reflectedMethod->getDocComment()); |
55
|
2 |
|
$parameters = $parsedMethod->parameters(); |
56
|
2 |
|
$returning = $parsedMethod->returning(); |
|
|
|
|
57
|
|
|
|
58
|
2 |
|
$args = $this->_parseArgs($args, $parameters); |
59
|
2 |
|
$return = call_user_func_array(array($this->_obj, $method), $args); |
60
|
|
|
|
61
|
2 |
|
if (is_array($return)) { |
62
|
1 |
|
$obj = new stdClass(); |
63
|
1 |
|
foreach(array_keys($return) as $returnVariable) { |
64
|
1 |
|
$obj->$returnVariable = $return[$returnVariable]; |
65
|
1 |
|
} |
66
|
1 |
|
return $obj; |
67
|
|
|
} |
68
|
1 |
|
return $return; |
69
|
|
|
} |
70
|
|
|
|
71
|
2 |
|
private function _parseArgs($args, $parameters) |
72
|
|
|
{ |
73
|
2 |
|
$args = Arrays::getValue($args, 0, new stdClass()); |
74
|
2 |
|
$newArgs = array(); |
75
|
2 |
|
$parameterNames = Arrays::map($parameters, Functions::extract()->getName()); |
76
|
2 |
|
foreach ($parameterNames as $name) { |
77
|
2 |
|
if (isset($args->$name)) { |
78
|
1 |
|
$newArgs[] = $args->$name; |
79
|
1 |
|
} |
80
|
2 |
|
} |
81
|
2 |
|
return $newArgs; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.