/** * 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); }
/** * 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; }
/** * 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; }
/** * 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']); } }
/** * 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; }
/** * 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); } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }