当前位置: 首页>>代码示例>>PHP>>正文


PHP Container::singleton方法代码示例

本文整理汇总了PHP中Illuminate\Contracts\Container\Container::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::singleton方法的具体用法?PHP Container::singleton怎么用?PHP Container::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Contracts\Container\Container的用法示例。


在下文中一共展示了Container::singleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register

 public function register(Container $container)
 {
     $container->singleton(Container::class, function () use($container) {
         return $container;
     });
     $container->singleton(ContainerInterface::class, LaravelContainer::class);
 }
开发者ID:simensen,项目名称:monii-nimble-framework,代码行数:7,代码来源:ContainerServiceProvider.php

示例2: registerContainerBindings

 /**
  * @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();
     });
 }
开发者ID:nordsoftware,项目名称:lumen-file-manager,代码行数:12,代码来源:EloquentServiceProvider.php

示例3: addConnection

 /**
  * @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;
     }
 }
开发者ID:Devitek,项目名称:orm,代码行数:12,代码来源:IlluminateRegistry.php

示例4: registerContainerBindings

 /**
  * @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);
     });
 }
开发者ID:nordsoftware,项目名称:lumen-file-manager,代码行数:13,代码来源:DoctrineServiceProvider.php

示例5: handle

 /**
  * 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);
 }
开发者ID:ben-challis,项目名称:api-1,代码行数:23,代码来源:Request.php

示例6: registerContainerBindings

 /**
  * 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);
     });
 }
开发者ID:nordsoftware,项目名称:lumen-doctrine-mongodb-odm,代码行数:15,代码来源:DoctrineServiceProvider.php

示例7: registerContainerBindings

 /**
  * 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');
 }
开发者ID:jaschweder,项目名称:lumen-doctrine,代码行数:13,代码来源:DoctrineServiceProvider.php

示例8: registerContainerBindings

 /**
  * 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);
     });
 }
开发者ID:nordsoftware,项目名称:lumen-mandrill-mailer,代码行数:12,代码来源:MandrillMailServiceProvider.php

示例9: registerContainerBindings

 /**
  * @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);
     });
 }
开发者ID:nordsoftware,项目名称:lumen-image-manager,代码行数:11,代码来源:ImageManagerServiceProvider.php

示例10: registerBindings

 /**
  * @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);
 }
开发者ID:nordsoftware,项目名称:lumen-sparkpost,代码行数:11,代码来源:SparkPostServiceProvider.php

示例11: registerAuthorizer

 /**
  * 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);
 }
开发者ID:catlabinteractive,项目名称:laravel-charon,代码行数:41,代码来源:ServiceProvider.php

示例12: registerManager

 /**
  * 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);
 }
开发者ID:HalimZamal,项目名称:telegram-bot-sdk,代码行数:15,代码来源:TelegramServiceProvider.php

示例13: registerManager

 /**
  * 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);
 }
开发者ID:irazasyed,项目名称:telegram-bot-sdk,代码行数:15,代码来源:TelegramServiceProvider.php

示例14: registerBindings

 /**
  * @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);
 }
开发者ID:nordsoftware,项目名称:lumen-fractal,代码行数:13,代码来源:FractalServiceProvider.php

示例15: setupContainer

 /**
  * 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);
 }
开发者ID:aedart,项目名称:scaffold,代码行数:13,代码来源:IoC.php


注:本文中的Illuminate\Contracts\Container\Container::singleton方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。