public static function setupConfig(Application $app) { $loader = new YamlLoader(); $schema = new MetaYaml($loader->loadFromFile(__DIR__ . '/config_schema.yml')); $schema->validate($config = $loader->loadFromFile(__DIR__ . '/../config/config.yml')); foreach ($config as $key => $value) { $app->setConfig($key, $value); } if (array_key_exists('SCRIPT_NAME', $_SERVER) && is_string($_SERVER['SCRIPT_NAME']) && !empty($_SERVER['SCRIPT_NAME'])) { $dir = dirname($_SERVER['SCRIPT_NAME']); } else { $dir = '/'; } $app->setConfig('dir', $dir); }
/** * Tail -f for stdout or stderr for a process. * * @param Response $response * @param Supervisor $instance * @param string $process * @param string $type * * @throws Exception */ private function getLog($response, $instance, $process, $type = 'Stdout') { $template = $this->app['twig']->loadTemplate(sprintf('layout/tail.twig')); $response->setContent($template->render(['doNotClose' => true, 'baseUrl' => $this->app->getConfig('dir', '/')]))->sendContent(); //flush template to browser. Tmeplate is setup to use bigpipe so the connection doesn't close. ob_flush(); flush(); if ($type != 'Stdout' && $type != 'Stderr') { throw new Exception('Log type not supported'); } $offset = -4096; while (true) { // Check if client is still connected. if (connection_aborted()) { return; } usleep(300000); //0.3 s //Get log until no more from last offset. $bufferOverFlow = true; while ($bufferOverFlow) { list($string, $newoffset, $bufferOverFlow) = $instance->{'tailProcess' . $type . 'Log'}($process, $offset, 4096); if (strlen($string) > 0) { if ($offset > 0) { $template = $this->app['twig']->loadTemplate(sprintf('layout/tailContent.twig')); // Set content with <br/> for new lines and only send in offset difference. // This is becuase tailProcessStdoutLog returns 4096 no matter what the offset is. $twigVariables = ['string' => nl2br(substr($string, $offset - $newoffset))]; $response->setContent($template->render($twigVariables))->sendContent(); } else { $template = $this->app['twig']->loadTemplate(sprintf('layout/tailContent.twig')); $twigVariables = ['string' => nl2br($string)]; $response->setContent($template->render($twigVariables))->sendContent(); } // Flush to browser. ob_flush(); flush(); } $offset = $newoffset; } } }
/** * Bootstraps the application * * @param Application $app * * @return Application */ public function load(Application $app) { $app->get('/', 'Indigo\\Service\\Controller\\MainController::index'); $app->get('/services', 'Indigo\\Service\\Controller\\ServiceController::listAction'); $app->get('/services/create', 'Indigo\\Service\\Controller\\ServiceController::createAction'); $app->post('/services', 'Indigo\\Service\\Controller\\ServiceController::create'); $app->get('/services/{id}', 'Indigo\\Service\\Controller\\ServiceController::read'); $app->post('/services/{id}/comment', 'Indigo\\Service\\Controller\\ServiceController::createComment'); $app->get('/services/{id}/edit', 'Indigo\\Service\\Controller\\ServiceController::updateAction'); $app->post('/services/{id}', 'Indigo\\Service\\Controller\\ServiceController::update'); $app->delete('/services/{id}', 'Indigo\\Service\\Controller\\ServiceController::delete'); $app->get('/services/print/{id}', 'Indigo\\Service\\Controller\\ServiceController::pdf'); $app->get('/login', 'Indigo\\Service\\Controller\\AuthController::login'); $app->post('/login', 'Indigo\\Service\\Controller\\AuthController::processLogin'); $baseUriListener = new BaseUri(); $baseUriListener->setApplication($app); $app->subscribe('request.received', $baseUriListener); return $app; }
public function testRun() { $app = new Application(); $app->get('/', function ($request, $response) { $response->setContent('<h1>It works!</h1>'); return $response; }); $app->subscribe('request.received', function ($event, $request) { $this->assertInstanceOf('League\\Event\\Event', $event); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Request', $request); }); $app->subscribe('response.sent', function ($event, $request, $response) { $this->assertInstanceOf('League\\Event\\Event', $event); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Request', $request); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response); }); ob_start(); $app->run(); ob_get_clean(); }
} /** * Checking environment * * The environment is already loaded, now it should be checked */ $dotenv->required(['APP_ROOT', 'APP_CONFIG', 'WKHTMLTOPDF']); /** * Setting up dependency container */ $diConfig = (require __DIR__ . '/di.php'); $container = new Container($diConfig); /** * Instantiating the application */ $app = new Application(); $app->setContainer($container); $app['env'] = $dotenv; /** * Loading configuration */ if (is_file($configFile = getenv('APP_CONFIG'))) { foreach (Yaml::parse($configFile) as $config => $value) { $app->setConfig($config, $value); } } // The application path is protected from being overwritten // Should be placed after configuration loading $app->setConfig('path', __DIR__); // Set locale based on environment setlocale(LC_ALL, getenv('LANG'));
public function testGetNamedInstance() { $s = new Application(); $s->setName('foo'); $this->assertSame($s, Application::getInstance('foo')); }
<?php /* * This file is part of the Supervisor Monitor project. * * (c) Márk Sági-Kazár <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require __DIR__ . '/../vendor/autoload.php'; use League\Container\Container; use Proton\Application; $bootstrap = (require __DIR__ . '/../app/bootstrap.php'); $container = new Container($bootstrap); $app = new Application(); $app->setContainer($container); require __DIR__ . '/../app/config.php'; config::setupConfig($app); $app->get('/', 'controller::index'); // Global actions $app->get('/start', 'controller::startAllServers'); $app->get('/restart', 'controller::restartAllServers'); $app->get('/stop', 'controller::stopAllServers'); $app->get('/clearAllProcessLogs', 'controller::clearAllProcessLogs'); // Instance actions $app->get('/start/{instance}', 'controller::startAll'); $app->get('/restart/{instance}', 'controller::restartAll'); $app->get('/stop/{instance}', 'controller::stopAll'); $app->get('/clearAllProcessLogs/{instance}', 'controller::clearAllProcessLogsInstance'); // Process actions