/** * @return UserSourceInterface */ private function userSource() { if (empty($this->userSource)) { //Lazy loading $this->userSource = $this->factory->make($this->config->userSource()); } return $this->userSource; }
/** * @return TokenSourceInterface|AbstractTokenSource */ protected function tokenSource() { if (empty($this->source)) { $this->source = $this->factory->make($this->sourceClass); } return $this->source; }
/** * @param SecurityConfig $config * @param FactoryInterface $factory */ public function __construct(SecurityConfig $config, FactoryInterface $factory) { $this->config = $config; foreach ($this->config->getLibraries() as $library) { $this->register($factory->make($library)); } }
/** * @param AuthConfig $config * @param FactoryInterface $factory * @return UserSourceInterface */ public function userSource(AuthConfig $config, FactoryInterface $factory) { if (empty($config->userSource())) { throw new AuthException("User source is not set"); } return $factory->make($config->userSource()); }
/** * Get driver by it's name. Every driver associated with configured connection, there is minor * de-sync in naming due legacy code. * * @param string $connection * @return Driver * @throws DatabaseException */ public function driver($connection) { if (isset($this->drivers[$connection])) { return $this->drivers[$connection]; } if (!$this->config->hasConnection($connection)) { throw new DatabaseException("Unable to create Driver, no presets for '{$connection}' found."); } $this->drivers[$connection] = $this->factory->make($this->config->connectionDriver($connection), ['name' => $connection, 'config' => $this->config->connectionConfig($connection)]); return $this->drivers[$connection]; }
/** * {@inheritdoc} */ public function store($store = null) { //Default store class $store = !empty($store) ? $store : $this->config->defaultStore(); $store = $this->config->resolveAlias($store); if (isset($this->stores[$store])) { return $this->stores[$store]; } $benchmark = $this->benchmark('store', $store); try { //Constructing cache instance $this->stores[$store] = $this->factory->make($this->config->storeClass($store), $this->config->storeOptions($store)); } finally { $this->benchmark($benchmark); } if ($store == $this->config['store'] && !$this->stores[$store]->isAvailable()) { throw new CacheException("Unable to use default store '{$store}', driver is unavailable."); } return $this->stores[$store]; }
/** * {@inheritdoc} */ public function getMigrations() { $migrations = []; foreach ($this->getFiles() as $definition) { if (!class_exists($definition['class'], false)) { require_once $definition['filename']; } if (!$definition['created'] instanceof \DateTime) { throw new RepositoryException("Invalid migration filename '{$definition['filename']}'"); } /** * @var MigrationInterface $migration */ $migration = $this->factory->make($definition['class']); //Repository related meta information $migration->setMeta(new Meta($definition['name'], $definition['created'])); $migrations[$definition['filename']] = $migration; } return $migrations; }
/** * Configuring session handler. * * @param \SessionHandler $handler */ protected function initHandler(\SessionHandler $handler = null) { if (!empty($handler)) { session_set_save_handler($handler, true); return; } if ($this->config->sessionHandler() == SessionConfig::NATIVE_HANDLER) { //Nothing to do return; } $benchmark = $this->benchmark('handler', $this->config->sessionHandler()); $handler = $this->factory->make($this->config->handlerClass(), $this->config->handlerParameters()); $this->benchmark($benchmark); session_set_save_handler($handler, true); }
/** * Create bucket based configuration settings. * * @param string $name * @param array $bucket * @return BucketInterface */ private function createBucket($name, array $bucket) { $parameters = $bucket + compact('name'); if (!array_key_exists('options', $bucket)) { throw new StorageException("Bucket configuration must include options."); } if (!array_key_exists('prefix', $bucket)) { throw new StorageException("Bucket configuration must include prefix."); } if (!array_key_exists('server', $bucket)) { throw new StorageException("Bucket configuration must include server id."); } $parameters['server'] = $this->server($bucket['server']); $parameters['storage'] = $this; return $this->factory->make(StorageBucket::class, $parameters); }
/** * Get handlers associated with specified log. * * @param string $name * @return HandlerInterface[] */ public function logHandlers($name) { $handlers = []; if (!empty($this->sharedHandler)) { //Shared handler applied to every Logger $handlers[] = $this->sharedHandler; } if (!$this->config->hasHandlers($name)) { return $handlers; } foreach ($this->config->logHandlers($name) as $handler) { /** * @var HandlerInterface $instance */ $handlers[] = $instance = $this->factory->make($handler['handler'], $handler['options']); if (!empty($handler['format'])) { //Let's use custom line formatter $instance->setFormatter(new LineFormatter($handler['format'])); } } return $handlers; }
/** * 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 (!$this->config->hasRelation($type, 'schema')) { throw new ORMException("Undefined relation schema '{$type}'."); } //Getting needed relation schema builder return $this->factory->make($this->config->relationClass($type, 'schema'), compact('builder', 'record', 'name', 'definition')); }
/** * @param string $name * @return ProviderInterface */ public function getProvider($name) { return $this->factory->make($this->config->providerClass($name), $this->config->providerOptions($name)); }
/** * @param string $name * @return TokenOperatorInterface */ public function getOperator($name) { return $this->factory->make($this->config->operatorClass($name), $this->config->operatorOptions($name)); }
/** * @param SecurityConfig $config * @param FactoryInterface $factory * @return ActorInterface */ public function defaultActor(SecurityConfig $config, FactoryInterface $factory) { return $factory->make($config->defaultActor()); }
/** * @param HttpDispatcher $dispatcher * @param FactoryInterface $factory */ public function boot(HttpDispatcher $dispatcher, FactoryInterface $factory) { $dispatcher->riseMiddleware($factory->make(ProfilerWrapper::class, ['started' => microtime(true)])); }
/** * Get instance of Driver specific QueryCompiler. * * @param string $prefix Database specific table prefix, used to quote table names and build * aliases. * @return QueryCompiler */ public function queryCompiler($prefix = '') { return $this->factory->make(static::QUERY_COMPILER, ['driver' => $this, 'quoter' => new Quoter($this, $prefix)]); }
/** * Get instance of ODM SchemaBuilder. * * @param ClassLocatorInterface $locator * @return SchemaBuilder */ public function schemaBuilder(ClassLocatorInterface $locator = null) { return $this->factory->make(SchemaBuilder::class, ['odm' => $this, 'config' => $this->config['schemas'], 'locator' => $locator]); }