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); }
/** * 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); } }
/** * 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; }
/** * 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; }
/** * @param string $abstract * @param array|string $alias */ public function alias($abstract, $alias) { foreach ((array) $alias as $item) { $this->container->alias($abstract, $item); } }
/** * Alias a type to a different name. * * @param string $abstract * @param string $alias */ public function alias($abstract, $alias) { $this->delegate->alias($abstract, $alias); }
/** * 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; }