本文整理汇总了PHP中Illuminate\Container\Container::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::instance方法的具体用法?PHP Container::instance怎么用?PHP Container::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Container\Container
的用法示例。
在下文中一共展示了Container::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupContainer
/**
* Setup the IoC container instance.
*
* @param \Illuminate\Container\Container|null $container
* @return void
*/
protected function setupContainer($container)
{
$this->container = $container ?: new Container();
if (!$this->container->bound('config')) {
$this->container->instance('config', new Fluent());
}
}
示例2: it_should_not_affect_parent_container
/**
* @test
*/
public function it_should_not_affect_parent_container()
{
$this->parent->instance('a', 1);
$this->local->instance('a', 2);
$this->local->instance('b', 3);
$this->assertTrue($this->parent->bound('a'));
$this->assertEquals(1, $this->parent->make('a'));
$this->assertFalse($this->parent->bound('b'));
$this->assertEquals(2, $this->local->make('a'));
$this->assertEquals(3, $this->local->make('b'));
}
示例3: setUp
/**
* Set up the tests
*/
public function setUp()
{
date_default_timezone_set('Europe/London');
// Create container
$this->app = new Container();
$provider = new EventServiceProvider($this->app);
$provider->register();
// Bind mocked instances into it
$this->app['config'] = $this->mockConfig();
$this->app->instance('request', $this->mockRequest());
$this->app['translation.loader'] = Mockery::mock('Illuminate\\Translation\\FileLoader');
$this->app->instance('Illuminate\\Container\\Container', $this->app);
}
示例4: setUp
/**
* Set up the tests
*
* @return void
*/
public function setUp()
{
$this->app = new Container();
// Laravel classes --------------------------------------------- /
$this->app->instance('path.base', '/src');
$this->app->instance('path', '/src/app');
$this->app->instance('path.public', '/src/public');
$this->app->instance('path.storage', '/src/app/storage');
$this->app['files'] = new Filesystem();
$this->app['config'] = $this->getConfig();
// Trucker classes ------------------------------------------- /
$serviceProvider = new TruckerServiceProvider($this->app);
$this->app = $serviceProvider->bindClasses($this->app);
}
示例5: loadExternalConfig
/**
* Load the external config files specified by the command line option.
*/
protected function loadExternalConfig()
{
$config = new Repository(static::getDefaultConfig());
$filesystem = new Filesystem();
foreach ($this->getConfigFiles($filesystem) as $filename) {
$this->output->writeln("<info>Reading config from <path>{$filename}</path></info>");
if ($filesystem->extension($filename) == 'php') {
$configValues = $filesystem->getRequire($filename);
} else {
$configValues = Yaml::parse($filesystem->get($filename));
}
$config->set(array_dot($configValues));
}
$this->container->instance('config', $config);
}
示例6: setRoutes
/**
* Set the route collection instance.
*
* @param \Illuminate\Routing\RouteCollection $routes
* @return void
*/
public function setRoutes(RouteCollection $routes)
{
foreach ($routes as $route) {
$route->setRouter($this)->setContainer($this->container);
}
$this->routes = $routes;
$this->container->instance('routes', $this->routes);
}
示例7: toMacros
/**
* Dispatch a call to a registered macro
*
* @param string $method The macro's name
* @param array $parameters The macro's arguments
*
* @return mixed
*/
public function toMacros($method, $parameters)
{
if (!$this->app['former']->hasMacro($method)) {
return false;
}
// Get and format macro
$callback = $this->app['former']->getMacro($method);
if ($callback instanceof Closure) {
return call_user_func_array($callback, $parameters);
} elseif (!is_string($callback)) {
return false;
}
// Get class and method
list($class, $method) = explode('@', $callback);
$this->app->instance('Illuminate\\Container\\Container', $this->app);
return call_user_func_array(array($this->app->make($class), $method), $parameters);
}
示例8: resolveController
/**
* Resolve a controller from the container.
*
* @param string $class
*
* @return \Illuminate\Routing\Controller
*/
protected function resolveController($class)
{
$controller = $this->container->make($class);
if (!$this->container->bound($class)) {
$this->container->instance($class, $controller);
}
return $controller;
}
示例9: createContainer
protected function createContainer()
{
$container = new Container();
$container->instance('array_iterator', new \ArrayIterator(range(1, 5)));
$container->bind('error', function () {
throw new \RuntimeException();
});
return new LaravelContainerAdapter($container);
}
示例10: setUp
/**
* Set up the tests
*
* @return void
*/
public function setUp()
{
$this->app = new Container();
// Laravel classes --------------------------------------------- /
$this->app->instance('path.base', '/src');
$this->app->instance('path', '/src/app');
$this->app->instance('path.public', '/src/public');
$this->app->instance('path.storage', '/src/app/storage');
$this->app['files'] = new Filesystem();
$this->app['config'] = $this->getConfig();
$this->app['remote'] = $this->getRemote();
$this->app['artisan'] = $this->getArtisan();
$this->app['rocketeer.command'] = $this->getCommand();
// Rocketeer classes ------------------------------------------- /
$serviceProvider = new RocketeerServiceProvider($this->app);
$this->app = $serviceProvider->bindPaths($this->app);
$this->app = $serviceProvider->bindCoreClasses($this->app);
$this->app = $serviceProvider->bindClasses($this->app);
$this->app = $serviceProvider->bindScm($this->app);
}
示例11: 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);
}
示例12: getController
/**
* Get the routes controller instance.
*
* @return mixed
*/
public function getController()
{
if (!isset($this->action['uses']) || !is_string($this->action['uses'])) {
return;
} elseif (isset($this->controller)) {
return $this->controller;
}
if (Str::contains($this->action['uses'], '@')) {
list($controller, $this->method) = explode('@', $this->action['uses']);
$this->container->instance($controller, $this->controller = $this->container->make($controller));
return $this->controller;
}
}
示例13: testDispatchShouldCallAfterResolvingIfCommandNotQueued
public function testDispatchShouldCallAfterResolvingIfCommandNotQueued()
{
$container = new Container();
$handler = m::mock('StdClass')->shouldIgnoreMissing();
$handler->shouldReceive('after')->once();
$container->instance('Handler', $handler);
$dispatcher = new Dispatcher($container);
$dispatcher->mapUsing(function () {
return 'Handler@handle';
});
$dispatcher->dispatch(new BusDispatcherTestBasicCommand(), function ($handler) {
$handler->after();
});
}
示例14: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$app = new Container();
$app->instance('config', new Repository());
(new EventServiceProvider($app))->register();
(new AmiServiceProvider($app))->register();
$this->loop = $app[LoopInterface::class];
$this->loop->nextTick(function () {
if (!$this->running) {
$this->loop->stop();
}
});
$this->stream = $app[Stream::class];
$this->events = $app['events'];
$this->app = $app;
}
示例15: bindConfiguration
/**
* Bind paths to the configuration files
*
* @return void
*/
protected function bindConfiguration()
{
$path = $this->getBasePath();
$logs = $this->getStoragePath();
// Prepare the paths to bind
$paths = array('config' => '.rocketeer', 'events' => '.rocketeer/events', 'tasks' => '.rocketeer/tasks', 'logs' => $logs . '/logs');
foreach ($paths as $key => $file) {
$filename = $path . $file;
// Check whether we provided a file or folder
if (!is_dir($filename) and file_exists($filename . '.php')) {
$filename .= '.php';
}
// Use configuration in current folder if none found
$realpath = realpath('.') . '/' . $file;
if (!file_exists($filename) and file_exists($realpath)) {
$filename = $realpath;
}
$this->app->instance('path.rocketeer.' . $key, $filename);
}
}