本文整理汇总了PHP中Illuminate\Container\Container::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::singleton方法的具体用法?PHP Container::singleton怎么用?PHP Container::singleton使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Container\Container
的用法示例。
在下文中一共展示了Container::singleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createApplicationContainer
protected function createApplicationContainer()
{
$this->app = new \TestContainer();
$this->app->singleton('config', function () {
return new \Illuminate\Config\Repository();
});
$this->registerConfigure();
$eventServiceProvider = new \Illuminate\Encryption\EncryptionServiceProvider($this->app);
$eventServiceProvider->register();
$eventServiceProvider = new \Illuminate\Events\EventServiceProvider($this->app);
$eventServiceProvider->register();
$queueProvider = new \Illuminate\Queue\QueueServiceProvider($this->app);
$queueProvider->register();
$sessionProvider = new \Illuminate\Session\SessionServiceProvider($this->app);
$sessionProvider->register();
$this->registerDatabase();
$this->registerCache();
$couchbaseProvider = new \Ytake\LaravelCouchbase\CouchbaseServiceProvider($this->app);
$couchbaseProvider->register();
$couchbaseProvider->boot();
$this->app->bind(\Illuminate\Container\Container::class, function () {
return $this->app;
});
(new \Illuminate\Events\EventServiceProvider($this->app))->register();
\Illuminate\Container\Container::setInstance($this->app);
}
示例2: __construct
public function __construct(array $attributes)
{
$this->encrypter = new Encrypter('088409730f085dd15e8e3a7d429dd185', 'AES-256-CBC');
$app = new Container();
$app->singleton('app', 'Illuminate\\Container\\Container');
$app->singleton('config', 'Illuminate\\Config\\Repository');
$app['config']->set('elocrypt.prefix', '__ELOCRYPT__:');
Facade::setFacadeApplication($app);
parent::__construct($attributes);
}
示例3: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$app = new Container();
$app->singleton('app', 'Illuminate\\Config\\Repository');
$app->singleton('config', 'Illuminate\\Config\\Repository');
Facade::setFacadeApplication($app);
$app['app']->set('aliases.Config', Illuminate\Support\Facades\Config::class);
$api_key = empty(getenv('YANDEX_API_KEY')) ? include_once 'yandex.api.key.php' : getenv('YANDEX_API_KEY');
$app['config']->set('services.yandex-translate.key', $api_key);
$this->translate = new Translate();
}
示例4: initialize
/**
* @param Configuration $configuration
* @return void
*/
public function initialize(Configuration $configuration)
{
// start up the service locator
$this->container = new Container();
foreach ($this->default_components as $k => $v) {
if ($k == 'parser.login' and $configuration->getRetsVersion()->isAtLeast1_8()) {
$v = '\\PHRETS\\Parsers\\Login\\OneEight';
}
$this->container->singleton($k, function () use($v) {
return new $v();
});
}
}
示例5: boot
/**
* Set up required container bindings.
*
* @param Container $app
*/
public function boot(Container $app)
{
$app->singleton('files', Filesystem::class);
$app->singleton('events', function ($app) {
return new Dispatcher($app);
});
$app->bind(Builder::class, function ($app) {
return new Builder($app, $app['config']['build.pipeline']);
});
$app->bind(Factory::class, function ($app) {
$engineResolver = $app->make(EngineResolver::class);
$viewFinder = $app->make(FileViewFinder::class, [$app['files'], [$app['config']['source.directory']]]);
return new Factory($engineResolver, $viewFinder, $app['events']);
});
$this->bindAliasesForPipeline($app);
}
示例6: registerViewFinder
/**
* Register the view finder implementation.
*
* @return void
*/
public function registerViewFinder()
{
$me = $this;
$this->container->singleton('view.finder', function ($app) use($me) {
$paths = $me->viewPaths;
return new FileViewFinder($app['files'], $paths);
});
}
示例7: bindWarkhamClasses
/**
* Bind the Warkham classes to the Container
*
* @param Container $app
*
* @return Container
*/
public function bindWarkhamClasses(Container $app)
{
$app->singleton('warkham', function ($app) {
$methodDispatcher = array('Warkham\\Fields\\', Warkham::FIELDSPACE);
$methodDispatcher = new MethodDispatcher($app, $methodDispatcher);
return new Warkham($app, $methodDispatcher);
});
return $app;
}
示例8: __construct
/**
* @param bool $cache
*/
public function __construct($cache)
{
$this->filesystem = new Filesystem();
$this->moduleContainer = new Container();
$this->cache = !$cache;
$container = AppFactory::getInstance()->getContainer();
$container['cache'] = function () {
$cacheContainer = new Container();
$cacheContainer->singleton('files', function () {
return new Filesystem();
});
$cacheContainer->singleton('config', function () {
return AppFactory::getInstance()->getContainer()->config['cache'];
});
return new CacheManager($cacheContainer);
};
$this->cacheManager = $container->get('cache');
}
示例9: __construct
/**
* Build a new Form instance
*
* @param UrlGenerator $url
*/
public function __construct(Container $app, $url, Populator $populator)
{
$this->app = $app;
$this->url = $url;
$this->populator = $populator;
$this->app->singleton('former.form.framework', function ($app) {
return clone $app['former.framework'];
});
}
示例10: ensureIlluminateBase
/**
* Ensure the base event and file bindings are present. Required for binding anything else.
*
* @param Container $app
* @return void
*/
public function ensureIlluminateBase(Container $app = null)
{
if (!$app->bound('events')) {
$app->singleton('events', $this->illuminateClasses['events']);
$app['events']->fire('booting');
}
if (!$app->bound('files')) {
$app->bindIf('files', $this->illuminateClasses['files']);
}
}
示例11: it_should_not_auto_inject_dependencies_from_local_container_into_services_from_parent_container
/**
* @test
*/
public function it_should_not_auto_inject_dependencies_from_local_container_into_services_from_parent_container()
{
$this->local->singleton(Helper::class, function () {
return new Helper(uniqid());
});
$this->parent->singleton(Service::class, function (Container $c) {
return $c->build(Service::class);
});
$this->setExpectedException(BindingResolutionException::class);
$this->local->make(Service::class);
}
示例12: createApplicationContainer
protected function createApplicationContainer()
{
$this->app = new \Illuminate\Container\Container();
$this->app->singleton('config', function () {
return new \Illuminate\Config\Repository();
});
$this->app->instance('log', $log = new \Illuminate\Log\Writer(new \Monolog\Logger('testing')));
$this->app->instance('Psr\\Log\\LoggerInterface', $log = new \Illuminate\Log\Writer(new \Monolog\Logger('testing')));
$this->registerConfigure();
$this->registerDatabase();
$this->registerCache();
$annotationConfiguration = new \Ytake\LaravelAspect\AnnotationConfiguration($this->app['config']->get('ytake-laravel-aop.annotation'));
$annotationConfiguration->ignoredAnnotations();
$this->app->singleton('aspect.manager', function ($app) {
return new \Ytake\LaravelAspect\AspectManager($app);
});
$this->app->bind(\Illuminate\Container\Container::class, function () {
return $this->app;
});
\Illuminate\Container\Container::setInstance($this->app);
}
示例13: registerFactory
/**
* Register the view environment.
*
* @return Illuminate\View\Factory
*/
protected function registerFactory()
{
$this->container->singleton('view', function ($container) {
// Next we need to grab the engine resolver instance that will be used by the
// environment. The resolver will be used by an environment to get each of
// the various engine implementations such as plain PHP or Blade engine.
$resolver = $container['view.engine.resolver'];
$finder = $container['view.finder'];
$env = new Factory($resolver, $finder, $container['events']);
// We will also set the container instance on this view environment since the
// view composers may be classes registered in the container, which allows
// for great testable, flexible composers for the application developer.
$env->setContainer($container);
$env->share('app', $container);
return $env;
});
}
示例14: build
/**
* Run the build command.
*
* @return bool
*/
protected function build()
{
$container = new Container();
$container->singleton('files', Filesystem::class);
$container->bind(Factory::class, function ($app) {
return new Factory($app->make(EngineResolver::class), new FileViewFinder($app['files'], ['test/source']), new Dispatcher($app));
});
$container->afterResolving(function (Factory $factory, $app) {
$factory->addExtension('php', 'php', function () {
return new PhpEngine();
});
$factory->addExtension('blade.php', 'blade', function () use($app) {
return new CompilerEngine(new BladeCompiler($app['files'], vfsStream::url('test/.cache')));
});
});
$builder = new Builder($container, [Skip::class . ':_*', Compile::class]);
return $builder->build(vfsStream::url('test/source'), vfsStream::url('test/build'));
}
示例15: singleton
/**
* Add a singleton definition to the container.
* Not sure if generally required, but this call quietly wraps non-callable $concrete
* implementations with an anonymous function. (i.e.: Simplifies illuminate/container call.)
*
* @param string|array $abstract
* @param mixed $concrete
*
* @return void
*/
public function singleton($abstract, $concrete = NULL)
{
$alias = NULL;
if (is_array($abstract)) {
$alias = $abstract[0];
$abstract = $abstract[1];
# register the alias because the alias is provided
static::$container->alias($abstract, $alias);
}
if (!is_callable($concrete)) {
static::$container->singleton($abstract, function () use($concrete) {
return $concrete;
});
}
if (is_callable($concrete)) {
static::$container->singleton($abstract, $concrete);
}
}