/** * {@inheritdoc} */ protected function createController($controller) { $callable = parent::createController($controller); if ($callable[0] instanceof ContainerAwareInterface) { $callable[0]->setContainer($this->app); } return $callable; }
protected function createController($controller) { if (false !== strpos($controller, '::')) { return parent::createController($controller); } if (false === strpos($controller, ':')) { throw new \LogicException(sprintf('Unable to parse the controller name "%s".', $controller)); } list($service, $method) = explode(':', $controller, 2); if (!isset($this->app[$service])) { throw new \InvalidArgumentException(sprintf('Service "%s" does not exist.', $controller)); } return array($this->app[$service], $method); }
/** * We're overriding this protected method to auto-inject the application container * into our controllers. * * @param string $controller * @return array|mixed */ protected function createController($controller) { if (false !== strpos($controller, '::')) { $instance = parent::createController($controller); // Injects container from side rather than constructor. if ($instance[0] instanceof BaseController) { $instance[0]->setApplication($this->app); } return $instance; } if (false === strpos($controller, ':')) { throw new \LogicException(sprintf('Unable to parse the controller name "%s".', $controller)); } list($service, $method) = explode(':', $controller, 2); if (!isset($this->app[$service])) { throw new \InvalidArgumentException(sprintf('Service "%s" does not exist.', $controller)); } return [$this->app[$service], $method]; }
/** * {@inheritdoc} */ protected function createController($controller) { if (false === strpos($controller, '::')) { $count = substr_count($controller, ':'); if (2 == $count) { if (3 !== count($parts = explode(':', $controller))) { throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid "a:b:c" controller string.', $controller)); } // Controller in the a:b:c notation then list($namespace, $controller, $action) = $parts; $controller = str_replace('/', '\\', $controller); $try = sprintf('%s\\Controller\\%sController', $namespace, $controller); if (class_exists($try)) { $controller = sprintf('%s::%sAction', $try, $action); } } } return parent::createController($controller); }
protected function createController($controller) { if (is_string($controller) && class_exists($controller)) { $methodHandler = strtolower($this->request->getMethod()); $method = null; $whitelistedMethods = array('get', 'post', 'put', 'patch', 'delete', 'copy', 'head', 'options', 'link', 'unlink', 'purge'); if (!in_array($methodHandler, $whitelistedMethods)) { $methodHandler = ''; } if (method_exists($controller, 'handleRequest')) { $method = 'handleRequest'; } elseif (method_exists($controller, $methodHandler)) { $method = $methodHandler; } elseif (method_exists($controller, 'handleMissingMethod')) { $method = 'handleMissingMethod'; } else { throw new \LogicException('No method handler found'); } /** @var \SDispatcher\Common\ResourceOptionInterface $resourceOption */ $resourceOption = $this->app['sdispatcher.resource_option']; $resourceOption->setTarget($controller); $svcIds = $resourceOption->getRequiredServices(); if (empty($svcIds) && (is_subclass_of($controller, 'SDispatcher\\Common\\RequiredServiceMetaProviderInterface') || method_exists($controller, 'getRequiredServices'))) { $svcIds = (array) call_user_func("{$controller}::getRequiredServices"); } if (!empty($svcIds)) { $reflection = new \ReflectionClass($controller); if ($reflection->getConstructor()) { $deps = array(); foreach ($svcIds as $id) { $deps[] = $this->app[$id]; } $c = $reflection->newInstanceArgs($deps); } else { $c = $reflection->newInstanceWithoutConstructor(); } } else { $c = new $controller(); } return array($c, $method); } return parent::createController($controller); }