Fix session generation issue on internal API calls, and migrate the environment
flag to be a defined boolean instead of string comparison for less error-prone-ness.
This commit is contained in:
parent
a46ad3c46d
commit
a9415fb9bb
|
@ -37,6 +37,7 @@ if (file_exists(APP_INCLUDE_BASE.'/env.ini')) {
|
|||
|
||||
// Application environment.
|
||||
define('APP_APPLICATION_ENV', $_ENV['application_env'] ?? 'development');
|
||||
define('APP_IN_PRODUCTION', APP_APPLICATION_ENV === 'production');
|
||||
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
|
||||
$_SERVER['HTTPS'] = (strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https');
|
||||
|
@ -52,7 +53,7 @@ $app_settings = [
|
|||
'addContentLengthHeader' => false,
|
||||
];
|
||||
|
||||
if (APP_APPLICATION_ENV !== 'development') {
|
||||
if (APP_IN_PRODUCTION) {
|
||||
$app_settings['routerCacheFile'] = APP_INCLUDE_TEMP . '/app_routes.cache.php';
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ return function (\Slim\Container $di, \App\Config $config) {
|
|||
$di['em'] = function ($di) {
|
||||
try {
|
||||
$options = [
|
||||
'autoGenerateProxies' => (APP_APPLICATION_ENV == "development"),
|
||||
'autoGenerateProxies' => !APP_IN_PRODUCTION,
|
||||
'proxyNamespace' => 'Proxy',
|
||||
'proxyPath' => APP_INCLUDE_TEMP . '/proxies',
|
||||
'modelPath' => APP_INCLUDE_BASE . '/models',
|
||||
|
|
|
@ -16,8 +16,8 @@ $config = [
|
|||
'static_uri' => '/static/',
|
||||
|
||||
'phpSettings' => [
|
||||
'display_startup_errors' => 0,
|
||||
'display_errors' => 0,
|
||||
'display_startup_errors' => !APP_IN_PRODUCTION ? 1 : 0,
|
||||
'display_errors' => !APP_IN_PRODUCTION ? 1 : 0,
|
||||
'log_errors' => 1,
|
||||
'error_log' => APP_INCLUDE_TEMP . '/php_errors.log',
|
||||
'error_reporting' => E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT,
|
||||
|
@ -62,20 +62,6 @@ $config = [
|
|||
'dark' => 'Dark',
|
||||
],
|
||||
],
|
||||
|
||||
/* RESOURCES: Doctrine ORM Layer */
|
||||
];
|
||||
|
||||
/**
|
||||
* Development mode changes.
|
||||
*/
|
||||
|
||||
if (APP_APPLICATION_ENV != 'production') {
|
||||
$config['phpSettings']['display_startup_errors'] = 1;
|
||||
$config['phpSettings']['display_errors'] = 1;
|
||||
|
||||
// Update if your local configuration differs.
|
||||
$config['base_url'] = '//localhost:8080';
|
||||
}
|
||||
|
||||
return $config;
|
||||
|
|
|
@ -17,6 +17,8 @@ class BaseController extends \AzuraCast\Mvc\Controller
|
|||
parent::preDispatch();
|
||||
|
||||
// Disable session creation.
|
||||
|
||||
/** @var \App\Session $session */
|
||||
$session = $this->di->get('session');
|
||||
|
||||
if (!$session->exists()) {
|
||||
|
|
|
@ -10,6 +10,8 @@ class InternalController extends BaseController
|
|||
|
||||
public function preDispatch()
|
||||
{
|
||||
parent::preDispatch();
|
||||
|
||||
$station_id = (int)$this->getParam('station');
|
||||
$station = $this->em->getRepository(Entity\Station::class)->find($station_id);
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ class Cache
|
|||
$item = $this->_cache->getItem($id);
|
||||
|
||||
$item->lock();
|
||||
|
||||
$item->set($data);
|
||||
$item->expiresAfter($specificLifetime);
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class Messenger
|
|||
$mail_config = $config->application->mail->toArray();
|
||||
|
||||
// Do not deliver mail on development environments.
|
||||
if (APP_APPLICATION_ENV == "development" && !defined('APP_FORCE_EMAIL')) {
|
||||
if (!APP_IN_PRODUCTION && !defined('APP_FORCE_EMAIL')) {
|
||||
$email_to = $mail_config['from_addr'];
|
||||
if (!empty($email_to)) {
|
||||
$options['to'] = $email_to;
|
||||
|
|
|
@ -429,7 +429,7 @@ class Controller
|
|||
*/
|
||||
protected function forceSecure()
|
||||
{
|
||||
if (APP_APPLICATION_ENV == 'production' && !APP_IS_SECURE) {
|
||||
if (APP_IN_PRODUCTION && !APP_IS_SECURE) {
|
||||
$this->doNotRender();
|
||||
|
||||
$url = 'https://' . $this->request->getHttpHost() . $this->request->getUri();
|
||||
|
|
|
@ -52,7 +52,7 @@ class ErrorHandler
|
|||
}
|
||||
}
|
||||
|
||||
if (APP_APPLICATION_ENV != 'production') {
|
||||
if (!APP_IN_PRODUCTION) {
|
||||
$show_debug = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,10 +52,12 @@ class Session
|
|||
|
||||
if (!isset($this->_sessions[$session_name])) {
|
||||
if (self::isActive()) {
|
||||
$this->_sessions[$session_name] = new \App\Session\Instance($this, $session_name);
|
||||
$session_instance = new \App\Session\Instance($this, $session_name);
|
||||
} else {
|
||||
$this->_sessions[$session_name] = new \App\Session\Temporary($this, $session_name);
|
||||
$session_instance = new \App\Session\Temporary($this, $session_name);
|
||||
}
|
||||
|
||||
$this->_sessions[$session_name] = $session_instance;
|
||||
}
|
||||
|
||||
return $this->_sessions[$session_name];
|
||||
|
|
|
@ -55,7 +55,7 @@ abstract class FrontendAbstract extends \AzuraCast\Radio\AdapterAbstract
|
|||
$use_radio_proxy = $settings_repo->getSetting('use_radio_proxy', 0);
|
||||
|
||||
// Web proxy support.
|
||||
if ((APP_APPLICATION_ENV == 'development' && !APP_INSIDE_DOCKER) || $use_radio_proxy) {
|
||||
if ((!APP_IN_PRODUCTION && !APP_INSIDE_DOCKER) || $use_radio_proxy) {
|
||||
return ((APP_IS_SECURE) ? 'https' : 'http') . '://' . $base_url . '/radio/' . $radio_port;
|
||||
} else {
|
||||
return 'http://' . $base_url . ':' . $radio_port;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
else
|
||||
$page_title = $config->application->name;
|
||||
|
||||
if (APP_APPLICATION_ENV != "production")
|
||||
if (!APP_IN_PRODUCTION)
|
||||
$page_title = '('.ucfirst(APP_APPLICATION_ENV).') '.$page_title;
|
||||
?>
|
||||
<title><?=$page_title ?></title>
|
||||
|
@ -40,7 +40,7 @@
|
|||
<script type="text/javascript" src="<?=$url->content('vendors/bower_components/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var APP_AppEnv = '<?=(defined('APP_APPLICATION_ENV') ? APP_APPLICATION_ENV : '') ?>';
|
||||
var APP_AppEnv = '<?=APP_APPLICATION_ENV ?>';
|
||||
var APP_BaseUrl = '<?=$url->named('home') ?>';
|
||||
var APP_ContentPath = '<?=$url->content('') ?>';
|
||||
</script>
|
||||
|
|
|
@ -23,7 +23,7 @@ if ($title)
|
|||
else
|
||||
$page_title = $config->application->name;
|
||||
|
||||
if (APP_APPLICATION_ENV != "production")
|
||||
if (!APP_IN_PRODUCTION)
|
||||
$page_title = '('.ucfirst(APP_APPLICATION_ENV).') '.$page_title;
|
||||
?>
|
||||
<title><?=$page_title ?></title>
|
||||
|
@ -43,10 +43,10 @@ if (APP_APPLICATION_ENV != "production")
|
|||
<script type="text/javascript" src="<?=$url->content('vendors/bower_components/jquery/dist/jquery.min.js') ?>"></script>
|
||||
<script type="text/javascript" src="<?=$url->content('vendors/bower_components/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
|
||||
<script type="text/javascript"
|
||||
src="<?= $url->content('vendors/bower_components/vue/dist/' . (APP_APPLICATION_ENV == 'development' ? 'vue.js' : 'vue.min.js')) ?>"></script>
|
||||
src="<?= $url->content('vendors/bower_components/vue/dist/' . (APP_IN_PRODUCTION ? 'vue.min.js' : 'vue.js')) ?>"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var APP_AppEnv = '<?=(defined('APP_APPLICATION_ENV') ? APP_APPLICATION_ENV : '') ?>';
|
||||
var APP_AppEnv = '<?=APP_APPLICATION_ENV ?>';
|
||||
var APP_BaseUrl = '<?=$url->named('home') ?>';
|
||||
var APP_ContentPath = '<?=$url->content('') ?>';
|
||||
</script>
|
||||
|
|
|
@ -23,7 +23,7 @@ if ($title)
|
|||
else
|
||||
$page_title = $config->application->name;
|
||||
|
||||
if (APP_APPLICATION_ENV != "production")
|
||||
if (!APP_IN_PRODUCTION)
|
||||
$page_title = '('.ucfirst(APP_APPLICATION_ENV).') '.$page_title;
|
||||
?>
|
||||
<title><?=$page_title ?></title>
|
||||
|
@ -40,7 +40,7 @@ if (APP_APPLICATION_ENV != "production")
|
|||
<script type="text/javascript" src="<?=$url->content('vendors/bower_components/bootstrap/dist/js/bootstrap.min.js') ?>"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var APP_AppEnv = '<?=(defined('APP_APPLICATION_ENV') ? APP_APPLICATION_ENV : '') ?>';
|
||||
var APP_AppEnv = '<?=APP_APPLICATION_ENV ?>';
|
||||
var APP_BaseUrl = '<?=$url->named('home') ?>';
|
||||
var APP_ContentPath = '<?=$url->content('') ?>';
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue