@@ -24,25 +24,25 @@ |
||
24 | 24 | class Helper |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * |
|
29 | - * |
|
30 | - * @since 0.1.0 |
|
31 | - * |
|
32 | - * @param ReflectionParameter[] $params The reflection parameters to parse. |
|
33 | - * @param array $args The arguments to check against. |
|
34 | - * @return array The correctly ordered arguments to pass to the reflected callable. |
|
35 | - */ |
|
36 | - public static function parse_params(array $params, $args) |
|
37 | - { |
|
38 | - $ordered_args = array(); |
|
27 | + /** |
|
28 | + * |
|
29 | + * |
|
30 | + * @since 0.1.0 |
|
31 | + * |
|
32 | + * @param ReflectionParameter[] $params The reflection parameters to parse. |
|
33 | + * @param array $args The arguments to check against. |
|
34 | + * @return array The correctly ordered arguments to pass to the reflected callable. |
|
35 | + */ |
|
36 | + public static function parse_params(array $params, $args) |
|
37 | + { |
|
38 | + $ordered_args = array(); |
|
39 | 39 | |
40 | - foreach ($params as $param) { |
|
41 | - $ordered_args[] = array_key_exists($param->name, $args) |
|
42 | - ? $args[$param->name] |
|
43 | - : $param->getDefaultValue(); |
|
44 | - } |
|
40 | + foreach ($params as $param) { |
|
41 | + $ordered_args[] = array_key_exists($param->name, $args) |
|
42 | + ? $args[$param->name] |
|
43 | + : $param->getDefaultValue(); |
|
44 | + } |
|
45 | 45 | |
46 | - return $ordered_args; |
|
47 | - } |
|
46 | + return $ordered_args; |
|
47 | + } |
|
48 | 48 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * MethodInvokerTrait |
|
4 | - * |
|
5 | - * @package BrightNucleus\Invoker |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license GPL-2.0+ |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2015-2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * MethodInvokerTrait |
|
4 | + * |
|
5 | + * @package BrightNucleus\Invoker |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license GPL-2.0+ |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2015-2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Invoker; |
13 | 13 | |
@@ -26,42 +26,42 @@ discard block |
||
26 | 26 | trait MethodInvokerTrait |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Check the accepted arguments for a given method and pass associative |
|
31 | - * array values in the right order. |
|
32 | - * |
|
33 | - * @since 0.1.0 |
|
34 | - * |
|
35 | - * @param object $object The object that contains the method to invoke. |
|
36 | - * @param string $method Name of the method to invoke. |
|
37 | - * @param array $args Associative array that contains the arguments. |
|
38 | - * @return mixed Return value of the invoked method. |
|
39 | - * @throws InvalidArgumentException If a valid method is missing. |
|
40 | - */ |
|
41 | - protected function invokeMethod($object, $method, array $args = []) |
|
42 | - { |
|
29 | + /** |
|
30 | + * Check the accepted arguments for a given method and pass associative |
|
31 | + * array values in the right order. |
|
32 | + * |
|
33 | + * @since 0.1.0 |
|
34 | + * |
|
35 | + * @param object $object The object that contains the method to invoke. |
|
36 | + * @param string $method Name of the method to invoke. |
|
37 | + * @param array $args Associative array that contains the arguments. |
|
38 | + * @return mixed Return value of the invoked method. |
|
39 | + * @throws InvalidArgumentException If a valid method is missing. |
|
40 | + */ |
|
41 | + protected function invokeMethod($object, $method, array $args = []) |
|
42 | + { |
|
43 | 43 | |
44 | - if (! $method || ! is_string($method) || '' === $method) { |
|
45 | - throw new InvalidArgumentException(_('Missing valid method to invoke.')); |
|
46 | - } |
|
44 | + if (! $method || ! is_string($method) || '' === $method) { |
|
45 | + throw new InvalidArgumentException(_('Missing valid method to invoke.')); |
|
46 | + } |
|
47 | 47 | |
48 | - try { |
|
49 | - $reflection = new ReflectionMethod(get_class($object), $method); |
|
50 | - $ordered_arguments = Helper::parse_params( |
|
51 | - $reflection->getParameters(), |
|
52 | - $args |
|
53 | - ); |
|
48 | + try { |
|
49 | + $reflection = new ReflectionMethod(get_class($object), $method); |
|
50 | + $ordered_arguments = Helper::parse_params( |
|
51 | + $reflection->getParameters(), |
|
52 | + $args |
|
53 | + ); |
|
54 | 54 | |
55 | - return $reflection->invokeArgs($object, $ordered_arguments); |
|
56 | - } catch (Exception $exception) { |
|
57 | - throw new InvalidArgumentException( |
|
58 | - sprintf( |
|
59 | - _('Failed to invoke method "%1$s" of class "%2$s". Reason: %3$s'), |
|
60 | - $method, |
|
61 | - get_class($object), |
|
62 | - $exception->getMessage() |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
66 | - } |
|
55 | + return $reflection->invokeArgs($object, $ordered_arguments); |
|
56 | + } catch (Exception $exception) { |
|
57 | + throw new InvalidArgumentException( |
|
58 | + sprintf( |
|
59 | + _('Failed to invoke method "%1$s" of class "%2$s". Reason: %3$s'), |
|
60 | + $method, |
|
61 | + get_class($object), |
|
62 | + $exception->getMessage() |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | + } |
|
67 | 67 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * FunctionInvokerTrait |
|
4 | - * |
|
5 | - * @package BrightNucleus\Invoker |
|
6 | - * @author Alain Schlesser <[email protected]> |
|
7 | - * @license GPL-2.0+ |
|
8 | - * @link http://www.brightnucleus.com/ |
|
9 | - * @copyright 2015-2016 Alain Schlesser, Bright Nucleus |
|
10 | - */ |
|
3 | + * FunctionInvokerTrait |
|
4 | + * |
|
5 | + * @package BrightNucleus\Invoker |
|
6 | + * @author Alain Schlesser <[email protected]> |
|
7 | + * @license GPL-2.0+ |
|
8 | + * @link http://www.brightnucleus.com/ |
|
9 | + * @copyright 2015-2016 Alain Schlesser, Bright Nucleus |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | namespace BrightNucleus\Invoker; |
13 | 13 | |
@@ -26,40 +26,40 @@ discard block |
||
26 | 26 | trait FunctionInvokerTrait |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * Check the accepted arguments for a given function and pass associative |
|
31 | - * array values in the right order. |
|
32 | - * |
|
33 | - * @since 0.1.0 |
|
34 | - * |
|
35 | - * @param string $function Name of the function to invoke. |
|
36 | - * @param array $args Associative array that contains the arguments. |
|
37 | - * @return mixed Return value of the invoked function. |
|
38 | - * @throws InvalidArgumentException If a valid function is missing. |
|
39 | - */ |
|
40 | - public function invokeFunction($function, array $args = array()) |
|
41 | - { |
|
29 | + /** |
|
30 | + * Check the accepted arguments for a given function and pass associative |
|
31 | + * array values in the right order. |
|
32 | + * |
|
33 | + * @since 0.1.0 |
|
34 | + * |
|
35 | + * @param string $function Name of the function to invoke. |
|
36 | + * @param array $args Associative array that contains the arguments. |
|
37 | + * @return mixed Return value of the invoked function. |
|
38 | + * @throws InvalidArgumentException If a valid function is missing. |
|
39 | + */ |
|
40 | + public function invokeFunction($function, array $args = array()) |
|
41 | + { |
|
42 | 42 | |
43 | - if (! $function || ! is_string($function) || '' === $function) { |
|
44 | - throw new InvalidArgumentException(_('Missing valid function to invoke.')); |
|
45 | - } |
|
43 | + if (! $function || ! is_string($function) || '' === $function) { |
|
44 | + throw new InvalidArgumentException(_('Missing valid function to invoke.')); |
|
45 | + } |
|
46 | 46 | |
47 | - try { |
|
48 | - $reflection = new ReflectionFunction($function); |
|
49 | - $ordered_arguments = Helper::parse_params( |
|
50 | - $reflection->getParameters(), |
|
51 | - $args |
|
52 | - ); |
|
47 | + try { |
|
48 | + $reflection = new ReflectionFunction($function); |
|
49 | + $ordered_arguments = Helper::parse_params( |
|
50 | + $reflection->getParameters(), |
|
51 | + $args |
|
52 | + ); |
|
53 | 53 | |
54 | - return $reflection->invokeArgs($ordered_arguments); |
|
55 | - } catch (Exception $exception) { |
|
56 | - throw new InvalidArgumentException( |
|
57 | - sprintf( |
|
58 | - _('Failed to invoke function "%1$s". Reason: %2$s'), |
|
59 | - $function, |
|
60 | - $exception->getMessage() |
|
61 | - ) |
|
62 | - ); |
|
63 | - } |
|
64 | - } |
|
54 | + return $reflection->invokeArgs($ordered_arguments); |
|
55 | + } catch (Exception $exception) { |
|
56 | + throw new InvalidArgumentException( |
|
57 | + sprintf( |
|
58 | + _('Failed to invoke function "%1$s". Reason: %2$s'), |
|
59 | + $function, |
|
60 | + $exception->getMessage() |
|
61 | + ) |
|
62 | + ); |
|
63 | + } |
|
64 | + } |
|
65 | 65 | } |