diff --git a/src/PHPRouter/DI/ContainerInterface.php b/src/PHPRouter/DI/ContainerInterface.php new file mode 100644 index 0000000..e98ec1a --- /dev/null +++ b/src/PHPRouter/DI/ContainerInterface.php @@ -0,0 +1,15 @@ +_url = $resource; $this->_config = $config; + $this->_container= $container; + $this->_methods = isset($config['methods']) ? $config['methods'] : array(); $this->_target = isset($config['target']) ? $config['target'] : null; } @@ -120,6 +132,16 @@ public function getParameters() return $this->_parameters; } + /** + * @return object + */ + public function getContainer() + { + return $this->_container; + } + + + public function setParameters(array $parameters) { $this->_parameters = $parameters; @@ -129,6 +151,15 @@ public function dispatch() { $action = explode('::', $this->_config['_controller']); $instance = new $action[0]; + + if($this->getContainer() && $instance instanceof InjectableInterface){ + $instance->setServiceContainer($this->getContainer()); + }else{ + throw new InjectionException('To inject container you need to implement InjectableInterface'); + } + call_user_func_array(array($instance, $action[1]), $this->_parameters); } + + }