2018-11-12 16:59:15 +00:00
|
|
|
<?php
|
|
|
|
namespace App;
|
|
|
|
|
2019-08-09 15:00:21 +00:00
|
|
|
use App\Http\Response;
|
|
|
|
use App\Http\ServerRequest;
|
|
|
|
use Azura\App;
|
2018-11-12 16:59:15 +00:00
|
|
|
use Azura\Exception;
|
2019-08-09 15:00:21 +00:00
|
|
|
use Azura\Http\Factory\ResponseFactory;
|
|
|
|
use Azura\Http\Factory\ServerRequestFactory;
|
2019-08-07 04:33:55 +00:00
|
|
|
use Azura\Settings;
|
2019-09-10 02:30:05 +00:00
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry;
|
2018-11-12 16:59:15 +00:00
|
|
|
|
2019-08-09 15:00:21 +00:00
|
|
|
class AppFactory extends \Azura\AppFactory
|
2018-11-12 16:59:15 +00:00
|
|
|
{
|
2019-08-07 04:33:55 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2019-08-09 15:00:21 +00:00
|
|
|
public static function create($autoloader = null, $settings = [], $diDefinitions = []): App
|
2018-11-12 16:59:15 +00:00
|
|
|
{
|
2019-09-10 02:30:05 +00:00
|
|
|
// Register Annotation autoloader
|
|
|
|
if (null !== $autoloader) {
|
|
|
|
AnnotationRegistry::registerLoader([$autoloader, 'loadClass']);
|
2018-11-12 16:59:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 02:30:05 +00:00
|
|
|
$settings = self::buildSettings($settings);
|
2018-11-12 16:59:15 +00:00
|
|
|
|
2019-09-10 02:30:05 +00:00
|
|
|
self::applyPhpSettings($settings);
|
2018-12-22 17:27:41 +00:00
|
|
|
|
2019-08-07 04:33:55 +00:00
|
|
|
if ($autoloader) {
|
2018-11-12 16:59:15 +00:00
|
|
|
$plugins = new Plugins($settings[Settings::BASE_DIR] . '/plugins');
|
2019-08-07 04:33:55 +00:00
|
|
|
$plugins->registerAutoloaders($autoloader);
|
2018-11-12 16:59:15 +00:00
|
|
|
|
2019-08-07 04:33:55 +00:00
|
|
|
$diDefinitions[Plugins::class] = $plugins;
|
|
|
|
$diDefinitions = $plugins->registerServices($diDefinitions);
|
2018-11-12 16:59:15 +00:00
|
|
|
} else {
|
|
|
|
$plugins = null;
|
|
|
|
}
|
|
|
|
|
2019-09-10 02:30:05 +00:00
|
|
|
$di = self::buildContainer($settings, $diDefinitions);
|
|
|
|
|
2019-08-09 15:00:21 +00:00
|
|
|
// Set Response/Request decoratorclasses.
|
|
|
|
ServerRequestFactory::setServerRequestClass(ServerRequest::class);
|
|
|
|
ResponseFactory::setResponseClass(Response::class);
|
|
|
|
|
2019-09-10 02:30:05 +00:00
|
|
|
$app = self::createFromContainer($di);
|
|
|
|
$di->set(App::class, $app);
|
|
|
|
$di->set(\Slim\App::class, $app);
|
|
|
|
|
|
|
|
self::updateRouteHandling($app);
|
|
|
|
self::buildRoutes($app);
|
2018-11-12 16:59:15 +00:00
|
|
|
|
2019-08-07 04:33:55 +00:00
|
|
|
$settings = $di->get(Settings::class);
|
2018-11-12 16:59:15 +00:00
|
|
|
|
|
|
|
define('APP_APPLICATION_ENV', $settings[Settings::APP_ENV]);
|
|
|
|
define('APP_IN_PRODUCTION', $settings->isProduction());
|
|
|
|
|
|
|
|
return $app;
|
|
|
|
}
|
2019-09-10 02:30:05 +00:00
|
|
|
|
|
|
|
protected static function buildSettings($settings): Settings
|
|
|
|
{
|
|
|
|
if (!isset($settings[Settings::BASE_DIR])) {
|
2019-09-10 23:42:47 +00:00
|
|
|
throw new Exception\BootstrapException('No base directory specified!');
|
2019-09-10 02:30:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$settings[Settings::TEMP_DIR] = dirname($settings[Settings::BASE_DIR]) . '/www_tmp';
|
|
|
|
|
|
|
|
// Define the "helper" constants used by AzuraCast.
|
|
|
|
define('APP_IS_COMMAND_LINE', PHP_SAPI === 'cli');
|
|
|
|
|
|
|
|
define('APP_INCLUDE_ROOT', $settings[Settings::BASE_DIR]);
|
|
|
|
define('APP_INCLUDE_TEMP', $settings[Settings::TEMP_DIR]);
|
|
|
|
|
|
|
|
define('APP_INSIDE_DOCKER', file_exists(dirname($settings[Settings::BASE_DIR]) . '/.docker'));
|
|
|
|
define('APP_DOCKER_REVISION', getenv('AZURACAST_DC_REVISION') ?? 1);
|
|
|
|
|
|
|
|
$settings[Settings::IS_DOCKER] = APP_INSIDE_DOCKER;
|
|
|
|
|
|
|
|
define('APP_TESTING_MODE',
|
|
|
|
(isset($settings[Settings::APP_ENV]) && Settings::ENV_TESTING === $settings[Settings::APP_ENV]));
|
|
|
|
|
|
|
|
// Constants used in annotations
|
|
|
|
define('SAMPLE_TIMESTAMP', rand(time() - 86400, time() + 86400));
|
|
|
|
|
|
|
|
return parent::buildSettings($settings);
|
|
|
|
}
|
2018-11-12 16:59:15 +00:00
|
|
|
}
|