-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #434 from Ocramius/fix/variadic-arguments-remote-s…
…ervice-proxy-2.2.x Fix passing of variadic arguments to RPC adapters in remote object proxies (Backport of #443)
- Loading branch information
Showing
4 changed files
with
30 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,22 +7,16 @@ | |
use ProxyManager\Generator\MethodGenerator; | ||
use ProxyManager\Generator\Util\ProxiedMethodReturnExpression; | ||
use ReflectionClass; | ||
use Zend\Code\Generator\ParameterGenerator; | ||
use Zend\Code\Generator\PropertyGenerator; | ||
use Zend\Code\Reflection\MethodReflection; | ||
use function var_export; | ||
|
||
/** | ||
* Method decorator for remote objects | ||
* | ||
* @author Vincent Blanchon <[email protected]> | ||
* @license MIT | ||
*/ | ||
class RemoteObjectMethod extends MethodGenerator | ||
{ | ||
/** | ||
* @param \Zend\Code\Reflection\MethodReflection $originalMethod | ||
* @param \Zend\Code\Generator\PropertyGenerator $adapterProperty | ||
* @param \ReflectionClass $originalClass | ||
* | ||
* @return self|static | ||
*/ | ||
|
@@ -31,19 +25,13 @@ public static function generateMethod( | |
PropertyGenerator $adapterProperty, | ||
ReflectionClass $originalClass | ||
) : self { | ||
/* @var $method self */ | ||
$method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod); | ||
$list = array_values(array_map( | ||
function (ParameterGenerator $parameter) : string { | ||
return '$' . $parameter->getName(); | ||
}, | ||
$method->getParameters() | ||
)); | ||
/** @var self $method */ | ||
$method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod); | ||
|
||
$method->setBody( | ||
'$return = $this->' . $adapterProperty->getName() | ||
. '->call(' . var_export($originalClass->getName(), true) | ||
. ', ' . var_export($originalMethod->getName(), true) . ', array('. implode(', ', $list) .'));' . "\n\n" | ||
. ', ' . var_export($originalMethod->getName(), true) . ', \func_get_args());' . "\n\n" | ||
. ProxiedMethodReturnExpression::generate('$return', $originalMethod) | ||
); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tests/ProxyManagerTestAsset/RemoteProxy/VariadicArgumentsServiceInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ProxyManagerTestAsset\RemoteProxy; | ||
|
||
/** | ||
* Simple interface for a remote API that has a variadic number of arguments | ||
* | ||
* @author Marco Pivetta <[email protected]> | ||
* @license MIT | ||
*/ | ||
interface VariadicArgumentsServiceInterface | ||
{ | ||
public function method(string $param1, int ...$param2) : bool; | ||
} |