Connects the passed application to the system configuration.

@param \AppserverIo\Psr\Application\ApplicationInterface $application The application to be prepared

@return void
184048
public function addApplicationToSystemConfiguration(ApplicationInterface $application)
    {

        // try to load the API app service instance
        $appNode = $this->getService()->loadByWebappPath($application->getWebappPath());

        // check if the application has already been attached to the container
        if ($appNode == null) {
            $this->getService()->newFromApplication($application);
        }

        // connect the application to the container
        $application->connect();
    }
802221
public function register(Application $app)
    {
        /** @var Translator $translator  */
        $translator = $app['translator'];
        $translator->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages');

        /** @var ApplicationConfiguration $config */
        $config = $app['config'];

        $partialsCollection = new PartialsCollection($app['markdown']);
        $app['partials'] = $partialsCollection;

        /** @var Partial[] $partials */
        $partials = $config->getPartials();
        if ($partials) {
            foreach ($partials as $partial) {
                if (! $partial->getName()) {
                    throw new Exception\MissingNameForPartialException('The name of the partial to load is missing');
                }

                $content = '';
                if ($partial->getContent()) {
                    $content = $partial->getContent();
                } elseif ($partial->getLink()) {
                    if (! is_readable($partial->getLink())) {
                        $app['monolog']->error(
                            sprintf($translator->translate('PPCPP:EXC-NOPARTIAL'), $partial->getLink())
                        );
                        continue;
                    }

                    $content = file_get_contents($partial->getLink());
                }
                $partialsCollection->set($partial->getName(), $content);
            }
        }
    }
1209102
public function cleanUpFolders(ApplicationInterface $application)
    {

        // load the directories we want to clean-up on appserver restart
        $cleanUpFolders = array(new \SplFileInfo($application->getCacheDir()));

        // clean-up the directories
        foreach ($cleanUpFolders as $cleanUpFolder) {
            $this->cleanUpDir($cleanUpFolder);
        }
    }
1263276
public function handle(EventInterface $event)
    {

        try {
            // load the application server and the naming directory instance
            /** @var \AppserverIo\Psr\ApplicationServer\ApplicationServerInterface $applicationServer */
            $applicationServer = $this->getApplicationServer();
            /** @var \AppserverIo\Psr\Naming\NamingDirectoryInterface $namingDirectory */
            $namingDirectory = $applicationServer->getNamingDirectory();

            // initialize configuration and schema file name
            $configurationFileName = $applicationServer->getConfigurationFilename();

            // get an instance of our configuration tester
            $configurationService = new ConfigurationService(new InitialContext(new AppserverNode()));

            // load the parsed system configuration
            /** @var \DOMDocument $doc */
            $doc = $configurationService->loadConfigurationByFilename($configurationFileName);

            // validate the configuration file with the schema
            $configurationService->validateXml($doc, null, true);

            try {
                // query whether we're in configuration test mode or not
                if ($namingDirectory->search('php:env/args/t')) {
                    echo 'Syntax OK' . PHP_EOL;
                    exit(0);
                }

            } catch (NamingException $ne) {
                // do nothing, because we're NOT in configuration test mode
            }

            // initialize the SimpleXMLElement with the content XML configuration file
            $configuration = new Configuration();
            $configuration->initFromString($doc->saveXML());

            // initialize the configuration and the base directory
            $systemConfiguration = new AppserverNode();
            $systemConfiguration->initFromConfiguration($configuration);

            // re-initialize the container service with the real system configuration
            $configurationService->setSystemConfiguration($systemConfiguration);

            // then we can replace the system properties
            $properties = $configurationService->getSystemProperties();
            $systemConfiguration->replaceProperties($properties);

            // set the system configuration in the application server instance
            $applicationServer->setSystemConfiguration($systemConfiguration);

        } catch (\Exception $e) {
            // render the validation errors and exit immediately
            echo $e . PHP_EOL;
            exit(0);
        }
    }
205513
public function connect(Application $app)
    {
        /** @var ControllerCollection $controllers */
        $controllers = $app['controllers_factory'];
        $controllers->get('/', 'oauth.controller::signinRedirect');
        $controllers->get('/signin', 'oauth.controller::signinGet');
        $controllers->post('/signin', 'oauth.controller::signinPost');
        $controllers->post('/authorize', 'oauth.controller::authorize');
        $controllers->get('/access_token', 'oauth.controller::accessToken');
        $controllers->post('/access_token', 'oauth.controller::accessToken');
        $controllers->get('/token', 'oauth.controller::tokenInfo');

        return $controllers;
    }
386269
protected function setupMigrations(Application $app)
    {
        $source = realpath(__DIR__.'/../database/migrations/');

        if ($app instanceof LaravelApplication && $app->runningInConsole()) {
            $this->publishes([$source => database_path('migrations')], 'migrations');
        }
    }
687848
public function bootstrap(Application $app)
    {
        $items = [];

        $app->instance('config', $config = new Repository($items));

        $this->loadConfigurationFiles($app, $config);

        mb_internal_encoding('UTF-8');
    }
1035331
public static function run(Application $app)
    {
        $config = Config::getOrEmpty('application');
        $debug  = (bool)Arr::get($config, 'debug', false);
        define('DEBUG', $debug);

        self::setUpErrorHandling($debug);
        self::configure($config);
        self::bootstrap($config);
        self::initAPI($config, $app);

        Session::start();

        foreach (Arr::get($config, 'response.defaultHeaders', []) as $header) {
            header($header);
        }
    }
1317946
private function initializeConfig(Application $app)
    {
        $config_provider = $app->make('Concrete\Core\Config\ConfigServiceProvider');
        $config_provider->register();

        /*
         * @var \Concrete\Core\Config\Repository\Repository
         */
        $config = $app->make('config');

        return $config;
    }
713085
public function register(Application $app)
    {
        $this->config = $app['config']->load('log');

        $handlers = $this->getHandlers($app);
        $app['log'] = $app->share(function ($app) use ($handlers) {
            return new Logger('main', $handlers);
        });

        $app->initializer('Synapse\\Log\\LoggerAwareInterface', function ($object, $app) {
            $object->setLogger($app['log']);
            return $object;
        });
    }
570296
public function handle(EventInterface $event)
    {

        try {
            // load the application server instance
            /** @var \AppserverIo\Psr\ApplicationServer\ApplicationServerInterface $applicationServer */
            $applicationServer = $this->getApplicationServer();

            // unbind the loggers from the naming directory
            foreach (array_keys($applicationServer->getLoggers()) as $name) {
                $applicationServer->getNamingDirectory()->unbind(sprintf('php:global/log/%s', $name));
            }

            // set the initialized loggers finally
            $applicationServer->setLoggers(array());

        } catch (\Exception $e) {
            error_log($e->__toString());
        }
    }
529854
final protected function resolveApplicationBindings($app): void
    {
        foreach ($this->overrideApplicationBindings($app) as $original => $replacement) {
            $app->bind($original, $replacement);
        }
    }
146469
public function newFromApplication(ApplicationInterface $application)
    {
        // create a new AppNode and initialize it
        $appNode = new AppNode();
        $appNode->initFromApplication($application);
        $appNode->setParentUuid($this->getSystemConfiguration()->getUuid());

        // persist the AppNode instance
        $this->persist($appNode);
    }
223221
public function run(ApplicationInterface $app)
    {
        $config = $app->getConfig();
        
        $servicesFactory = $app->getServicesFactory();
        
        $this->injectInitialServices($app);
        
        foreach ($config->get(Service::class, []) as $serviceSpec) {
            $servicesFactory->registerService($serviceSpec);
        }
    }
8217
public function updateResponse(ApplicationInterface $application, RequestInterface $request, ResponseInterface $response): void
    {
        parent::updateResponse($application, $request, $response);

        $response->setHeader('Content-Type', 'application/json');
    }
447438
public function postStartup(ApplicationInterface $application)
    {

        // load the object manager
        /** @var \AppserverIo\Psr\Di\ObjectManagerInterface $objectManager */
        $objectManager = $application->search(ObjectManagerInterface::IDENTIFIER);

        // register the beans found by annotations and the XML configuration
        /** \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor */
        foreach ($objectManager->getObjectDescriptors() as $descriptor) {
            // if we found a singleton session bean with a startup callback instanciate it
            if ($descriptor instanceof SingletonSessionBeanDescriptorInterface && $descriptor->isInitOnStartup()) {
                $this->startupBeanTasks[] = new StartupBeanTask($application, $descriptor);
            }
        }
    }
1196246
public function registerBeans(ApplicationInterface $application)
    {

        // parse the object descriptors
        $this->parseObjectDescriptors();

        // load the object manager
        /** @var \AppserverIo\Psr\Di\ObjectManagerInterface $objectManager */
        $objectManager = $this->getApplication()->search(ObjectManagerInterface::IDENTIFIER);

        // register the beans found by annotations and the XML configuration
        /** \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor */
        foreach ($objectManager->getObjectDescriptors() as $descriptor) {
            // check if we've found a bean descriptor and register the bean
            if ($descriptor instanceof BeanDescriptorInterface) {
                $this->registerBean($descriptor);
            }
        }
    }