/** * @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); }); }
/** * 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); }
/** * 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'); }
/** * @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 bindings. * * @param \Illuminate\Contracts\Container\Container $app * * @return void */ protected function registerBindings(Application $app) { $app->bind('telegram.bot', function ($app) { $manager = $app['telegram']; return $manager->bot(); }); $app->alias('telegram.bot', Api::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); }
/** * 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); }
/** * Register an addon. * * @param $path * @param $enabled * @param $installed */ public function register($path, array $enabled, array $installed) { if (!is_dir($path)) { return; } $vendor = strtolower(basename(dirname($path))); $slug = strtolower(substr(basename($path), 0, strpos(basename($path), '-'))); $type = strtolower(substr(basename($path), strpos(basename($path), '-') + 1)); $class = studly_case($vendor) . '\\' . studly_case($slug) . studly_case($type) . '\\' . studly_case($slug) . studly_case($type); /* @var Addon|Module|Extension|Twig_ExtensionInterface $addon */ $addon = app($class)->setPath($path)->setType($type)->setSlug($slug)->setVendor($vendor); // If the addon supports states - set the state now. if ($addon->getType() === 'module' || $addon->getType() === 'extension') { $addon->setInstalled(in_array($addon->getNamespace(), $installed)); $addon->setEnabled(in_array($addon->getNamespace(), $enabled)); } // Bind to the service container. $this->container->alias($addon->getNamespace(), $alias = get_class($addon)); $this->container->instance($alias, $addon); // Load package configuration. $this->configurator->addNamespace($addon->getNamespace(), $addon->getPath('resources/config')); // Load system overrides. $this->configurator->addNamespaceOverrides($addon->getNamespace(), base_path('resources/addons/' . $addon->getVendor() . '/' . $addon->getSlug() . '-' . $addon->getType())); // Load application overrides. $this->configurator->addNamespaceOverrides($addon->getNamespace(), $this->application->getResourcesPath('addons/' . $addon->getVendor() . '/' . $addon->getSlug() . '-' . $addon->getType() . '/config')); // Continue loading things. $this->provider->register($addon); // Add the view / translation namespaces. $this->views->addNamespace($addon->getNamespace(), $addon->getPath('resources/views')); $this->translator->addNamespace($addon->getNamespace(), $addon->getPath('resources/lang')); /* * If the addon is a plugin then * load it into Twig when appropriate. */ if ($addon->getType() === 'plugin') { $this->events->listen('Anomaly\\Streams\\Platform\\View\\Event\\RegisteringTwigPlugins', function (RegisteringTwigPlugins $event) use($addon) { $twig = $event->getTwig(); $twig->addExtension($addon); }); } $this->collection->put($addon->getNamespace(), $addon); $this->events->fire(new AddonWasRegistered($addon)); }
/** * 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); }
/** * Register the bindings. * * @param \Illuminate\Contracts\Container\Container $app * * @return void */ protected function registerBindings(Application $app) { $app->bind('pusher.connection', function ($app) { $manager = $app['pusher']; return $manager->connection(); }); $app->alias('pusher.connection', Pusher::class); }