startProvidersPlugin method.

@param \Illuminate\Foundation\Application $app
970681
protected function startProvidersPlugin($app)
    {
        switch ($this->registerProvidersOn) {
            case 'register':
                $this->onRegister('providers', function () {
                    $this->handleProviders();
                });
                break;
            case 'booting':
                $this->app->booting(function () {
                    $this->handleProviders();
                });
                break;
            case 'boot':
                $this->onBoot('providers', function () {
                    $this->handleProviders();
                });
                break;
            case 'booted':
                $this->app->booted(function () {
                    $this->handleProviders();
                });
                break;
            default:
                throw new \LogicException('registerProvidersOn not valid');
                break;
        }
    }
992463
public function handle(Request $request, Application $app = null)
    {
        $this->request = $request;

        try {
            // init services providers
            /** @var \Alchemy\Service\ServiceProviderInterface $providers */
            $providers = $app->getServiceProviders();

            foreach ($providers as $provider) {
                $provider->init($app);
            }


            /*
             * "EVENT" KernelEvents::REQUEST using GetResponse Event
             *
             * This event can be used by an application to filter a request before
             * ever all kernel logic being executed, listeners for this event should
             * be registered outside framework logic (should be on application logic).
             */
            if ($this->dispatcher->hasListeners(KernelEvents::REQUEST)) {
                $event = new GetResponseEvent($this, $request, $app);
                $this->dispatcher->dispatch(KernelEvents::REQUEST, $event);

                if ($event->hasResponse()) {
                    //var_dump($event->getResponse()); die("ee");
                    $event = new FilterResponseEvent($this, $request, $event->getResponse());
                    $this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);

                    return $event->getResponse();
                }
            }

            /*
             * try match the url request with a defined route.
             * it any route match the current url a ResourceNotFoundException
             * will be thrown.
             */
            $params = $this->mapper->match($request);
            $uriParams = $params["params"];

            // prepare request params.
            $params = $this->prepareRequestParams(array($params["mapped"], $request->query->all(), $request->request->all()));

            // add prepared params to request as attributes.
            $request->attributes->add($params);

            // resolve controller
            try {
                $controller = $this->resolver->getController($request);
            } catch (\Exception $exception) {
                /*
                 * Detailed exception types are only for development environments
                 * if the current is a non dev environment just overrides the current exception with
                 * a ResourceNotFoundException exception
                 */
                if ($this->config->get('env.type') !== 'dev') {
                    $exception = new ResourceNotFoundException($request->getPathInfo());
                }

                throw $exception;
            }

            if (! $controller) {
                throw new ResourceNotFoundException($request->getPathInfo());
            }

            // setting default annotations namespace
            $this->annotationReader->setDefaultNamespace('\Alchemy\Annotation\\');
            // seeting annotation reader target
            $this->annotationReader->setTarget($params['_controllerClass'], $params['_controllerMethod']);

            $arguments = $this->resolver->getArguments($app, $request, $controller);

            //"EVENT" FILTER_CONTROLLER
            if ($this->dispatcher->hasListeners(KernelEvents::FILTER_CONTROLLER)) {
                $event = new FilterControllerEvent($this, $controller, $request);
                $this->dispatcher->dispatch(KernelEvents::FILTER_CONTROLLER, $event);

                // getting controller; this can be the same or other filtered controller
                $controller = $event->getController();
            }

            //"EVENT" BEFORE_CONTROLLER
            if ($this->dispatcher->hasListeners(KernelEvents::BEFORE_CONTROLLER)) {
                $event = new ControllerEvent($this, $controller, $arguments, $request);
                $this->dispatcher->dispatch(KernelEvents::BEFORE_CONTROLLER, $event);
            }

            // Execute controller action
            $response = call_user_func_array($controller, $arguments);

            // check returned value by method is a array
            if (is_array($response)) {
                // set controller view data object
                foreach ($response as $key => $value) {
                    $controller[0]->view->$key = $value;
                }
            }

            // getting controller's data.
            $controllerData = (array) $controller[0]->view;

            if (! ($response instanceof Response || $response instanceof JsonResponse)) {
                if ($this->annotationReader->getAnnotation('JsonResponse')) {
                    $controllerData = $response;
                    $response = new JsonResponse();
                    $response->setData($controllerData);
                } else {
                    $response = new Response();
                }
            }

            //"EVENT" AFTER_CONTROLLER
            if ($this->dispatcher->hasListeners(KernelEvents::AFTER_CONTROLLER)) {
                if (!isset($event) || !($event instanceof ControllerEvent)) {
                    $event = new ControllerEvent($this, $controller, $arguments, $request);
                }
                $event->setResponse($response);

                $this->dispatcher->dispatch(KernelEvents::AFTER_CONTROLLER, $event);
            }

            // handling view
            $view = $this->handleView(
                $params['_controllerClass'],
                $params['_controllerMethod'],
                $controllerData,
                $this->annotationReader->getAnnotation('View')
            );

            // handling meta ui
            if ($this->annotationReader->getAnnotation('ServeUi')) {
                $view = $this->handleMetaUi(
                    $controllerData,
                    $this->annotationReader->getAnnotation('ServeUi'),
                    $view,
                    $request
                );
            }

            // if there is a view adapter instance, get its contents and set to response content
            if (! empty($view)) {
                foreach ($uriParams as $keyParam => $valParam) {
                    $view->assign($keyParam, $valParam);
                }

                //"EVENT" VIEW dispatch all KernelEvents::VIEW events
                if ($this->dispatcher->hasListeners(KernelEvents::VIEW)) {
                    $event = new ViewEvent($this, $view, $request, $this->annotationReader, $app);
                    $this->dispatcher->dispatch(KernelEvents::VIEW, $event);
                    $view = $event->getView();
                }

                $response->setContent($view->getOutput());
            }

        } catch (ResourceNotFoundException $e) {
            $exceptionHandler = new Exception\Handler();

            if ($request->isXmlHttpRequest()) {
                $response = new JsonResponse();
                $response->setData(array('success'=>false, 'message'=>$e->getMessage()));
            } else {
                $response = new Response($exceptionHandler->getOutput($e), 404);
            }
        } catch (\Exception $e) {
//            echo $e->getMessage();
//            echo "<br><pre>";
//            echo $e->getTraceAsString();
//            die;

            $exceptionHandler = new Exception\Handler();

            if ($request->isXmlHttpRequest()) {
                $response = new JsonResponse();
                $response->setData(array('success'=>false, 'message'=>$e->getMessage()));
            } else {
                $response = new Response($exceptionHandler->getOutput($e), 500);
            }
        }

        if ($this->annotationReader->hasTarget()) {
            $responseAnnotation = $this->annotationReader->getAnnotation('Response');
        } else {
            $responseAnnotation = null;
        }

        // dispatch a response event
        $this->dispatcher->dispatch(
            KernelEvents::RESPONSE,
            new FilterResponseEvent($this, $request, $response, $responseAnnotation)
        );

        return $response;
    }
1146027
public function register(Application $app)
    {
        $this->loadProviders();

        foreach ($this->controllerProviders as $class => $values) {
            $app->register(new $class, $values);
        }
    }
52430
protected function registerMapperInitializer(Application $app)
    {
        $initializer = function ($mapper, $app) {
            $mapper->setSqlFactory(new SqlFactory);
        };

        $app->initializer('Synapse\Mapper\AbstractMapper', $initializer);
    }
146541
public static function start($app)
    	{
    		// Here, we will go ahead and "boot" the application for usage. This simply
    		// calls the boot method on all of the service providers so they get all
    		// their work done and are ready to handle interacting with dev input.
    		$app->boot();

    		$artisan = require __DIR__ . '/start.php';

    		$artisan->setAutoExit(false);

    		// If the event dispatcher is set on the application, we will fire an event
    		// with the Artisan instance to provide each listener the opportunity to
    		// register their commands on this application before it gets started.
    		if (isset($app['events'])) {
    			$app['events']->fire('artisan.start', array($artisan));
    		}

    		return $artisan;
    	}
940681
public function bootstrap(Container $app)
    {
        Facade::clearResolvedInstances();
        
        Facade::setFacadeApplication($app);
        
        AliasLoader::getInstance($app->make('config')->get('app.aliases'))->register();
        AliasLoader::getInstance($app->make('config')->get('app.theme.aliases', []))->register();
    }
937988
public function bootstrap(Application $app)
    {
        foreach ($app['config']->get('supports', []) as $feature => $value)
        {
            if ($value === 'automatic-feed-links')
            {
                add_theme_support($value);
            }
            else
            {
                add_theme_support($feature, $value);
            }
        }
    }
633287
public function boot(Application $app)
    {
        $paths = $app['lazy.thumbnail.mount_paths'];
        foreach ($paths as $route => $data) {
            $realRoute = isset($data['route']) ? $data['route'] : $route;
            $app->mount($realRoute, $this->connect($app, $realRoute, $data));
        }
    }
145991
public function bootstrap(Application $app)
    {
        if (app('antares.installed')) {
            //app('antares.license.response')->validate();
        }
        $this->setCurrentTheme($app);
        $this->setThemeResolver($app);
    }
210028
public function bootstrap(Application $app)
    {
        if ($app->configurationIsCached()) {
            return;
        }

        $this->checkForSpecificEnvironmentFile($app);

        try {
            $this->createDotenv($app)->safeLoad();
        } catch (InvalidFileException $e) {
            $this->writeErrorAndDie($e);
        }
    }
566339
public function boot(Application $app)
    {
        $this->app = $app;

        $this->config = $app->make('config');

        return $this;
    }
753478
protected function startConfigPlugin($app)
    {
        $this->getVariables['config'] = function () {
            return $this->app->make('config');
        };

        $this->requiresPlugins(Resources::class, Paths::class);
        $this->onRegister('config', function ($app) {
            $this->registerConfigFiles();
        });
        $this->onBoot('config', function ($app) {
            $this->bootConfigFiles();
        });
    }
1129225
public function boot(Application $app)
    {
        $app->error(
            function (\Exception $e, $code) use ($app) {
                if (true === $app['debug']) {
                    return null;
                }

                // 404.html.twig, or 40x.html, or 4xx.html.twig, or error.html
                $templates = array(
                    'error/' . $code . $app['kurl.error.template_suffix'],
                    'error/' . substr($code, 0, 2) . 'x' . $app['kurl.error.template_suffix'],
                    'error/' . substr($code, 0, 1) . 'xx' . $app['kurl.error.template_suffix'],
                    'error/default' . $app['kurl.error.template_suffix'],
                );

                return new Response(
                    $app['twig']->resolveTemplate($templates)->render(array('code' => $code, 'exception' => $e)),
                    $code
                );
            }
        );
    }
873198
public function register(Application $app)
    {
        $this->setup($app);
        $app
            ->offsetGet('console')
            ->getHelperSet()
            ->set(new ConnectionHelper($app->offsetGet('connection')), 'connection')
        ;
    }
692444
protected function startCommandsPlugin($app)
    {
        $this->onRegister('commands', function ($app) {
            /** @var \Illuminate\Foundation\Application $app */
            // Commands
            if ($app->runningInConsole()) {
                foreach ($this->findCommands as $path) {
                    $dir = path_get_directory((new ReflectionClass(get_called_class()))->getFileName());
                    $classes = $this->findCommandsIn(path_join($dir, $path), $this->findCommandsRecursive);

                    $this->commands = array_merge($this->commands, $classes);
                }
                if (is_array($this->commands) && count($this->commands) > 0) {
                    $commands = [];
                    foreach ($this->commands as $k => $v) {
                        if (is_string($k)) {
                            $app[ $this->commandPrefix.$k ] = $app->share(function ($app) use ($k, $v) {
                                return $app->build($v);
                            });

                            $commands[] = $this->commandPrefix.$k;
                        } else {
                            $commands[] = $v;
                        }
                    }
                    $this->commands($commands);
                }
            }
        });
    }
466791
public function register(Application $app)
    {
        $prefix = $this->prefix;

        foreach(array('.server', '.options', '.attributes') as $key) {
            if (!(isset($app[$prefix . $key]))) {
                $app[$prefix. $key] = array();
            }
        }

        $app[$prefix] = $this->getPdo($app, $prefix);
    }
977115
public function onConstruct($app)
    {
        //if not null
        if (!is_null($app)) {
            $key = $this->settingsKey;
            $this->$key = $app;
        }
    }