WEBD-325-45/week-03/project/includes/app.php

95 lines
3.5 KiB
PHP
Raw Normal View History

<?php
/**
2022-04-12 19:41:51 +00:00
* @package Octoleo CMS
*
2022-04-12 19:41:51 +00:00
* @created 9th April 2022
* @author Llewellyn van der Merwe <https://git.vdm.dev/Llewellyn>
* @git WEBD-325-45 <https://git.vdm.dev/Llewellyn/WEBD-325-45>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
2022-04-12 19:41:51 +00:00
defined('_LEXEC') or die;
2022-04-12 19:41:51 +00:00
// Option to override defines from root folder
// source: https://github.com/joomla/joomla-cms/blob/4.1-dev/includes/app.php#L15
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
include_once dirname(__DIR__) . '/defines.php';
}
2022-04-12 19:41:51 +00:00
// Load the default defines
// source: https://github.com/joomla/joomla-cms/blob/4.1-dev/includes/app.php#L20
if (!defined('_LDEFINES'))
{
2022-04-12 19:41:51 +00:00
define('LPATH_BASE', dirname(__DIR__));
require_once LPATH_BASE . '/includes/defines.php';
}
// Check for presence of vendor dependencies not included in the git repository
2022-04-12 19:41:51 +00:00
// source: https://github.com/joomla/joomla-cms/blob/4.1-dev/includes/app.php#L26
if (!file_exists(LPATH_LIBRARIES . '/vendor/autoload.php'))
{
2022-04-12 19:41:51 +00:00
echo file_get_contents(LPATH_ROOT . '/templates/system/build_incomplete.html');
exit;
}
2022-04-12 19:41:51 +00:00
// Load configuration (or install)
// source: https://github.com/joomla/joomla-cms/blob/4.1-dev/includes/app.php#L34
require_once LPATH_BASE . '/includes/framework.php';
2022-04-12 19:41:51 +00:00
// Wrap in a try/catch so we can display an error if need be
try
{
$container = (new Joomla\DI\Container)
->registerServiceProvider(new Octoleo\CMS\Service\SiteApplicationProvider)
->registerServiceProvider(new Octoleo\CMS\Service\ConfigurationProvider(LPATH_CONFIGURATION . '/octoconfig.php'))
->registerServiceProvider(new Joomla\Database\Service\DatabaseProvider)
->registerServiceProvider(new Octoleo\CMS\Service\EventProvider)
->registerServiceProvider(new Octoleo\CMS\Service\HttpProvider)
->registerServiceProvider(new Octoleo\CMS\Service\LoggingProvider)
->registerServiceProvider(new Joomla\Preload\Service\PreloadProvider)
->registerServiceProvider(new Octoleo\CMS\Service\TemplatingProvider);
2022-04-12 19:41:51 +00:00
// Alias the web application to Octoleo's base application class as this is the primary application for the environment
$container->alias(Joomla\Application\AbstractApplication::class, Joomla\Application\AbstractWebApplication::class);
2022-04-12 19:41:51 +00:00
// Alias the web logger to the PSR-3 interface as this is the primary logger for the environment
$container->alias(Monolog\Logger::class, 'monolog.logger.application.web')
->alias(Psr\Log\LoggerInterface::class, 'monolog.logger.application.web');
}
catch (\Throwable $e)
{
error_log($e);
header('HTTP/1.1 500 Internal Server Error', null, 500);
echo '<html><head><title>Container Initialization Error</title></head><body><h1>Container Initialization Error</h1><p>An error occurred while creating the DI container: ' . $e->getMessage() . '</p></body></html>';
2022-04-12 19:41:51 +00:00
exit(1);
}
2022-04-12 19:41:51 +00:00
// Execute the application
// source: https://github.com/joomla/framework.joomla.org/blob/master/www/index.php#L85
try
{
$app = $container->get(Joomla\Application\AbstractApplication::class);
// Set the application as global app
\Octoleo\CMS\Factory::$application = $app;
// Execute the application.
$app->execute();
}
catch (\Throwable $e)
{
error_log($e);
2022-04-12 19:41:51 +00:00
if (!headers_sent())
{
header('HTTP/1.1 500 Internal Server Error', null, 500);
header('Content-Type: text/html; charset=utf-8');
}
echo '<html><head><title>Application Error</title></head><body><h1>Application Error</h1><p>An error occurred while executing the application: ' . $e->getMessage() . '</p></body></html>';
exit(1);
}
// I am just playing around... ((ewɘ))yn purring