本文整理汇总了PHP中Illuminate\Container\Container::bindIf方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::bindIf方法的具体用法?PHP Container::bindIf怎么用?PHP Container::bindIf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Container\Container
的用法示例。
在下文中一共展示了Container::bindIf方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupContainer
/**
* Bind required instances for the service provider.
*/
protected function setupContainer()
{
$this->container->bindIf('files', function () {
return new Filesystem();
}, true);
$this->container->bindIf('events', function () {
return new Dispatcher();
}, true);
$this->container->bindIf('config', function () {
return ['view.paths' => (array) $this->viewPaths, 'view.compiled' => $this->cachePath];
}, true);
}
示例2: bindCoreClasses
/**
* Bind core classes to the Container
*
* @param Container $app
*
* @return Container
*/
public function bindCoreClasses(Container $app)
{
$app->bindIf('events', function ($app) {
return new Dispatcher($app);
}, true);
$app->bindIf('router', function ($app) {
return new Router($app['events'], $app);
}, true);
$app->bind('url', function ($app) {
return new UrlGenerator($app['router']->getRoutes(), $app['request']);
});
return $app;
}
示例3: bindCoreClasses
/**
* Bind the core classes to the Container
*
* @param Container $app
*
* @return Container
*/
public function bindCoreClasses(Container $app)
{
// Cancel if in the scope of a Laravel application
if ($app->bound('events')) {
return $app;
}
// Core classes
//////////////////////////////////////////////////////////////////
$app->bindIf('files', 'Illuminate\\Filesystem\\Filesystem');
$app->bindIf('url', 'Illuminate\\Routing\\UrlGenerator');
// Session and request
//////////////////////////////////////////////////////////////////
$app->bindIf('session.manager', function ($app) {
return new SessionManager($app);
});
$app->bindIf('session', function ($app) {
return $app['session.manager']->driver('array');
}, true);
$app->bindIf('request', function ($app) {
$request = Request::createFromGlobals();
if (method_exists($request, 'setSessionStore')) {
$request->setSessionStore($app['session']);
} else {
$request->setSession($app['session']);
}
return $request;
}, true);
// Config
//////////////////////////////////////////////////////////////////
$app->bindIf('path.config', function ($app) {
dd(__DIR__ . '/../config/');
return __DIR__ . '/../config/';
}, true);
$app->bindIf('config', function ($app) {
$config = new Repository();
$this->loadConfigurationFiles($app, $config);
return $config;
}, true);
// Localization
//////////////////////////////////////////////////////////////////
$app->bindIf('translation.loader', function ($app) {
return new FileLoader($app['files'], 'src/config');
});
$app->bindIf('translator', function ($app) {
$loader = new FileLoader($app['files'], 'lang');
return new Translator($loader, 'fr');
});
return $app;
}
示例4: 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']);
}
}
示例5: bindCoreClasses
/**
* Bind the core classes
*
* @param Container $app
*
* @return Container
*/
public function bindCoreClasses(Container $app)
{
if ($app->bound('events')) {
return $app;
}
$app->bindIf('request', function ($app) {
return Request::createFromGlobals();
});
$app->bindIf('url', function ($app) {
$routes = new RouteCollection();
return new UrlGenerator($routes, $app['request']);
});
$app->bindIf('html', function ($app) {
return new HtmlBuilder($app['url']);
});
$app->bindIf('path.public', function () {
return realpath(__DIR__ . '/../../');
});
return $app;
}
示例6: bindIf
/**
* Register a binding if it hasn't already been registered.
*
* @param string $abstract
* @param \Closure|string|null $concrete
* @param bool $shared
* @return void
*/
public function bindIf($abstract, $concrete = null, $shared = false)
{
if (!$this->parentContainer->bound($abstract) && !$this->bound($abstract)) {
parent::bindIf($abstract, $concrete, $shared);
}
}
示例7: bindCoreClasses
/**
* Bind the core classes
*
* @param Container $app
*
* @return Container
*/
public function bindCoreClasses(Container $app)
{
$app->bindIf('files', 'Illuminate\\Filesystem\\Filesystem');
$app->bindIf('request', function () {
return Request::createFromGlobals();
}, true);
$app->bindIf('config', function ($app) {
$fileloader = new FileLoader($app['files'], __DIR__ . '/../config');
return new Repository($fileloader, 'config');
}, true);
$app->bindIf('remote', function ($app) {
return new RemoteManager($app);
}, true);
$app->bindIf('events', function ($app) {
return new Dispatcher($app);
}, true);
$app->bindIf('log', function () {
return new Writer(new Logger('rocketeer'));
}, true);
// Register factory and custom configurations
$app = $this->registerConfig($app);
return $app;
}
示例8: 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;
}
示例9: bindClasses
/**
* Bind Illuminage's classes
*
* @param Container $app
*
* @return Container
*/
public function bindClasses(Container $app)
{
// Register config file
$app['config']->package('anahkiasen/illuminage', __DIR__ . '/../config');
$app->bindIf('illuminage', function ($app) {
return new Illuminage($app);
});
$app->bindIf('imagine', function ($app) {
$engine = $app['illuminage']->getOption('image_engine');
$imagine = "\\Imagine\\{$engine}\\Imagine";
return new $imagine();
});
$app->bindIf('illuminage.processor', function ($app) {
return new ImageProcessor($app['imagine']);
});
$app->bindIf('illuminage.cache', function ($app) {
return new Cache($app['illuminage']);
});
// Set cache folder if non existing
$cache = $app['illuminage']->getPublicFolder() . '/' . $app['config']->get('illuminage::cache_folder');
if (!file_exists($cache)) {
$app['config']->set('illuminage::cache_folder', 'public/');
}
return $app;
}
示例10: bindCoreClasses
/**
* Bind the core classes
*
* @param Container $app
*
* @return Container
*/
public function bindCoreClasses(Container $app)
{
$app->bindIf('files', 'Illuminate\\Filesystem\\Filesystem');
$app->bindIf('config', function ($app) {
$fileloader = new FileLoader($app['files'], __DIR__ . '/../config');
return new Repository($fileloader, 'config');
}, true);
// Register factory and custom configurations
$app = $this->registerConfig($app);
return $app;
}