/** * Configure logger handlers. * * @param Logger $logger */ public function configureLogger(Logger $logger) { if (!isset($this->config['loggers'][$logger->getName()])) { //Nothing to configure return; } foreach ($this->config['loggers'][$logger->getName()] as $logLevel => $handler) { $logger->setHandler($logLevel, $this->container->construct($handler['class'], ['options' => $handler])); } }
/** * {@inheritdoc} * * @param \SessionHandler $handler Custom session handler. */ public function start(\SessionHandler $handler = null) { if ($this->started) { return true; } //We don't need cookies ini_set('session.use_cookies', false); !empty($this->id) && session_id($this->id); if (empty($handler)) { $defaultHandler = $this->config['handler']; if ($defaultHandler != self::NATIVE_HANDLER) { $config = $this->config['handlers'][$this->config['handler']]; $benchmark = $this->benchmark('handler', $this->config['handler']); $handler = $this->handler = $this->container->construct($config['class'], ['options' => $config, 'lifetime' => $this->config['lifetime']]); $this->benchmark($benchmark); } } !empty($handler) && session_set_save_handler($handler, true); try { $benchmark = $this->benchmark('start'); session_start(); $this->benchmark($benchmark); $this->id = session_id(); $this->started = true; $this->destroyed = false; } catch (\ErrorException $exception) { throw new SessionException($exception->getMessage(), $exception->getCode()); } return true; }
/** * {@inheritdoc} * * @throws CacheException */ public function createInjection(\ReflectionClass $class, $context) { if (!$class->isInstantiable()) { return $this->store(); } $store = $this->container->construct($class->getName(), ['cache' => $this]); if (!$store->isAvailable()) { throw new CacheException("Unable to use store '" . get_class($store) . "', driver is unavailable."); } return $store; }
/** * Get next chain to be called. Exceptions will be converted to responses. * * @param int $position * @param ServerRequestInterface $request * @param ResponseInterface $response * @return null|ResponseInterface * @throws \Exception */ protected function next($position, ServerRequestInterface $request, ResponseInterface $response) { if (!isset($this->middlewares[$position])) { //Middleware target endpoint to be called and converted into response return $this->createResponse($request, $response); } /** * @var callable $middleware */ $middleware = $this->middlewares[$position]; $middleware = is_string($middleware) ? $this->container->construct($middleware) : $middleware; //Executing next middleware return $middleware($request, $response, $this->getNext($position, $request, $response)); }
/** * Get driver by it's name. * * @param string $name * @param array $config Custom driver options and class. * @return Driver * @throws DatabaseException */ public function driver($name, array $config = []) { if (isset($this->drivers[$name])) { return $this->drivers[$name]; } if (empty($config)) { if (!isset($this->config['connections'][$name])) { throw new DatabaseException("Unable to create Driver, no presets for '{$name}' found."); } $config = $this->config['connections'][$name]; } $this->drivers[$name] = $this->container->construct($config['driver'], compact('name', 'config')); return $this->drivers[$name]; }
/** * {@inheritdoc} */ public function server($server, array $options = []) { if (isset($this->servers[$server])) { return $this->servers[$server]; } if (!empty($options)) { $this->config['servers'][$server] = $options; } if (!array_key_exists($server, $this->config['servers'])) { throw new StorageException("Undefined storage server '{$server}'."); } $config = $this->config['servers'][$server]; return $this->servers[$server] = $this->container->construct($config['class'], $config); }
/** * {@inheritdoc} * * @return MigrationInterface[] */ public function getMigrations() { $migrations = []; foreach ($this->getFiles() as $filename => $definition) { if (!class_exists($definition['class'], false)) { //Can happen sometimes require_once $filename; } elseif (isset($migrations[$filename])) { $this->logger()->warning("Migration '{class}' already presented in loaded classes.", $definition); continue; } /** * @var MigrationInterface $migration */ $migration = $this->container->construct($definition['class']); //Status $migration->setState($this->getStatus($definition)); $migrations[$filename] = $migration; } return $migrations; }
/** * Create instance of relation schema based on relation type and given definition (declared in * record). Resolve using container to support any possible relation type. You can create your * own relations, loaders and schemas by altering ORM config. * * @param mixed $type * @param SchemaBuilder $builder * @param RecordSchema $record * @param string $name * @param array $definition * @return Schemas\RelationInterface */ public function relationSchema($type, SchemaBuilder $builder, RecordSchema $record, $name, array $definition) { if (!isset($this->config['relations'][$type]['schema'])) { throw new ORMException("Undefined relation schema '{$type}'."); } return $this->container->construct($this->config['relations'][$type]['schema'], compact('builder', 'record', 'name', 'definition')); }
/** * Get instance of ODM SchemaBuilder. * * @param TokenizerInterface $tokenizer * @return SchemaBuilder */ public function schemaBuilder(TokenizerInterface $tokenizer = null) { return $this->container->construct(SchemaBuilder::class, ['odm' => $this, 'config' => $this->config['schemas'], 'tokenizer' => $tokenizer]); }
/** * Get instance of Driver specific QueryCompiler. * * @param string $tablePrefix Database specific table prefix, used to quote table names and * build aliases. * @return QueryCompiler */ public function queryCompiler($tablePrefix = '') { return $this->container->construct(static::QUERY_COMPILER, ['driver' => $this, 'tablePrefix' => $tablePrefix]); }