public function it_resolve_commands(Container $container, $command1, $command2) { $container->keys()->willReturn(['test1.command', 'test2.command']); $container->offsetGet('test1.command')->willReturn($command1); $container->offsetGet('test2.command')->willReturn($command2); $this->commands()->shouldReturn([$command1, $command2]); }
/** * Register the ServiceProvider in the container. * * @return Container */ public function compile() { if (!$this->compiled) { $this->compiled = true; $this->container->register(new ServiceProvider(), $this->config); $this->container->offsetGet('console')->addCommands($this->commands); } return $this->container; }
/** * AbstractController constructor. * @param Container $container */ public function __construct(Container $container) { $this->container = $container; if ($twig = $this->container->offsetGet('twig')) { $this->twig = $twig; } if ($response = $this->container->offsetGet('response')) { $this->response = $response; } if ($request = $this->container->offsetGet('request')) { $this->request = $request; } }
public function register(Container $container) { $cid = $this->cid; $container[$cid] = $container->factory(function () use($cid, $container) { $get = function ($key, $default = null) use($container, $cid) { $key = $cid . '.' . $key; return $container->offsetExists($key) ? $container->offsetGet($key) : $default; }; $adapterName = $get('adapter'); switch ($adapterName) { case 'redis': $adapter = new AdapterPureRedis(['host' => $get('host'), 'port' => $get('port'), 'timeout' => $get('timeout'), 'password' => $get('password'), 'dbIndex' => $get('dbIndex')]); break; case 'file': $adapter = new AdapterFile($get('dir')); break; default: $adapter = new AdapternotCache(); break; } foreach ($get('options', []) as $k => $v) { $adapter->setOption($k, $v); } return new Cache($adapter); }); }
private function activateResponsiveTheme() { /** @var ThemeService $themeService */ $themeService = $this->container->offsetGet('theme.service'); $themeService->activateResponsiveTheme(); return; }
public function offsetGet($id) { $instance = parent::offsetGet($id); if ($instance instanceof ContainerAware) { $instance->setContainer($this); } return $instance; }
public function register(Container $app) { if ($app instanceof Application) { $app->error(function (\Exception $e, Request $request, $code) use($app) { return $app->offsetGet("error.controller")->index($e, $request, $code); }); } }
public function register(Container $pimple) { if ($pimple->offsetExists('facade.aliases')) { $aliases = $pimple->offsetGet('facade.aliases'); } else { $aliases = null; } $facadeServiceLocator = new ArrayAccessAdapter($pimple); FacadeLoader::init($facadeServiceLocator, $aliases); }
public function it_calls_setLogger_and_processes_the_resource(Container $container, Processor $processor, NodeFilter $filter) { $processor->implement(LoggerAwareInterface::class); $container->offsetGet('processor.default')->willReturn($processor); $container->offsetSet('method_filter_pattern', '/^[let|go|it_].*$/')->shouldBeCalled(); $processor->setLogger(Argument::type(LoggerInterface::class))->shouldBeCalled(); $processor->process(__DIR__)->shouldBeCalled(); $stream = fopen('php://memory', 'rw'); $this->run(new ArrayInput(['resource' => __DIR__]), new StreamOutput($stream))->shouldBe(0); }
public function register(Container $container) { $cid = $this->cid; $container[$cid] = $container->factory(function () use($cid, $container) { $get = function ($key, $default = null) use($container, $cid) { $key = $cid . '.' . $key; return $container->offsetExists($key) ? $container->offsetGet($key) : $default; }; $pdo = new Database($get('dsn'), $get('user'), $get('password'), $get('options', [])); return new Db($pdo); }); }
/** * @param string $abstract * @param array $parameters * @return mixed * @throws ContainerException */ public function make($abstract, $parameters = []) { $abstract = $this->getAlias($abstract); $normalAbstract = $this->normalize($abstract); if ($this->container->offsetExists($normalAbstract)) { return $this->container->offsetGet($normalAbstract); } if (!class_exists($abstract)) { throw new ContainerException("Class {$abstract} does not exist"); } $reflector = new \ReflectionClass($abstract); if (!$reflector->isInstantiable()) { throw new ContainerException("Can't instantiate this"); } $constructor = $reflector->getConstructor(); if (is_null($constructor)) { return new $abstract(); } $parameters = $constructor->getParameters(); $dependencies = $this->getDependencies($parameters); $builder = $reflector->newInstanceArgs($dependencies); $this->instance($normalAbstract, $builder); return $this->container->offsetGet($normalAbstract); }
/** * @param MockListener $listener * @param Event $event * @param Container $container * @param MockServiceSubscriber $sub * * @throws \DomainException * @throws \InvalidArgumentException * @throws \LengthException * @throws \LogicException */ public function it_should_still_allow_service_subscriber_to_be_removed_after_event_has_been_triggered(MockListener $listener, Event $event, Container $container, MockServiceSubscriber $sub) { $events = ['test1' => [[['containerID1', 'method1']]]]; $event->hasBeenHandled()->willReturn(false); $sub->getServiceSubscribedEvents()->willReturn($events); $this->addServiceSubscriber($sub); $this->getServiceListeners()->shouldHaveKey('test1'); $container->offsetGet('containerID1')->willReturn($listener); $this->setServiceContainer($container); $listener->method1($event, 'test1', $this)->shouldBeCalled(); $this->getServiceByName('containerID1')->shouldReturn($listener); $this->trigger('test1', $event); $this->removeServiceSubscriber($sub); $this->getServiceListeners()->shouldNotHaveKey('test1'); }
use Shopware\Recovery\Install\Service\ConfigWriter; use Shopware\Recovery\Install\Service\DatabaseService; use Shopware\Recovery\Install\Service\LicenseInstaller; use Shopware\Recovery\Install\Service\LocaleSettingsService; use Shopware\Recovery\Install\Service\LocalLicenseUnpackService; use Shopware\Recovery\Install\Service\ShopService; use Shopware\Recovery\Install\Service\CurrencyService; use Shopware\Recovery\Install\Service\ThemeService; use Shopware\Recovery\Install\Service\TranslationService; use Shopware\Recovery\Install\Struct\DatabaseConnectionInformation; use Shopware\Recovery\Install\Struct\LicenseUnpackRequest; $config = (require __DIR__ . '/../config/production.php'); $container = new Container(); $container->register(new ContainerProvider($config)); /** @var \Slim\Slim $app */ $app = $container->offsetGet('slim.app'); // After instantiation $sessionPath = str_replace('index.php', '', $app->request()->getScriptName()); $app->config('cookies.path', $sessionPath); if (!isset($_SESSION)) { session_cache_limiter(false); session_set_cookie_params(600, $sessionPath); session_start(); } if (!isset($_SESSION["parameters"])) { $_SESSION["parameters"] = []; } if (isset($_SESSION["databaseConnectionInfo"])) { $connectionInfo = $_SESSION["databaseConnectionInfo"]; try { $databaseFactory = new DatabaseFactory();
/** * Sets a parameter. * * @param string $name The parameter name * @param mixed $value The parameter value * * @api */ public function setParameter($name, $value) { $config = $this->pimple->offsetGet('config'); $config[$name] = $value; $this->pimple->offsetSet('config', $config); }
protected function view($name, Config $config) { if (!($config = $config->get("views.{$name}"))) { throw new \LogicException("No configuration for view '{$name}'"); } $view = parent::offsetGet('view')->create($config); parent::offsetExists('profiler') && $view->setProfiler(parent::offsetGet('profiler')); return $view; }
public function offsetGet($id) { return $this->pimpleContainer->offsetGet($this->ensureNamespacesLoaded($id)); }
/** * {@inheritdoc} */ public function offsetGet($id) { $id = strtolower(trim($id)); $cms = $this; if (!isset($this[$id])) { $className = $cms['ns'] . ucfirst($id); if (class_exists($className)) { $this[$id] = function ($cms) use($className, $cms) { return new $className($cms); }; } } return parent::offsetGet($id); }