/**
  * {@inheritdoc}
  */
 public function get($name, array $options = [])
 {
     if (!isset($this->menuIds[$name])) {
         throw new \InvalidArgumentException(sprintf('The menu "%s" is not defined', $name));
     }
     return $this->container->get($this->menuIds[$name], $options);
 }
예제 #2
0
파일: Dispatcher.php 프로젝트: jirro/jirro
 public function __construct(ContainerInterface $container, array $routes, array $data)
 {
     $this->container = $container;
     $this->request = $container->get('service.http.request');
     $this->routes = $routes;
     $this->auth = $container->get('service.account.auth');
     parent::__construct($data);
 }
예제 #3
0
 /**
  * Retrieves a middleware from the container
  * 
  * @param string $middleware
  * @return mixed
  */
 public function resolve($middleware)
 {
     //Not a string, should be an object
     if (!is_string($middleware)) {
         return $middleware;
     }
     return $this->container->get($middleware);
 }
예제 #4
0
 /**
  * Dispatch the controller, the return value of this method will bubble out and be
  * returned by \League\Route\Dispatcher::dispatch, it does not require a response, however,
  * beware that there is no output buffering by default in the router.
  *
  * $controller can be one of three types but based on the type you can infer what the
  * controller actually is:
  *     - string   (controller is a named function)
  *     - array    (controller is a class method [0 => ClassName, 1 => MethodName])
  *     - \Closure (controller is an anonymous function)
  *
  * @param  string|array|\Closure $controller
  * @param  array $vars - named wildcard segments of the matched route
  *
  * @return mixed
  */
 public function dispatch($controller, array $vars)
 {
     $request = $this->container->get('Symfony\\Component\\HttpFoundation\\Request');
     $response = $this->invokeController($controller, array_merge([$request], array_values($vars)));
     if ($response instanceof Response && $response->getContent() !== '') {
         return $this->serialize($response->getContent(), $request, $response);
     }
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public function get($name = null)
 {
     if (is_null($name)) {
         $name = $this->defaultRenderer;
     }
     if (!isset($this->rendererIds[$name])) {
         throw new \InvalidArgumentException(sprintf('The renderer "%s" is not defined', $name));
     }
     return $this->container->get($this->rendererIds[$name]);
 }
예제 #6
0
파일: Kernel.php 프로젝트: hopus/common
 /**
  * Builds the container
  */
 protected function buildContainer()
 {
     $this->container->add('kernel', $this);
     $this->container->add('base_dir', $this->baseDir);
     /**
      * Templating
      */
     $loader = new \Twig_Loader_Filesystem($this->baseDir . '/' . $this->container->get('config')->get('hopus.templates.dir'));
     $twig = new \Twig_Environment($loader, ['cache' => $this->withCache ? $this->baseDir . '/' . $this->container->get('config')->get('hopus.cache.dir') . '/templating' : false]);
     $twig->addExtension(new ContentExtension($this->baseDir . '/' . $this->container->get('config')->get('hopus.contents.dir')));
     $this->container->share('templating', $twig);
     /**
      * Http
      */
     $this->container->share('request_stack', new RequestStack());
     $this->container->get('request_stack')->push(Request::createFromGlobals());
     /**
      * Events
      */
     $this->container->share('event_emitter', new Emitter());
     /**
      * Puli
      */
     $factoryClass = PULI_FACTORY_CLASS;
     $factory = new $factoryClass();
     $repo = $factory->createRepository();
     $discovery = $factory->createDiscovery($repo);
     //$discovery->addBindingType(new BindingType(PluginManager::PLUGIN_BINDING_TYPE));
     //$discovery->addBindingType(new BindingType(Application::COMMAND_BINDING_TYPE));
     $this->container->share('puli_discovery', $discovery);
 }
예제 #7
0
파일: Container.php 프로젝트: khelle/surume
 /**
  * @param string $alias
  * @param mixed[] $parameters
  * @return mixed
  * @throws IoReadException
  */
 public function make($alias, $parameters = [])
 {
     try {
         $object = $this->container->get($alias, $parameters);
         if ($object instanceof FactoryMethod === true) {
             $parameters = count($parameters) === 0 ? $object->getArgs() : $parameters;
             return $this->container->call($object->getCallback(), $parameters);
         }
         return $object;
     } catch (Error $ex) {
         throw new IoReadException("Resolving object of [{$alias}] from Container failed.", $ex);
     } catch (Exception $ex) {
         throw new IoReadException("Resolving object of [{$alias}] from Container failed.", $ex);
     }
 }
예제 #8
0
파일: BaseCommand.php 프로젝트: baleen/cli
 /**
  * @param ContainerInterface $container A reference to the Application's Container.
  *
  * @param string $serviceAlias The key in the Container for the command that the instance of this class represents.
  *
  * @param string $serviceClass Needed in order to run certain checks against the class before instantiating it
  *                             with the container. This helps us make those checks without triggering all the other
  *                             services through the Container's DI functionality.
  *
  * @throws InvalidArgumentException
  */
 public function __construct(ContainerInterface $container, $serviceAlias, $serviceClass)
 {
     $serviceClass = (string) $serviceClass;
     if (!class_exists($serviceClass) || !new $serviceClass() instanceof MessageInterface) {
         throw new InvalidArgumentException(sprintf('Message class "%s" must exist and be an instance of %s', $serviceClass, MessageInterface::class));
     }
     $this->serviceClass = $serviceClass;
     $serviceAlias = (string) $serviceAlias;
     $this->serviceAlias = $serviceAlias;
     $commandBus = $container->get(Services::COMMAND_BUS);
     if (!$commandBus instanceof CommandBus) {
         throw new InvalidArgumentException(sprintf('Invalid service: expected an instance of "%s".', CommandBus::class));
     }
     $this->commandBus = $commandBus;
     $this->container = $container;
     parent::__construct(null);
     // name will be set inside configure()
 }
예제 #9
0
 /**
  * @param Match $match
  *
  * @return ResponseInterface
  */
 protected function getControllerResult(Match $match) : ResponseInterface
 {
     if ($match->controller === null) {
         $response = $this->dependencyContainer->get('fuel.application.response');
         return $response->withStatus(404);
     }
     $controller = $this->createController($match);
     $controllerResult = $controller->{$match->action}();
     // generate and send response
     // If the controller response is a response object then just pass that back out
     if ($controllerResult instanceof ResponseInterface) {
         return $controllerResult;
     }
     // Else update the application response with the controller result#
     /** @var ResponseInterface $response */
     $response = $this->dependencyContainer->get('fuel.application.response');
     $response->withStatus(200);
     return $response->withBody(new CallbackStream(function () use($controllerResult) {
         return $controllerResult;
     }));
 }
예제 #10
0
 public function baseAction(Host $host, Page $page)
 {
     // TODO : Widgets ?!?
     $request = $this->container->get('request_stack')->getCurrentRequest();
 }
예제 #11
0
 /**
  * @param \League\Container\ContainerInterface $app
  */
 protected function registerEngine(ContainerInterface $app)
 {
     $app->add('Plates.Engine', new Engine(null, $app->config('plates.extension')));
     $themeDir = vsprintf('%s/%s', [$app->config('plates.templatesDir'), $app->config('app.theme')]);
     $app->get('Plates.Engine')->addFolder('theme', $themeDir);
 }
 function it_returns_the_default_renderer(ContainerInterface $container, RendererInterface $renderer)
 {
     $container->get('list')->willReturn($renderer);
     $this->get()->shouldReturn($renderer);
 }
예제 #13
0
 /**
  * Register the necessary classes for Terminus
  *
  * @param \League\Container\ContainerInterface $container
  */
 private function configureContainer(ContainerInterface $container)
 {
     // Add the services.
     $container->share('request', Request::class);
     $container->inflector(RequestAwareInterface::class)->invokeMethod('setRequest', ['request']);
     $session_store = new FileStore($this->config->get('cache_dir'));
     $session = new Session($session_store);
     $container->share('session', $session);
     $container->inflector(SessionAwareInterface::class)->invokeMethod('setSession', ['session']);
     $token_store = new FileStore($this->config->get('tokens_dir'));
     $container->inflector(SavedTokens::class)->invokeMethod('setDataStore', [$token_store]);
     // Add the models and collections
     $container->add(User::class);
     $container->add(SavedTokens::class);
     $container->add(SavedToken::class);
     $container->add(PaymentMethods::class);
     $container->add(PaymentMethod::class);
     $container->add(SSHKeys::class);
     $container->add(SSHKey::class);
     $container->add(Workflows::class);
     $container->add(Workflow::class);
     $container->add(WorkflowOperation::class);
     $container->add(MachineTokens::class);
     $container->add(MachineToken::class);
     $container->add(Upstream::class);
     $container->add(Upstreams::class);
     $container->add(UserSiteMemberships::class);
     $container->add(UserSiteMembership::class);
     $container->add(UserOrganizationMemberships::class);
     $container->add(UserOrganizationMembership::class);
     $container->add(OrganizationSiteMemberships::class);
     $container->add(OrganizationSiteMembership::class);
     $container->add(OrganizationUserMemberships::class);
     $container->add(OrganizationUserMembership::class);
     $container->add(Organization::class);
     $container->add(Branches::class);
     $container->add(Branch::class);
     $container->add(SiteUserMemberships::class);
     $container->add(SiteUserMembership::class);
     $container->add(SiteOrganizationMemberships::class);
     $container->add(SiteOrganizationMembership::class);
     $container->add(Site::class);
     $container->add(Redis::class);
     $container->add(Solr::class);
     $container->add(Environments::class);
     $container->add(Environment::class);
     $container->add(Backups::class);
     $container->add(Backup::class);
     $container->add(Lock::class);
     $container->add(Bindings::class);
     $container->add(Binding::class);
     $container->add(Domains::class);
     $container->add(Domain::class);
     $container->add(Commits::class);
     $container->add(Commit::class);
     $container->add(NewRelic::class);
     $container->add(Tags::class);
     $container->add(Tag::class);
     $container->share('sites', Sites::class);
     $container->inflector(SiteAwareInterface::class)->invokeMethod('setSites', ['sites']);
     // Add the commands.
     $factory = $container->get('commandFactory');
     $factory->setIncludeAllPublicMethods(false);
     $commands_directory = __DIR__ . '/Commands';
     $top_namespace = 'Pantheon\\Terminus\\Commands';
     $this->commands = $this->getCommands(['path' => $commands_directory, 'namespace' => $top_namespace]);
     $this->commands[] = 'Pantheon\\Terminus\\Authorizer';
 }
예제 #14
0
 /**
  * Run the application.
  *
  * It will boot the DI-Container and create the Kernel if both are not already there.
  * It will then call all registered ConfigurationInterfaces.
  * Finally the Request gets hand down into the Kernel::handle to get the Application up and running.
  *
  * @return KernelInterface
  */
 public function run() : KernelInterface
 {
     return $this->boot()->getKernel()->handle($this->container->get('request'));
 }
 function it_returns_a_menu_instance(ContainerInterface $container, ItemInterface $menu)
 {
     $container->get('menu.main', [])->willReturn($menu);
     $this->get('main')->shouldReturn($menu);
 }
예제 #16
0
 /**
  * {@inheritdoc}
  */
 public function getService($service)
 {
     return $this->container->get($service);
 }
예제 #17
0
파일: Client.php 프로젝트: larabros/elogram
 /**
  * Enables or disables secure requests by adding or removing
  * `SecureRequestMiddleware`.
  *
  * @param bool $enable
  *
  * @return  void
  *
  * @codeCoverageIgnore
  */
 public function secureRequests($enable = true)
 {
     $this->container->get('config')->set('secure_requests', $enable);
 }