public function register(Container $container)
 {
     $container->singleton(Container::class, function () use($container) {
         return $container;
     });
     $container->singleton(ContainerInterface::class, LaravelContainer::class);
 }
 /**
  * @param Container $container
  */
 protected function registerContainerBindings(Container $container)
 {
     $container->singleton(FileFactoryContract::class, function () {
         return new FileFactory(File::class);
     });
     $container->singleton(FileStorageContract::class, function () {
         return new FileStorage();
     });
 }
Exemple #3
0
 /**
  * @param $connection
  */
 public function addConnection($connection)
 {
     if (!$this->container->bound($this->getConnectionBindingName($connection))) {
         $this->container->singleton($this->getConnectionBindingName($connection), function () use($connection) {
             return $this->getManager($connection)->getConnection();
         });
         $this->connections[$connection] = $connection;
     }
 }
 /**
  * @param Container $container
  */
 protected function registerContainerBindings(Container $container)
 {
     $container->singleton(FileFactoryContract::class, function () {
         return new FileFactory(File::class);
     });
     $documentManager = $container->make(DocumentManager::class);
     $container->singleton(FileStorageContract::class, function () use($documentManager) {
         return new FileStorage($documentManager);
     });
 }
Exemple #5
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     try {
         if ($this->validator->validateRequest($request)) {
             $this->app->singleton('Illuminate\\Contracts\\Debug\\ExceptionHandler', function ($app) {
                 return $app['Dingo\\Api\\Contract\\Debug\\ExceptionHandler'];
             });
             $request = $this->app->make('Dingo\\Api\\Contract\\Http\\Request')->createFromIlluminate($request);
             return $this->sendRequestThroughRouter($request);
         }
     } catch (Exception $exception) {
         return $this->exception->handle($exception);
     }
     return $next($request);
 }
 /**
  * Registers container bindings.
  *
  * @param Container        $container
  * @param ConfigRepository $config
  *
  * @return DocumentManager
  */
 protected function registerContainerBindings(Container $container, ConfigRepository $config)
 {
     $container->singleton('Doctrine\\ODM\\MongoDB\\DocumentManager', function () use($config) {
         Config::mergeWith($config);
         return $this->createDocumentManager($config);
     });
 }
 /**
  * Registers container bindings.
  *
  * @param Container        $container
  * @param ConfigRepository $config
  */
 protected function registerContainerBindings(Container $container, ConfigRepository $config)
 {
     $container->singleton('Doctrine\\ORM\\EntityManager', function () use($config) {
         return $this->createEntityManager($config);
     });
     $container->alias('Doctrine\\ORM\\EntityManager', 'Doctrine\\ORM\\EntityManagerInterface');
 }
 /**
  * Registers the container bindings.
  *
  * @param Container $container
  */
 protected function registerContainerBindings(Container $container)
 {
     $container->singleton('Nord\\Lumen\\Mandrill\\Mailer\\Contracts\\MandrillMailer', function () {
         $config = config('mandrillmailer', []);
         return new MandrillMailer($config);
     });
 }
 /**
  * @param Container        $container
  * @param ConfigRepository $config
  */
 protected function registerContainerBindings(Container $container, ConfigRepository $config)
 {
     $container->alias(ImageManager::class, ImageManagerContract::class);
     $container->singleton(ImageManagerContract::class, function () use($container, $config) {
         return $this->createManager($container, $config);
     });
 }
 /**
  * @param Container        $container
  * @param ConfigRepository $config
  */
 protected function registerBindings(Container $container, ConfigRepository $config)
 {
     $container->singleton(SparkPostService::class, function () use($config) {
         return new SparkPostService($config[self::CONFIG_KEY]);
     });
     $container->alias(SparkPostService::class, SparkPostServiceContract::class);
 }
 /**
  * Register the Authorization server with the IoC container.
  *
  * @param \Illuminate\Contracts\Container\Container $app
  *
  * @return void
  */
 public function registerAuthorizer(Application $app)
 {
     $app->singleton('oauth2-server.authorizer', function ($app) {
         $config = $app['config']->get('oauth2');
         $issuer = $app->make(AuthorizationServer::class)->setClientStorage($app->make(ClientInterface::class))->setSessionStorage($app->make(SessionInterface::class))->setAuthCodeStorage($app->make(AuthCodeInterface::class))->setAccessTokenStorage($app->make(AccessTokenInterface::class))->setRefreshTokenStorage($app->make(RefreshTokenInterface::class))->setScopeStorage($app->make(ScopeInterface::class))->requireScopeParam($config['scope_param'])->setDefaultScope($config['default_scope'])->requireStateParam($config['state_param'])->setScopeDelimiter($config['scope_delimiter'])->setAccessTokenTTL($config['access_token_ttl']);
         // add the supported grant types to the authorization server
         foreach ($config['grant_types'] as $grantIdentifier => $grantParams) {
             $grant = $app->make($grantParams['class']);
             $grant->setAccessTokenTTL($grantParams['access_token_ttl']);
             if (array_key_exists('callback', $grantParams)) {
                 list($className, $method) = array_pad(explode('@', $grantParams['callback']), 2, 'verify');
                 $verifier = $app->make($className);
                 $grant->setVerifyCredentialsCallback([$verifier, $method]);
             }
             if (array_key_exists('auth_token_ttl', $grantParams)) {
                 $grant->setAuthTokenTTL($grantParams['auth_token_ttl']);
             }
             if (array_key_exists('refresh_token_ttl', $grantParams)) {
                 $grant->setRefreshTokenTTL($grantParams['refresh_token_ttl']);
             }
             if (array_key_exists('rotate_refresh_tokens', $grantParams)) {
                 $grant->setRefreshTokenRotation($grantParams['rotate_refresh_tokens']);
             }
             $issuer->addGrantType($grant, $grantIdentifier);
         }
         $checker = $app->make(ResourceServer::class);
         $authorizer = new Authorizer($issuer, $checker);
         $authorizer->setRequest($app['request']);
         $authorizer->setTokenType($app->make($config['token_type']));
         $app->refresh('request', $authorizer, 'setRequest');
         return $authorizer;
     });
     $app->alias('oauth2-server.authorizer', Authorizer::class);
 }
 /**
  * Register the manager class.
  *
  * @param \Illuminate\Contracts\Container\Container $app
  *
  * @return void
  */
 protected function registerManager(Application $app)
 {
     $app->singleton('telegram', function ($app) {
         $config = $app['config'];
         return new BotsManager($config, $app);
     });
     $app->alias('telegram', BotsManager::class);
 }
 /**
  * Register the manager class.
  *
  * @param \Illuminate\Contracts\Container\Container $app
  *
  * @return void
  */
 protected function registerManager(Application $app)
 {
     $app->singleton('telegram', function ($app) {
         $config = (array) $app['config']['telegram'];
         return (new BotsManager($config))->setContainer($app);
     });
     $app->alias('telegram', BotsManager::class);
 }
 /**
  * @param Container        $container
  * @param ConfigRepository $config
  */
 protected function registerBindings(Container $container, ConfigRepository $config)
 {
     $container->singleton(FractalService::class, function () use($config) {
         $fractal = new FractalService();
         $this->configureService($fractal, $config[self::CONFIG_KEY]);
         return $fractal;
     });
     $container->alias(FractalService::class, FractalServiceContract::class);
 }
Exemple #15
0
 /**
  * Initialise the IoC Service Container
  */
 protected function setupContainer()
 {
     // Only set the application on the Facade
     // if there is none yet set
     if (is_null(App::getFacadeApplication())) {
         App::setFacadeApplication(new Container());
     }
     $this->container = App::getFacadeApplication();
     $this->container->singleton('app', $this->container);
 }
 /**
  * @param Container        $container
  * @param ConfigRepository $config
  *
  * @throws Exception
  */
 protected function registerContainerBindings(Container $container, ConfigRepository $config)
 {
     if (!isset($config['rbac'])) {
         throw new Exception('RBAC configuration not registered.');
     }
     $rbacConfig = $config['rbac'];
     $container->alias('Nord\\Lumen\\Rbac\\RbacService', 'Nord\\Lumen\\Rbac\\Contracts\\RbacService');
     $container->alias($rbacConfig['subjectProvider'], 'Nord\\Lumen\\Rbac\\Contracts\\SubjectProvider');
     $container->singleton('Nord\\Lumen\\Rbac\\RbacService', function () use($container) {
         return $this->createService($container);
     });
 }
 /**
  * Bind the storage implementations to the IoC container.
  *
  * @param \Illuminate\Contracts\Foundation\Application $app
  *
  * @return void
  */
 public function registerStorageBindings(Application $app)
 {
     $provider = $this;
     $app->singleton(RedisAccessToken::class, function () use($provider) {
         $storage = new RedisAccessToken($provider->app['redis']);
         return $storage;
     });
     $app->singleton(RedisAuthCode::class, function () use($provider) {
         $storage = new RedisAuthCode($provider->app['redis']);
         return $storage;
     });
     $app->singleton(RedisClient::class, function ($app) use($provider) {
         $storage = new RedisClient($provider->app['redis']);
         return $storage;
     });
     $app->singleton(RedisRefreshToken::class, function () use($provider) {
         $storage = new RedisRefreshToken($provider->app['redis']);
         return $storage;
     });
     $app->singleton(RedisScope::class, function ($app) use($provider) {
         $storage = new RedisScope($provider->app['redis']);
         return $storage;
     });
     $app->singleton(RedisSession::class, function () use($provider) {
         $storage = new RedisSession($provider->app['redis']);
         return $storage;
     });
 }
 /**
  * Bind the storage implementations to the IoC container.
  *
  * @param \Illuminate\Contracts\Foundation\Application $app
  *
  * @return void
  */
 public function registerStorageBindings(Application $app)
 {
     $provider = $this;
     $app->singleton(FluentAccessToken::class, function () use($provider) {
         $storage = new FluentAccessToken($provider->app['db']);
         $storage->setConnectionName($provider->getConnectionName());
         return $storage;
     });
     $app->singleton(FluentAuthCode::class, function () use($provider) {
         $storage = new FluentAuthCode($provider->app['db']);
         $storage->setConnectionName($provider->getConnectionName());
         return $storage;
     });
     $app->singleton(FluentClient::class, function ($app) use($provider) {
         $limitClientsToGrants = $app['config']->get('oauth2.limit_clients_to_grants');
         $storage = new FluentClient($provider->app['db'], $limitClientsToGrants);
         $storage->setConnectionName($provider->getConnectionName());
         return $storage;
     });
     $app->singleton(FluentRefreshToken::class, function () use($provider) {
         $storage = new FluentRefreshToken($provider->app['db']);
         $storage->setConnectionName($provider->getConnectionName());
         return $storage;
     });
     $app->singleton(FluentScope::class, function ($app) use($provider) {
         $limitClientsToScopes = $app['config']->get('oauth2.limit_clients_to_scopes');
         $limitScopesToGrants = $app['config']->get('oauth2.limit_scopes_to_grants');
         $storage = new FluentScope($provider->app['db'], $limitClientsToScopes, $limitScopesToGrants);
         $storage->setConnectionName($provider->getConnectionName());
         return $storage;
     });
     $app->singleton(FluentSession::class, function () use($provider) {
         $storage = new FluentSession($provider->app['db']);
         $storage->setConnectionName($provider->getConnectionName());
         return $storage;
     });
 }
 /**
  * Initialize Analytics Library with Default Config.
  *
  * @param \Illuminate\Contracts\Container\Container $app
  */
 protected function registerAnalytics(Application $app)
 {
     $app->singleton('gamp', function ($app) {
         $config = $app['config'];
         $analytics = new Analytics($config->get('gamp.is_ssl', false));
         $analytics->setProtocolVersion($config->get('gamp.protocol_version', 1))->setTrackingId($config->get('gamp.tracking_id'));
         if ($config->get('gamp.anonymize_ip', false)) {
             $analytics->setAnonymizeIp('1');
         }
         if ($config->get('gamp.async_requests', false)) {
             $analytics->setAsyncRequest(true);
         }
         return $analytics;
     });
     $app->alias('gamp', Analytics::class);
 }
 /**
  * @param Container $container
  * @param ConfigRepository $config
  */
 protected function registerContainerBindings(Container $container, ConfigRepository $config)
 {
     $container->singleton('JMS\\Serializer\\Serializer', function () use($config) {
         return $this->createSerializer($config['serializer'], $config['app.debug']);
     });
 }
 /**
  * Register the Middleware to the IoC container because
  * some middleware need additional parameters.
  *
  * @param \Illuminate\Contracts\Container\Container $app
  *
  * @return void
  */
 public function registerMiddlewareBindings(Application $app)
 {
     $app->singleton(CheckAuthCodeRequestMiddleware::class, function ($app) {
         return new CheckAuthCodeRequestMiddleware($app['oauth2-server.authorizer']);
     });
     $app->singleton(OAuthMiddleware::class, function ($app) {
         $httpHeadersOnly = $app['config']->get('oauth2.http_headers_only');
         return new OAuthMiddleware($app['oauth2-server.authorizer'], $httpHeadersOnly);
     });
     $app->singleton(OAuthClientOwnerMiddleware::class, function ($app) {
         return new OAuthClientOwnerMiddleware($app['oauth2-server.authorizer']);
     });
     $app->singleton(OAuthUserOwnerMiddleware::class, function ($app) {
         return new OAuthUserOwnerMiddleware($app['oauth2-server.authorizer']);
     });
 }
 /**
  * Register the manager class.
  *
  * @param \Illuminate\Contracts\Container\Container $app
  *
  * @return void
  */
 protected function registerManager(Application $app)
 {
     $app->singleton('pusher', function ($app) {
         $config = $app['config'];
         $factory = $app['pusher.factory'];
         return new PusherManager($config, $factory);
     });
     $app->alias('pusher', PusherManager::class);
 }
 public function register(Container $container)
 {
     $container->singleton(ActionHandlerResolver::class, function (Container $container) {
         return new ResolverChain([$container->make(CallableResolver::class), $container->make(ObjectFromContainerResolver::class)]);
     });
 }
 /**
  * Register the presenter decorator.
  *
  * @param \Illuminate\Contracts\Container\Container $app
  *
  * @return void
  */
 public function registerAutoPresenter(Container $app)
 {
     $app->singleton('autopresenter', function (Container $app) {
         $autoPresenter = new AutoPresenter();
         $autoPresenter->register($app->make(AtomDecorator::class, ['autoPresenter' => $autoPresenter, 'app' => $app]));
         $autoPresenter->register($app->make(ArrayDecorator::class, ['autoPresenter' => $autoPresenter]));
         $autoPresenter->register($app->make(PaginatorDecorator::class, ['autoPresenter' => $autoPresenter]));
         return $autoPresenter;
     });
     $app->alias('autopresenter', AutoPresenter::class);
 }
 /**
  * Registers container bindings.
  *
  * @param Container $container
  */
 protected function registerBindings(Container $container)
 {
     $container->singleton(ElasticsearchService::class, function ($container) {
         return $this->createService($container);
     });
 }
 public function singleton($abstract, $concrete = null)
 {
     $this->container->singleton($abstract, $concrete);
 }