本文整理汇总了PHP中Illuminate\Container\Container::alias方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::alias方法的具体用法?PHP Container::alias怎么用?PHP Container::alias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Container\Container
的用法示例。
在下文中一共展示了Container::alias方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerCache
protected function registerCache()
{
$this->app->singleton('cache', function ($app) {
return new \Illuminate\Cache\CacheManager($app);
});
$this->app->singleton('cache.store', function ($app) {
return $app['cache']->driver();
});
$this->app->alias('cache', \Illuminate\Contracts\Cache\Factory::class);
}
示例2: 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);
}
}
示例3: bindForm
/**
* Bind Form classes to the container
*
* @param Container $app
*
* @return Container
*/
public function bindForm(Container $app)
{
// Add config namespace
$configPath = __DIR__ . '/../config/form.php';
$this->mergeConfigFrom($configPath, 'form');
$this->publishes([$configPath => $app['path.config'] . '/form.php']);
$framework = $app['config']->get('form.framework');
$app->bind('form.framework', function ($app) {
return $app['form']->getFrameworkInstance($app['config']->get('form.framework'));
});
$app->singleton('form.populator', function ($app) {
return new Populator();
});
$app->singleton('form.dispatcher', function ($app) {
return new MethodDispatcher($app, Form::FIELDSPACE);
});
$app->singleton('form', function ($app) {
return new Form($app, $app->make('form.dispatcher'));
});
$app->alias('form', 'Form\\Form');
Helpers::setApp($app);
return $app;
}
示例4: getContainer
/**
* Get the current dependencies
*
* @param string $dependency A dependency to make on the fly
*
* @return Container
*/
public static function getContainer($dependency = null)
{
if (!static::$container) {
$container = new Container();
// Create HTML
$container->bindIf('html', 'LaravelBook\\Laravel4Powerpack\\HTML');
// Create basic Request instance to use
$container->alias('Symfony\\Component\\HttpFoundation\\Request', 'request');
$container->bindIf('Symfony\\Component\\HttpFoundation\\Request', function () {
return Request::createFromGlobals();
});
static::setContainer($container);
}
// Shortcut for getting a dependency
if ($dependency) {
return static::$container->make($dependency);
}
return static::$container;
}
示例5: alias
/**
* @param string $abstract
* @param array|string $alias
*/
public function alias($abstract, $alias)
{
foreach ((array) $alias as $item) {
$this->container->alias($abstract, $item);
}
}
示例6: alias
/**
* Alias a type to a different name.
*
* @param string $abstract
* @param string $alias
*/
public function alias($abstract, $alias)
{
$this->delegate->alias($abstract, $alias);
}
示例7: bindFormer
/**
* Bind Former classes to the container.
*
* @param Container $app
*
* @return Container
*/
public function bindFormer(Container $app)
{
$framework = $app['config']->get('former.framework');
$app->bind('former.framework', function ($app) {
return $app['former']->getFrameworkInstance($app['config']->get('former.framework'));
});
$app->singleton('former.populator', function ($app) {
return new \Former\Populator();
});
$app->singleton('former.dispatcher', function ($app) {
return new \Former\MethodDispatcher($app, \Former\Former::FIELDSPACE);
});
$app->singleton('former', function ($app) {
return new \Former\Former($app, $app->make('former.dispatcher'));
});
$app->alias('former', 'Former\\Former');
\Former\Helpers::setApp($app);
return $app;
}