@@ -40,7 +40,7 @@ |
||
40 | 40 | public function invokeFunction($function, array $args = array()) |
41 | 41 | { |
42 | 42 | |
43 | - if (! $function || ! is_string($function) || '' === $function) { |
|
43 | + if ( ! $function || ! is_string($function) || '' === $function) { |
|
44 | 44 | throw new InvalidArgumentException(_('Missing valid function to invoke.')); |
45 | 45 | } |
46 | 46 |
@@ -26,40 +26,40 @@ |
||
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::parseParams( |
|
50 | - $reflection->getParameters(), |
|
51 | - $args |
|
52 | - ); |
|
47 | + try { |
|
48 | + $reflection = new ReflectionFunction($function); |
|
49 | + $ordered_arguments = Helper::parseParams( |
|
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 | } |
@@ -25,34 +25,34 @@ |
||
25 | 25 | class Helper |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * |
|
30 | - * |
|
31 | - * @since 0.1.0 |
|
32 | - * |
|
33 | - * @param ReflectionParameter[] $params The reflection parameters to parse. |
|
34 | - * @param array $args The arguments to check against. |
|
35 | - * @return array The correctly ordered arguments to pass to the reflected callable. |
|
36 | - * @throws RuntimeException If a $param does not have a name() method. |
|
37 | - */ |
|
38 | - public static function parseParams(array $params, $args) |
|
39 | - { |
|
40 | - $ordered_args = array(); |
|
28 | + /** |
|
29 | + * |
|
30 | + * |
|
31 | + * @since 0.1.0 |
|
32 | + * |
|
33 | + * @param ReflectionParameter[] $params The reflection parameters to parse. |
|
34 | + * @param array $args The arguments to check against. |
|
35 | + * @return array The correctly ordered arguments to pass to the reflected callable. |
|
36 | + * @throws RuntimeException If a $param does not have a name() method. |
|
37 | + */ |
|
38 | + public static function parseParams(array $params, $args) |
|
39 | + { |
|
40 | + $ordered_args = array(); |
|
41 | 41 | |
42 | - foreach ($params as $param) { |
|
43 | - if (! $param instanceof ReflectionParameter) { |
|
44 | - throw new RuntimeException( |
|
45 | - sprintf( |
|
46 | - _('Parameter %1$s is not an instance of ReflectionParameter.'), |
|
47 | - $param |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
51 | - $ordered_args[] = array_key_exists($param->name, $args) |
|
52 | - ? $args[$param->name] |
|
53 | - : $param->getDefaultValue(); |
|
54 | - } |
|
42 | + foreach ($params as $param) { |
|
43 | + if (! $param instanceof ReflectionParameter) { |
|
44 | + throw new RuntimeException( |
|
45 | + sprintf( |
|
46 | + _('Parameter %1$s is not an instance of ReflectionParameter.'), |
|
47 | + $param |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | + $ordered_args[] = array_key_exists($param->name, $args) |
|
52 | + ? $args[$param->name] |
|
53 | + : $param->getDefaultValue(); |
|
54 | + } |
|
55 | 55 | |
56 | - return $ordered_args; |
|
57 | - } |
|
56 | + return $ordered_args; |
|
57 | + } |
|
58 | 58 | } |
@@ -40,7 +40,7 @@ |
||
40 | 40 | $ordered_args = array(); |
41 | 41 | |
42 | 42 | foreach ($params as $param) { |
43 | - if (! $param instanceof ReflectionParameter) { |
|
43 | + if ( ! $param instanceof ReflectionParameter) { |
|
44 | 44 | throw new RuntimeException( |
45 | 45 | sprintf( |
46 | 46 | _('Parameter %1$s is not an instance of ReflectionParameter.'), |
@@ -27,41 +27,41 @@ |
||
27 | 27 | trait InstantiatorTrait |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Check the accepted arguments for a given class constructor and pass |
|
32 | - * associative array values in the right order. |
|
33 | - * |
|
34 | - * @since 0.2.0 |
|
35 | - * |
|
36 | - * @param string $class The class that needs to be instantiated. |
|
37 | - * @param array $args Associative array that contains the arguments. |
|
38 | - * |
|
39 | - * @return object Instantiated object. |
|
40 | - * @throws InvalidArgumentException If a valid method is missing. |
|
41 | - */ |
|
42 | - protected function instantiateClass($class, array $args) |
|
43 | - { |
|
44 | - try { |
|
45 | - $reflectionMethod = new ReflectionMethod($class, '__construct'); |
|
30 | + /** |
|
31 | + * Check the accepted arguments for a given class constructor and pass |
|
32 | + * associative array values in the right order. |
|
33 | + * |
|
34 | + * @since 0.2.0 |
|
35 | + * |
|
36 | + * @param string $class The class that needs to be instantiated. |
|
37 | + * @param array $args Associative array that contains the arguments. |
|
38 | + * |
|
39 | + * @return object Instantiated object. |
|
40 | + * @throws InvalidArgumentException If a valid method is missing. |
|
41 | + */ |
|
42 | + protected function instantiateClass($class, array $args) |
|
43 | + { |
|
44 | + try { |
|
45 | + $reflectionMethod = new ReflectionMethod($class, '__construct'); |
|
46 | 46 | |
47 | - $ordered_arguments = Helper::parseParams( |
|
48 | - $reflectionMethod->getParameters(), |
|
49 | - $args |
|
50 | - ); |
|
47 | + $ordered_arguments = Helper::parseParams( |
|
48 | + $reflectionMethod->getParameters(), |
|
49 | + $args |
|
50 | + ); |
|
51 | 51 | |
52 | - $reflectionClass = new ReflectionClass($class); |
|
52 | + $reflectionClass = new ReflectionClass($class); |
|
53 | 53 | |
54 | - return $reflectionClass->newInstanceArgs( |
|
55 | - (array)$ordered_arguments |
|
56 | - ); |
|
57 | - } catch (Exception $exception) { |
|
58 | - throw new InvalidArgumentException( |
|
59 | - sprintf( |
|
60 | - _('Failed to instantiate class "%1$s". Reason: %2$s'), |
|
61 | - $class, |
|
62 | - $exception->getMessage() |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
66 | - } |
|
54 | + return $reflectionClass->newInstanceArgs( |
|
55 | + (array)$ordered_arguments |
|
56 | + ); |
|
57 | + } catch (Exception $exception) { |
|
58 | + throw new InvalidArgumentException( |
|
59 | + sprintf( |
|
60 | + _('Failed to instantiate class "%1$s". Reason: %2$s'), |
|
61 | + $class, |
|
62 | + $exception->getMessage() |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | + } |
|
67 | 67 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | $reflectionClass = new ReflectionClass($class); |
53 | 53 | |
54 | 54 | return $reflectionClass->newInstanceArgs( |
55 | - (array)$ordered_arguments |
|
55 | + (array) $ordered_arguments |
|
56 | 56 | ); |
57 | 57 | } catch (Exception $exception) { |
58 | 58 | throw new InvalidArgumentException( |
@@ -26,42 +26,42 @@ |
||
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::parseParams( |
|
51 | - $reflection->getParameters(), |
|
52 | - $args |
|
53 | - ); |
|
48 | + try { |
|
49 | + $reflection = new ReflectionMethod(get_class($object), $method); |
|
50 | + $ordered_arguments = Helper::parseParams( |
|
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 | } |
@@ -41,7 +41,7 @@ |
||
41 | 41 | protected function invokeMethod($object, $method, array $args = []) |
42 | 42 | { |
43 | 43 | |
44 | - if (! $method || ! is_string($method) || '' === $method) { |
|
44 | + if ( ! $method || ! is_string($method) || '' === $method) { |
|
45 | 45 | throw new InvalidArgumentException(_('Missing valid method to invoke.')); |
46 | 46 | } |
47 | 47 |