public function configure(Container $pimple, $resource) { $parameters = $this->loader->load($resource); foreach ($parameters as $k => $v) { $pimple->offsetSet($k, $v); } }
public function it_exposes_all_needed_services(Container $container) { $services = ['method_filter_pattern' => 'string', 'console.application' => 'callable', 'console.command.transform' => 'callable', 'processor.default' => 'callable', 'docblock.factory' => 'callable', 'node.filter' => 'callable', 'node.spec_visitor' => 'callable', 'node.walker' => 'callable', 'loader.finder' => 'callable', 'writer.default' => 'callable', 'writer.filesystem' => 'callable', 'writer.memory' => 'callable', 'parser.lexer' => 'callable', 'parser.parser' => 'callable', 'parser.traverser' => 'callable', 'parser.printer' => 'callable']; foreach ($services as $id => $type) { $container->offsetSet($id, Argument::type($type))->shouldBeCalled(); } $this->register($container); }
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); }
/** * Gets a parameter or an object. * log.<name>, db.<name> and cache.<name> are acceptable shortcuts for creating services based on configuration entries. * @param string $id The unique identifier for the parameter or object * @return mixed The value of the parameter or an object * @throws InvalidArgumentException if the identifier is not defined */ public function offsetGet($id) { // key doesn't exist but it might be a shortcut if (!parent::offsetExists($id) && ($shortcut = $this->matchShortcut($id))) { list($type, $name) = $shortcut; if ($config = $this->getConfig()) { parent::offsetSet($id, $this->{$type}($name, $config)); } } return parent::offsetGet($id); }
/** * @param string $serviceName * @param mixed $callable */ public function registerService($serviceName, $callable = null) { if (is_string($callable)) { error_log('attempting to register ' . $serviceName); /* TODO Rethink how this works in order to figure out parameters to pass to new registered service */ $this->container[$serviceName] = function ($c) use($callable) { $r = new \ReflectionClass($callable); return $r->newInstanceArgs([$c]); }; } elseif (is_callable($callable)) { $this->container->offsetSet($serviceName, $callable); } }
public function offsetSet($id, $value) { if (!is_object($value) || !method_exists($value, '__invoke')) { throw new \InvalidArgumentException(sprintf('Identifier "%s" does not contain an object definition.', $id)); } $value = function ($c) use($value, $id) { if (is_callable($value)) { $result = $value($c); if (is_object($result)) { if ($result instanceof IncludeOperatorInterface) { $result->setOperator($this->getOperator()); } if ($result instanceof ConfigurableInterface) { $result->addConfig($this->getOperator()->getWorkerParams($id)); } } return $result; } else { return $value; } }; parent::offsetSet($id, $value); }
public function offsetSet($id, $value) { $this->pimpleContainer->offsetSet($id, $value); }
public function it_register_service_command_resolver(Container $container) { $container->offsetSet('command.resolver', Argument::Any())->shouldBeCalled(); $this->register($container); }
public function instance($abstract, $instance) { $this->container->offsetSet($abstract, $instance); }
/** * {@inheritDoc} */ public function offsetSet($id, $value) { parent::offsetSet($id, $value); $this->recordPrefix($id); }
/** * @param Container $container * @return mixed */ protected function processEnvironment(Container $container) { $containerKeys = $container->keys(); // Note: This will only set parameters IF they already exist in some form in the configuration foreach ($_SERVER as $key => $value) { if (0 === stripos($key, self::ENVIRONMENT_PREFIX)) { $key = substr($key, strlen(self::ENVIRONMENT_PREFIX)); $key = str_replace("__", ".", $key); $key = strtolower($key); // Look to see if the environment variable exists purely as lowercase if (!$container->offsetExists($key)) { // If it doesn't, then lowercase the container keys and see if we can find it there if (($offsetKey = array_search(strtolower($key), array_map('strtolower', $containerKeys))) === false) { // If we can't, then we shouldn't be setting this variable continue; } // Otherwise, use the correct key $key = $containerKeys[$offsetKey]; } $container->offsetSet($key, $value); } } }
$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(); $connection = $databaseFactory->createPDOConnection($connectionInfo); // init db in container $container->offsetSet('db', $connection); } catch (\Exception $e) { // jump to form throw $e; } } /** * @return array|string */ function selectLanguage() { /** * Load language file */ $allowedLanguages = ["de", "en", "nl"]; $selectedLanguage = "de";
public function it_registers_oauth2_security_services(Container $container) { $callable = Argument::type('callable'); $container->protect($callable)->willReturnArgument(); $factoryIdentifier = 'security.authentication_listener.factory.oauth2'; $viewPath = realpath(__DIR__ . '/../../src/Pimple') . '/../../views/authorize.php'; $container->offsetSet($factoryIdentifier, $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.default', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.types', ['client', 'access_token'])->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.access_token', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.authorization_code', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.client_credentials', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.client', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.refresh_token', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.user_credentials', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.user_claims', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.public_key', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.jwt_bearer', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.storage.scope', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.config', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.grant_types', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.response_types', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.token_type', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.scope_util', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.client_assertion_type', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.parameters', [])->shouldBeCalled(); $container->offsetSet('oauth2_server', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.authorize_renderer', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.authorize_renderer.view', $viewPath)->shouldBeCalled(); $container->offsetSet('oauth2_server.controllers_as_service', false)->shouldBeCalled(); $container->offsetSet('oauth2_server.controllers.authorize', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.controllers.authorize_validator', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.controllers.authorize_handler', $callable)->shouldBeCalled(); $container->offsetSet('oauth2_server.controllers.token', $callable)->shouldBeCalled(); $this->register($container); }
/** * @param DatabaseConnectionInformation $connectionInfo * @param Container $container * @return \PDO */ protected function initDatabaseConnection(DatabaseConnectionInformation $connectionInfo, Container $container) { $databaseFactory = new DatabaseFactory(); $conn = $databaseFactory->createPDOConnection($connectionInfo); $container->offsetSet('db', $conn); return $conn; }
/** * 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); }