Flarum\Foundation\Application::register PHP Method

register() public method

Register a service provider with the application.
public register ( ServiceProvider | string $provider, array $options = [], boolean $force = false ) : ServiceProvider
$provider Illuminate\Support\ServiceProvider | string
$options array
$force boolean
return Illuminate\Support\ServiceProvider
    public function register($provider, $options = [], $force = false)
    {
        if ($registered = $this->getProvider($provider) && !$force) {
            return $registered;
        }
        // If the given "provider" is a string, we will resolve it, passing in the
        // application instance automatically for the developer. This is simply
        // a more convenient way of specifying your service provider classes.
        if (is_string($provider)) {
            $provider = $this->resolveProviderClass($provider);
        }
        $provider->register();
        // Once we have registered the service we will iterate through the options
        // and set each of them on the application so they will be available on
        // the actual loading of the service objects and for developer usage.
        foreach ($options as $key => $value) {
            $this[$key] = $value;
        }
        $this->markAsRegistered($provider);
        // If the application has already booted, we will call this boot method on
        // the provider class so it has an opportunity to do its boot logic and
        // will be ready for any usage by the developer's application logics.
        if ($this->booted) {
            $this->bootProvider($provider);
        }
        return $provider;
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function getMiddleware(Application $app)
 {
     $pipe = new MiddlewarePipe();
     $path = parse_url($app->url(), PHP_URL_PATH);
     $errorDir = __DIR__ . '/../../error';
     if (!$app->isInstalled()) {
         $app->register('Flarum\\Install\\InstallServiceProvider');
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession'));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.install.routes')]));
         $pipe->pipe($path, new HandleErrors($errorDir, true));
     } elseif ($app->isUpToDate() && !$app->isDownForMaintenance()) {
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\ParseJsonBody'));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\StartSession'));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\RememberFromCookie'));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\AuthenticateWithSession'));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\SetLocale'));
         event(new ConfigureMiddleware($pipe, $path, $this));
         $pipe->pipe($path, $app->make('Flarum\\Http\\Middleware\\DispatchRoute', ['routes' => $app->make('flarum.forum.routes')]));
         $pipe->pipe($path, new HandleErrors($errorDir, $app->inDebugMode()));
     } else {
         $pipe->pipe($path, function () use($errorDir) {
             return new HtmlResponse(file_get_contents($errorDir . '/503.html', 503));
         });
     }
     return $pipe;
 }
All Usage Examples Of Flarum\Foundation\Application::register