@@ -10,69 +10,69 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class DefaultCallableStrategy implements ResolvableInterface |
| 12 | 12 | { |
| 13 | - const DEFAULT_METHOD_SEPARATOR = '::'; |
|
| 13 | + const DEFAULT_METHOD_SEPARATOR = '::'; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * @var ContainerInterface |
| 17 | 17 | */ |
| 18 | 18 | private $container; |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var null|string |
|
| 20 | + /** |
|
| 21 | + * @var null|string |
|
| 22 | 22 | */ |
| 23 | - private $method_separator; |
|
| 23 | + private $method_separator; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * DefaultCallableStrategy constructor. |
|
| 25 | + /** |
|
| 26 | + * DefaultCallableStrategy constructor. |
|
| 27 | 27 | * @param \Interop\Container\ContainerInterface $container |
| 28 | - * @param string $method_separator |
|
| 28 | + * @param string $method_separator |
|
| 29 | 29 | */ |
| 30 | - public function __construct(ContainerInterface $container = null, $method_separator = null) { |
|
| 30 | + public function __construct(ContainerInterface $container = null, $method_separator = null) { |
|
| 31 | 31 | $this->container = $container; |
| 32 | - $this->method_separator = ($method_separator === null) ? self::DEFAULT_METHOD_SEPARATOR : $method_separator; |
|
| 33 | - } |
|
| 32 | + $this->method_separator = ($method_separator === null) ? self::DEFAULT_METHOD_SEPARATOR : $method_separator; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param string $in |
|
| 37 | - * @return array |
|
| 38 | - * @throws \Exception |
|
| 35 | + /** |
|
| 36 | + * @param string $in |
|
| 37 | + * @return array |
|
| 38 | + * @throws \Exception |
|
| 39 | 39 | */ |
| 40 | - public function resolve($in) |
|
| 41 | - { |
|
| 42 | - $pos = strrpos($in, $this->method_separator); |
|
| 43 | - if ($pos === false) { |
|
| 44 | - throw new \Exception(sprintf('Method separator not found in %s', $in)); |
|
| 45 | - } |
|
| 40 | + public function resolve($in) |
|
| 41 | + { |
|
| 42 | + $pos = strrpos($in, $this->method_separator); |
|
| 43 | + if ($pos === false) { |
|
| 44 | + throw new \Exception(sprintf('Method separator not found in %s', $in)); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if ($pos === 0) { |
|
| 48 | - // Use backtrace to find the calling Class |
|
| 49 | - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); |
|
| 50 | - $class = $trace[2]['class']; |
|
| 51 | - $method = substr($in, $pos + strlen($this->method_separator)); |
|
| 52 | - } else { |
|
| 53 | - $class = substr($in, 0, $pos); |
|
| 54 | - $method = substr($in, $pos + strlen($this->method_separator)); |
|
| 55 | - } |
|
| 47 | + if ($pos === 0) { |
|
| 48 | + // Use backtrace to find the calling Class |
|
| 49 | + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); |
|
| 50 | + $class = $trace[2]['class']; |
|
| 51 | + $method = substr($in, $pos + strlen($this->method_separator)); |
|
| 52 | + } else { |
|
| 53 | + $class = substr($in, 0, $pos); |
|
| 54 | + $method = substr($in, $pos + strlen($this->method_separator)); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - if ($this->container !== null && $this->container->has($class)) { |
|
| 58 | - $class = $this->container->get($class); |
|
| 59 | - } |
|
| 57 | + if ($this->container !== null && $this->container->has($class)) { |
|
| 58 | + $class = $this->container->get($class); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return [$class, $method]; |
|
| 62 | - } |
|
| 61 | + return [$class, $method]; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param $in |
|
| 66 | - * @return array |
|
| 67 | - * @throws \Exception |
|
| 68 | - */ |
|
| 69 | - public function resolveSafe($in) |
|
| 70 | - { |
|
| 71 | - $callable = $this->resolve($in); |
|
| 72 | - if (is_callable($callable)) { |
|
| 73 | - return $callable; |
|
| 74 | - } |
|
| 64 | + /** |
|
| 65 | + * @param $in |
|
| 66 | + * @return array |
|
| 67 | + * @throws \Exception |
|
| 68 | + */ |
|
| 69 | + public function resolveSafe($in) |
|
| 70 | + { |
|
| 71 | + $callable = $this->resolve($in); |
|
| 72 | + if (is_callable($callable)) { |
|
| 73 | + return $callable; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - throw new \Exception(sprintf('Could not resolve %s to a callable', $in)); |
|
| 77 | - } |
|
| 76 | + throw new \Exception(sprintf('Could not resolve %s to a callable', $in)); |
|
| 77 | + } |
|
| 78 | 78 | } |
| 79 | 79 | \ No newline at end of file |
@@ -8,29 +8,29 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class CallableResolver implements StrategyAwareInterface |
| 10 | 10 | { |
| 11 | - use StrategyAwareTrait; |
|
| 11 | + use StrategyAwareTrait; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * CallableResolver constructor. |
|
| 13 | + /** |
|
| 14 | + * CallableResolver constructor. |
|
| 15 | 15 | */ |
| 16 | - public function __construct() |
|
| 17 | - { |
|
| 18 | - $this->setStrategy(new DefaultCallableStrategy()); |
|
| 19 | - } |
|
| 16 | + public function __construct() |
|
| 17 | + { |
|
| 18 | + $this->setStrategy(new DefaultCallableStrategy()); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param string $in |
|
| 23 | - * @return mixed |
|
| 21 | + /** |
|
| 22 | + * @param string $in |
|
| 23 | + * @return mixed |
|
| 24 | 24 | */ |
| 25 | - public function resolve($in) { |
|
| 25 | + public function resolve($in) { |
|
| 26 | 26 | return $this->getStrategy()->resolve($in); |
| 27 | - } |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param string $in |
|
| 31 | - * @return mixed |
|
| 32 | - */ |
|
| 33 | - public function resolveSafe($in) { |
|
| 34 | - return $this->getStrategy()->resolveSafe($in); |
|
| 35 | - } |
|
| 29 | + /** |
|
| 30 | + * @param string $in |
|
| 31 | + * @return mixed |
|
| 32 | + */ |
|
| 33 | + public function resolveSafe($in) { |
|
| 34 | + return $this->getStrategy()->resolveSafe($in); |
|
| 35 | + } |
|
| 36 | 36 | } |
| 37 | 37 | \ No newline at end of file |