Ejemplo n.º 1
0
 /**
  * Resolves an entry by its name.
  * If given a class name, it will return a new instance of that class.
  *
  * @param string $name Entry name or a class name.
  * @param array $parameters Optional parameters to use to build the entry. Use this to force specific
  *                           parameters to specific values. Parameters not defined in this array will
  *                           be automatically resolved.
  *
  * @throws \Exception       Error while resolving the entry.
  * @return mixed
  */
 public function make($name, array $parameters = [])
 {
     if (!method_exists($this->container, 'make')) {
         throw new Exception('Container method not found');
     }
     return $this->container->make($name, $parameters);
 }
Ejemplo n.º 2
0
 /**
  * Dispatch a route.
  *
  * @param ResolvedRequestInterface $resolvedRequest A resolved request.
  * @return string The response.
  */
 public function dispatch(ResolvedRequestInterface $resolvedRequest)
 {
     $route = $resolvedRequest->getRoute();
     $controller = $this->container->make($route->getController(), ['resolvedRequest' => $resolvedRequest]);
     // Call the before hook, if defined.
     if (method_exists($controller, 'before')) {
         $this->container->call([$controller, 'before'], ['resolvedRequest' => $resolvedRequest]);
     }
     // Call the action.
     $response = $this->container->call([$controller, 'action' . $route->getAction()], ['resolvedRequest' => $resolvedRequest]);
     // Call the after hook, if defined.
     if (method_exists($controller, 'after')) {
         $this->container->call([$controller, 'after'], ['resolvedRequest' => $resolvedRequest]);
     }
     return $response;
 }
 /**
  * Create an object
  *
  * @param  ContainerInterface $container
  * @param  string $requestedName
  * @param  null|array $options
  *
  * @return object
  * @throws ServiceNotFoundException if unable to resolve the service.
  * @throws ServiceNotCreatedException if an exception is raised when
  *     creating a service.
  * @throws ContainerException if any other error occurs
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     if ($container instanceof Container) {
         return $container->make($requestedName, $options ? $options : []);
     } else {
         return $container->get($requestedName);
     }
 }