本文整理汇总了PHP中Illuminate\Container\Container::bind方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::bind方法的具体用法?PHP Container::bind怎么用?PHP Container::bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Container\Container
的用法示例。
在下文中一共展示了Container::bind方法的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: getContainer
/**
* @return \Illuminate\Container\Container
*/
public static function getContainer()
{
if (!self::$container) {
self::$container = new \Illuminate\Container\Container();
self::$container->bind('app', self::$container);
}
return self::$container;
}
示例3: init
public function init()
{
$builder = new Container();
$builder->bind('bicycle_factory_shared', function ($app) {
return new \PhpBench\Benchmarks\Container\Acme\BicycleFactory();
}, true);
$builder->bind('bicycle_factory', function ($app) {
return new \PhpBench\Benchmarks\Container\Acme\BicycleFactory();
}, false);
$this->container = $builder;
}
示例4: registerRepositories
/**
* Register repositories Interfaces
*
* @return void
*/
public function registerRepositories()
{
//Bind UserRepository interface
$this->ioc->bind('App\\Repositories\\Contracts\\UserRepositoryInterface', 'App\\Repositories\\UserRepository');
$this->ioc->bind('UserRepo', function ($app) {
return $app->make('App\\Repositories\\Contracts\\UserRepositoryInterface');
});
//Bind PostRepository interface
$this->ioc->bind('App\\Repositories\\Contracts\\PostRepositoryInterface', 'App\\Repositories\\PostRepository');
$this->ioc->bind('PostRepo', function ($app) {
return $app->make('App\\Repositories\\Contracts\\PostRepositoryInterface');
});
}
示例5: setUpBeforeClass
public static function setUpBeforeClass()
{
$app = new Container();
$app->bind('config', function () {
return Mockery::mock('config', function ($mock) {
$mock->shouldReceive('get')->with('config.image_engine', '')->andReturn('Gd');
$mock->shouldReceive('get')->with('config.quality', '')->andReturn(75);
$mock->shouldReceive('get')->with('config.cache_folder', '')->andReturn('');
});
});
$app['path.public'] = 'tests/public';
$app->bind('illuminage', function ($app) {
return new \Illuminage\Illuminage($app);
});
Illuminage::setFacadeApplication($app);
}
示例6: register
/**
* Bind additional classes to the Container
*
* @param Container $app
*
* @return void
*/
public function register(Container $app)
{
$app->bind('campfire', function ($app) {
return new Campfire($app['config']->get('rocketeer-campfire::config'));
});
return $app;
}
示例7: register
/**
* Bind additional classes to the Container
*
* @param Container $app
*
* @return void
*/
public function register(Container $app)
{
$app->bind('newrelic', function ($app) {
return new RocketeerNewrelicConfig($app['config']->get('rocketeer-newrelic::config'));
});
return $app;
}
示例8: applyType
/**
* Apply various parameters according to form type
*
* @param string $type The original form type provided
*
* @return string The final form type
*/
private function applyType($type)
{
// If classic form
if ($type == 'open') {
return $this->app['former']->getOption('default_form_type');
}
// Look for HTTPS form
if (Str::contains($type, 'secure')) {
$type = str_replace('secure', '', $type);
$this->secure = true;
}
// Look for file form
if (Str::contains($type, 'for_files')) {
$type = str_replace('for_files', '', $type);
$this->attributes['enctype'] = 'multipart/form-data';
}
// Calculate form type
$type = str_replace('open', '', $type);
$type = trim($type, '_');
// If raw form
if ($type == 'raw') {
$this->app->bind('former.form.framework', function ($app) {
return $app['former']->getFrameworkInstance('Nude');
});
}
// Use default form type if the one provided is invalid
if ($type !== 'raw' and !in_array($type, $this->app['former.form.framework']->availableTypes())) {
$type = $this->app['former']->getOption('default_form_type');
}
return $type;
}
示例9: register
/**
* Bind additional classes to the Container
*
* @param Container $app
*
* @return void
*/
public function register(Container $app)
{
$app->bind('slack', function ($app) {
return new Client($app['config']->get('rocketeer-slack::url'));
});
return $app;
}
示例10: createContainer
/**
* @return ContainerInterface
*/
private function createContainer(array $map = [])
{
$container = new Container();
foreach ($map as $key => $value) {
$container->bind($key, $value);
}
return new LaravelContainer($container);
}
示例11: register
public function register(Container $app)
{
$settings = ['username' => $app['config']->get('rocketeer-slack-unofficial::config')['url'], 'channel' => $app['config']->get('rocketeer-slack-unofficial::config')['channel'], 'link_names' => true, 'icon' => ':rocket:'];
$app->bind('slack', function ($app) use($settings) {
return new Client($app['config']->get('rocketeer-slack-unofficial::config')['hook-url'], $settings);
});
return $app;
}
示例12: registerViewFinder
/**
* Register the view finder implementation.
*
* @return void
*/
public function registerViewFinder()
{
$me = $this;
$this->container->bind('view.finder', function ($app) use($me) {
$paths = $me->viewPaths;
return new FileViewFinder($app['files'], $paths);
});
}
示例13: shared
/**
* Shared is a pseudonym for `bind()` as singleton.
*
* @param $abstract
* @param null $concrete
*
* @return void
*/
public function shared($abstract, $concrete = NULL)
{
// translate ['alias','concrete'] to ['alias'=>'concrete'] for embedded DI
if (is_array($abstract)) {
$abstract = [$abstract[0] => $abstract[1]];
}
static::$container->bind($abstract, $concrete, TRUE);
}
示例14: bind
/**
* Overload the bind method so the services are added to the Slim DI container as well as Illuminate container
*/
public function bind($abstract, $concrete = null, $shared = false)
{
parent::bind($abstract, $concrete, $shared);
$service_manager = $this;
$this->app->{$abstract} = function () use($service_manager, $abstract) {
return $service_manager->make($abstract);
};
}
示例15: testAliases
public function testAliases()
{
$container = new Container();
$container->bind('request', function () {
return 'input';
});
$container->bind('translator', function () {
return 'lang';
});
$container->bind('blade.compiler', function () {
return 'blade';
});
Container::setInstance($container);
$this->assertEquals('input', $this->input);
$this->assertEquals('lang', $this->lang);
$this->assertEquals('blade', $this->blade_compiler);
$this->assertSame($container, $this->app);
}