.
*/
use Monolog\Logger;
use Monolog\Processor\UidProcessor;
use Psr\Container\ContainerInterface;
use Xibo\Factory\ContainerFactory;
define('XIBO', true);
define('PROJECT_ROOT', realpath(__DIR__ . '/../..'));
require PROJECT_ROOT . '/vendor/autoload.php';
// Enable/Disable logging
if (\Xibo\Helper\Environment::isDevMode() || \Xibo\Helper\Environment::isForceDebugging()) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
} else {
error_reporting(0);
ini_set('display_errors', 0);
}
// Should we show the installer?
if (!file_exists(PROJECT_ROOT . '/web/settings.php')) {
die('Not configured');
}
// Check that the cache folder if writeable - if it isn't we're in big trouble
if (!is_writable(PROJECT_ROOT . '/cache')) {
die('Installation Error: Cannot write files into the Cache Folder');
}
// Create the container for dependency injection.
try {
$container = ContainerFactory::create();
} catch (Exception $e) {
die($e->getMessage());
}
// Configure Monolog
$container->set('logger', function (ContainerInterface $container) {
$logger = new Logger('PWA');
$logger->pushProcessor(new UidProcessor());
$logger->pushHandler(new \Xibo\Helper\DatabaseLogHandler());
return $logger;
});
// Create a Slim application
$app = \DI\Bridge\Slim\Bridge::create($container);
$app->setBasePath($container->get('basePath'));
// Config
$container->get('configService');
$container->set('name', 'PWA');
// Middleware
$app->add(new \Xibo\Middleware\ConnectorMiddleware($app));
$app->add(new \Xibo\Middleware\ListenersMiddleware($app));
$app->add(new \Xibo\Middleware\Log($app));
$app->add(new \Xibo\Middleware\State($app));
$app->add(new \Xibo\Middleware\Storage($app));
$app->add(new \Xibo\Middleware\Xmr($app));
$app->addRoutingMiddleware();
$app->add(new \Xibo\Middleware\TrailingSlashMiddleware($app));
//
// End Middleware
//
// Add Error Middleware
$errorMiddleware = $app->addErrorMiddleware(
\Xibo\Helper\Environment::isDevMode() || \Xibo\Helper\Environment::isForceDebugging(),
true,
true
);
$errorMiddleware->setDefaultErrorHandler(\Xibo\Middleware\Handlers::jsonErrorHandler($container));
// All application routes
$app->get('/getResource', ['\Xibo\Controller\Pwa', 'getResource'])->setName('pwa.getResource');
$app->get('/getData', ['\Xibo\Controller\Pwa', 'getData'])->setName('pwa.getData');
// Run App
try {
$app->run();
} catch (Exception $e) {
echo 'Fatal Error - sorry this shouldn\'t happen. ';
echo '
' . $e->getMessage();
// Only output debug trace if we're configured to display errors
if (ini_get('display_errors') == 1) {
echo '
' . nl2br($e->getTraceAsString()) . '';
}
}