/** * Initialize the Laravel framework. * @param SymfonyRequest $request */ private function initialize($request = null) { // Store a reference to the database object // so the database connection can be reused during tests $this->oldDb = null; if ($this->app['db'] && $this->app['db']->connection()) { $this->oldDb = $this->app['db']; } // The module can login a user with the $I->amLoggedAs() method, // but this is not persisted between requests. Store a reference // to the logged in user to simulate this. $loggedInUser = null; if ($this->app['auth'] && $this->app['auth']->check()) { $loggedInUser = $this->app['auth']->user(); } // Load the application object $this->app = $this->kernel = $this->loadApplication(); // Set the request instance for the application if (is_null($request)) { $appConfig = (require $this->module->config['project_dir'] . 'config/app.php'); $request = SymfonyRequest::create($appConfig['url']); } $this->app->instance('request', Request::createFromBase($request)); $this->app->instance('middleware.disable', $this->module->config['disable_middleware']); // Reset the old database after the DatabaseServiceProvider ran. // This way other service providers that rely on the $app['db'] entry // have the correct instance available. if ($this->oldDb) { $this->app['events']->listen('Illuminate\\Database\\DatabaseServiceProvider', function () { $this->app->singleton('db', function () { return $this->oldDb; }); }); } $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap(); // If events should be disabled mock the event dispatcher instance if ($this->module->config['disable_events']) { $this->mockEventDispatcher(); } // Setup an event listener to listen for all events that are triggered $this->setupEventListener(); // If there was a user logged in restore this user. // Also reload the user object from the user provider to prevent stale user data. if ($loggedInUser) { $refreshed = $this->app['auth']->getProvider()->retrieveById($loggedInUser->getAuthIdentifier()); $this->app['auth']->setUser($refreshed ?: $loggedInUser); } $this->module->setApplication($this->app); }
/** * Magic method implementation for all the services * * @param string $name * @param mixed $arguments * @throws Exception * @return RentalsUnitedCaching\Services\Processable */ public function dataLoader($name = null, $arguments = null) { $name = $name ? $name : 'base'; $name = 'Jasekz\\RentalsUnitedCaching\\DataLoaders\\' . ucfirst($name); try { if (!isset($this->app[$name])) { // bind for if not already done so $this->app->singleton($name, function () use($name, $arguments) { return new $name($arguments); }); } return $this->app[$name]; } catch (Exception $e) { throw $e; } }
/** * Handle the command. * * @param Repository $config * @param Application $application */ public function handle(Repository $config, Application $application) { // First trigger to resolve. $application->make('translator'); /* * Change the lang loader so we can * add a few more necessary override * paths to the API. */ $application->singleton('translation.loader', function ($application) { return new Loader($application['files'], $application['path.lang']); }); /* * Re-bind the translator so we can use * the new loader defined above. */ $application->singleton('translator', function ($application) { $loader = $application->make('translation.loader'); // When registering the translator component, we'll need to set the default // locale as well as the fallback locale. So, we'll grab the application // configuration so we can easily get both of these values from there. $locale = $application['config']['app.locale']; $trans = new Translator($loader, $locale); $trans->setFallback($application['config']['app.fallback_locale']); return $trans; }); /* * Set the locale if LOCALE is defined. * * LOCALE is defined first thing in our * HTTP Kernel. Respect it! */ if (defined('LOCALE')) { $application->setLocale(LOCALE); $config->set('app.locale', LOCALE); } // Set our locale namespace. $application->make('translator')->addNamespace('streams', realpath(__DIR__ . '/../../../resources/lang')); }
/** * Initialize the Laravel framework. * * @param SymfonyRequest $request */ private function initialize($request = null) { // Store a reference to the database object // so the database connection can be reused during tests $this->oldDb = null; if (isset($this->app['db']) && $this->app['db']->connection()) { $this->oldDb = $this->app['db']; } $this->app = $this->kernel = $this->loadApplication(); // Set the request instance for the application, if (is_null($request)) { $appConfig = (require $this->module->config['project_dir'] . 'config/app.php'); $request = SymfonyRequest::create($appConfig['url']); } $this->app->instance('request', Request::createFromBase($request)); // Reset the old database after the DatabaseServiceProvider ran. // This way other service providers that rely on the $app['db'] entry // have the correct instance available. if ($this->oldDb) { $this->app['events']->listen('Illuminate\\Database\\DatabaseServiceProvider', function () { $this->app->singleton('db', function () { return $this->oldDb; }); }); } $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap(); // Record all triggered events by adding a wildcard event listener $this->app['events']->listen('*', function () { $this->triggeredEvents[] = $this->normalizeEvent($this->app['events']->firing()); }); // Replace the Laravel exception handler with our decorated exception handler, // so exceptions can be intercepted for the disable_exception_handling functionality. $decorator = new ExceptionHandlerDecorator($this->app['Illuminate\\Contracts\\Debug\\ExceptionHandler']); $decorator->exceptionHandlingDisabled($this->exceptionHandlingDisabled); $this->app->instance('Illuminate\\Contracts\\Debug\\ExceptionHandler', $decorator); if ($this->module->config['disable_middleware'] || $this->middlewareDisabled) { $this->app->instance('middleware.disable', true); } if ($this->module->config['disable_events'] || $this->eventsDisabled) { $this->mockEventDispatcher(); } if ($this->module->config['disable_model_events'] || $this->modelEventsDisabled) { Model::unsetEventDispatcher(); } $this->applyBindings(); $this->applyContextualBindings(); $this->applyInstances(); $this->module->setApplication($this->app); }
/** * Register a shared binding in the container. * * @param string|array $abstract * @param \Closure|string|null $concrete * @return void * @static */ public static function singleton($abstract, $concrete = null) { //Method inherited from \Illuminate\Container\Container \Illuminate\Foundation\Application::singleton($abstract, $concrete); }
/** * Resolve application HTTP exception handler. * * @param \Illuminate\Foundation\Application $app * * @return void */ protected function resolveApplicationExceptionHandler($app) { $app->singleton('Illuminate\\Contracts\\Debug\\ExceptionHandler', 'AcExceptionsHandler'); }
<?php use Illuminate\Foundation\Application; // create the application $app = new Application(realpath(__DIR__ . "/../")); // bind important interfaces $app->singleton(Illuminate\Contracts\Http\Kernel::class, App\Http\Kernel::class); $app->singleton(Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class); $app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class); // return the application return $app;
/** * Resolve application HTTP exception handler. * * @param \Illuminate\Foundation\Application $app * * @return void */ protected function resolveApplicationExceptionHandler($app) { $app->singleton('Illuminate\\Contracts\\Debug\\ExceptionHandler', 'Orchestra\\Testbench\\Exceptions\\ApplicationHandler'); }
/** * Register a shared binding in the container. * * @param string|array $abstract * @param \Closure|string|null $concrete */ protected function singleton($abstract, $concrete = null) { $this->app->singleton($abstract, $concrete); }
/** * Resolve application Console Kernel implementation. * * @param \Illuminate\Foundation\Application $app * @return void */ protected function resolveApplicationConsoleKernel($app) { $app->singleton('Illuminate\\Contracts\\Console\\Kernel', 'Nuwave\\Lighthouse\\Tests\\Support\\Console\\Kernel'); }
/** * @param string $basePath The application base path * @param ProvidesCapsulePattern $pattern The capsule pattern * * @return \Illuminate\Foundation\Application */ protected function bootstrapPattern($basePath, $pattern) { // Get the app's autoloader /** @noinspection PhpIncludeInspection */ require Disk::path([$basePath, 'vendor', 'autoload.php']); // Create the application $_app = new Application($basePath); $_app->useEnvironmentPath($basePath); foreach ($pattern as $_abstract => $_concrete) { $_app->singleton($_abstract, $_concrete); } // Set up logging $_app->configureMonologUsing(function (Logger $monolog) { $_logFile = Disk::path([env('DFE_CAPSULE_LOG_PATH', storage_path('logs')), $this->instanceId . '.log']); $_handler = new StreamHandler($_logFile); $_handler->setFormatter(new LineFormatter(null, null, true, true)); $monolog->pushHandler($_handler); }); $this->basePath = $basePath; return $this->app = $_app; }
function it_should_register_core_contract(Application $app) { $app->offsetGet(Argument::type('string'))->shouldBeCalled(); $app->singleton('Atlas\\CoreContract', 'Atlas\\Core')->shouldBeCalled(); $this->register(); }