本文整理汇总了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);
}
示例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();
});
}
示例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;
}
}
示例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);
});
}
示例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);
}
示例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);
});
}
示例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');
}
示例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);
});
}
示例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);
});
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}