/** * {@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); }
/** * @param ContainerInterface $container * @param Configurable $config * * @return void */ public function register(ContainerInterface $container, Configurable $config) { if (!$config instanceof Config) { throw new \InvalidArgumentException('Wrong Config object'); } $entityManager = EntityManager::create($config->database, Setup::createAnnotationMetadataConfiguration($config->annotationDirs, $config->dev, $config->proxyDir, $config->cache, false)); $container->add($config->getServiceName(), $entityManager); }
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); }
/** * @param ContainerInterface $container * @param Configurable $config * * @return void */ public function register(ContainerInterface $container, Configurable $config) { if (!$config instanceof Config) { throw new \InvalidArgumentException('Wrong Config object'); } $logger = new Logger($config->name, $config->handlers); $container->add($config->getServiceName(), $logger); }
/** * 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); }
/** * @param ContainerInterface $container * @param Configurable $config * * @return void */ public function register(ContainerInterface $container, Configurable $config) { if (!$config instanceof Config) { throw new \InvalidArgumentException('Wrong Config object'); } $requestFilter = new RequestFilter($config); $container->add($config->getServiceName(), $requestFilter); }
/** * 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]); }
/** * @param ContainerInterface $container * @param Configurable $config * * @return void */ public function register(ContainerInterface $container, Configurable $config) { if (!$config instanceof Config) { throw new \InvalidArgumentException('Wrong Config object'); } $validator = Validation::createValidatorBuilder(); if ($config->annotationMapping) { $validator->enableAnnotationMapping(); } $container->add($config->getServiceName(), $validator->getValidator()); }
/** * @param ContainerInterface $container * @param Configurable $config * * @return void */ public function register(ContainerInterface $container, Configurable $config) { if (!$config instanceof Config) { throw new \InvalidArgumentException('Wrong Config object'); } $hateoas = HateoasBuilder::create(); $hateoas->setDebug($config->debug); $hateoas->setUrlGenerator(null, new CallableUrlGenerator($config->urlGenerator)); if (!$config->debug) { $hateoas->setCacheDir($config->cacheDir); $hateoas->addMetadataDir($config->metadataDir); } $container->add($config->getServiceName(), $hateoas->build()); }
/** * @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() }
/** * @param callable $callable * @param mixed[] $parameters * @return mixed * @throws IoReadException */ public function call(callable $callable, $parameters = []) { try { return $this->container->call($callable, $parameters); } catch (Error $ex) { throw new IoReadException("Calling function with Container failed.", $ex); } catch (Exception $ex) { throw new IoReadException("Calling function with Container failed.", $ex); } }
/** * @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; })); }
/** * Add the Robo League\Container inflectors to the container * * @param \League\Container\ContainerInterface $container */ public static function addInflectors($container) { // Register our various inflectors. $container->inflector(\Robo\Contract\ConfigAwareInterface::class)->invokeMethod('setConfig', ['config']); $container->inflector(\Psr\Log\LoggerAwareInterface::class)->invokeMethod('setLogger', ['logger']); $container->inflector(\League\Container\ContainerAwareInterface::class)->invokeMethod('setContainer', ['container']); $container->inflector(\Symfony\Component\Console\Input\InputAwareInterface::class)->invokeMethod('setInput', ['input']); $container->inflector(\Robo\Contract\OutputAwareInterface::class)->invokeMethod('setOutput', ['output']); $container->inflector(\Robo\Contract\ProgressIndicatorAwareInterface::class)->invokeMethod('setProgressIndicator', ['progressIndicator']); }
/** * 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')); }
public function baseAction(Host $host, Page $page) { // TODO : Widgets ?!? $request = $this->container->get('request_stack')->getCurrentRequest(); }
function it_returns_the_default_renderer(ContainerInterface $container, RendererInterface $renderer) { $container->get('list')->willReturn($renderer); $this->get()->shouldReturn($renderer); }
/** * 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'; }
protected function parseConfig() { $config = Config::load($this->configFile); $this->container->share('config', $config); }
/** * {@inheritdoc} */ public function setContainer(LeagueContainerInterface $container) { // Set our own container as delegate $container->delegate($this->container); $this->container = $container; }
/** * Set a container. * * @param \League\Container\ContainerInterface $container */ public function setContainer(ContainerInterface $container) { $this->container = $container; $this->container->add('app', $this); }
function it_returns_a_menu_instance(ContainerInterface $container, ItemInterface $menu) { $container->get('menu.main', [])->willReturn($menu); $this->get('main')->shouldReturn($menu); }
/** * 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); }
/** * {@inheritdoc} */ public function getService($service) { return $this->container->get($service); }
/** * @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); }