Ejemplo n.º 1
0
 /**
  * @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));
     }
 }
Ejemplo n.º 2
0
 /**
  * @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());
 }
Ejemplo n.º 3
0
 /**
  * @return UserSourceInterface
  */
 private function userSource()
 {
     if (empty($this->userSource)) {
         //Lazy loading
         $this->userSource = $this->factory->make($this->config->userSource());
     }
     return $this->userSource;
 }
Ejemplo n.º 4
0
 /**
  * @return TokenSourceInterface|AbstractTokenSource
  */
 protected function tokenSource()
 {
     if (empty($this->source)) {
         $this->source = $this->factory->make($this->sourceClass);
     }
     return $this->source;
 }
Ejemplo n.º 5
0
 /**
  * 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];
 }
Ejemplo n.º 6
0
 /**
  * {@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];
 }
Ejemplo n.º 7
0
 /**
  * {@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;
 }
Ejemplo n.º 8
0
 /**
  * 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);
 }
Ejemplo n.º 9
0
 /**
  * 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);
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /**
  * 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'));
 }
Ejemplo n.º 12
0
 /**
  * @param string $name
  * @return ProviderInterface
  */
 public function getProvider($name)
 {
     return $this->factory->make($this->config->providerClass($name), $this->config->providerOptions($name));
 }
Ejemplo n.º 13
0
 /**
  * @param string $name
  * @return TokenOperatorInterface
  */
 public function getOperator($name)
 {
     return $this->factory->make($this->config->operatorClass($name), $this->config->operatorOptions($name));
 }
Ejemplo n.º 14
0
 /**
  * @param SecurityConfig   $config
  * @param FactoryInterface $factory
  * @return ActorInterface
  */
 public function defaultActor(SecurityConfig $config, FactoryInterface $factory)
 {
     return $factory->make($config->defaultActor());
 }
Ejemplo n.º 15
0
 /**
  * @param HttpDispatcher   $dispatcher
  * @param FactoryInterface $factory
  */
 public function boot(HttpDispatcher $dispatcher, FactoryInterface $factory)
 {
     $dispatcher->riseMiddleware($factory->make(ProfilerWrapper::class, ['started' => microtime(true)]));
 }
Ejemplo n.º 16
0
 /**
  * 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)]);
 }
Ejemplo n.º 17
0
 /**
  * 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]);
 }