Update descartes framework to improve env.php constants handling

This commit is contained in:
osaajani 2024-02-25 11:04:45 +01:00
parent cf4dd2f075
commit 6321899e02
7 changed files with 48 additions and 40 deletions

View File

@ -1 +1 @@
v3.8.3 v3.8.4

View File

@ -91,21 +91,21 @@
/** /**
* Cette fonction permet de faire un retour sous forme de json * Cette fonction permet de faire un retour sous forme de json
* @param array $data : Les données à retourner sous forme de json * @param array $datas : Les données à retourner sous forme de json
* @param boolean $secure : Défini si l'affichage doit être sécurisé contre les XSS, par défaut true * @param boolean $secure : Défini si l'affichage doit être sécurisé contre les XSS, par défaut true
* @return ApiController : On retourne l'API controlleur lui meme pour pouvoir chainer * @return ApiController : On retourne l'API controlleur lui meme pour pouvoir chainer
*/ */
public function json ($data, $secure = true) public function json ($datas, $secure = true)
{ {
header('Content-Type: application/json'); header('Content-Type: application/json');
if ($secure) if ($secure)
{ {
echo htmlspecialchars(json_encode($data), ENT_NOQUOTES); echo htmlspecialchars(json_encode($datas), ENT_NOQUOTES);
} }
else else
{ {
echo json_encode($data); echo json_encode($datas);
} }
return $this; return $this;

View File

@ -24,7 +24,7 @@
if (!is_readable($template_path)) if (!is_readable($template_path))
{ {
throw new DescartesTemplateNotReadableException('Template ' . $template_path . ' is not readable.'); throw new exceptions\DescartesExceptionTemplateNotReadable('Template ' . $template_path . ' is not readable.');
} }
require $template_path; require $template_path;

View File

@ -72,6 +72,10 @@
protected static function clean_url (string $url) protected static function clean_url (string $url)
{ {
$to_remove = parse_url(HTTP_PWD, PHP_URL_PATH); $to_remove = parse_url(HTTP_PWD, PHP_URL_PATH);
if ($to_remove === null)
{
return $url;
}
$url = mb_strcut($url, mb_strlen($to_remove)); $url = mb_strcut($url, mb_strlen($to_remove));
$url = parse_url($url, PHP_URL_PATH); $url = parse_url($url, PHP_URL_PATH);

View File

@ -4,7 +4,7 @@
/* /*
* Define Descartes env * Define Descartes env
*/ */
$http_dir_path = '/raspisms'; //Path we need to put after servername in url to access app $http_dir_path = ''; //Path we need to put after servername in url to access app
$https = $_SERVER['HTTPS'] ?? 0; $https = $_SERVER['HTTPS'] ?? 0;
// Check for proxy forward // Check for proxy forward
@ -27,10 +27,9 @@
$port = $proxy ? '' : $port; $port = $proxy ? '' : $port;
$http_server_port = $port ? ':' . $port : ''; $http_server_port = $port ? ':' . $port : '';
$pwd = substr(__DIR__, 0, strrpos(__DIR__, '/')); $pwd = substr(__DIR__, 0, strrpos(__DIR__, '/'));
$http_pwd = $http_protocol . $http_server_name . $http_server_port . $http_dir_path;
$env = [ $env = [
//Global http and file path //Global http and file path
@ -39,31 +38,25 @@
'HTTP_SERVER_NAME' => $http_server_name, 'HTTP_SERVER_NAME' => $http_server_name,
'HTTP_SERVER_PORT' => $http_server_port, 'HTTP_SERVER_PORT' => $http_server_port,
'PWD' => $pwd, 'PWD' => $pwd,
'HTTP_PWD' => $http_pwd,
//path of back resources //path of back resources
'PWD_CONTROLLER' => $pwd . '/controllers', //Controllers dir 'PWD_CONTROLLER' => $pwd . '/controllers', //Controllers dir
'PWD_MODEL' => $pwd . '/models', //Models dir 'PWD_MODEL' => $pwd . '/models', //Models dir
'PWD_TEMPLATES' => $pwd . '/templates', //Templates dir 'PWD_TEMPLATES' => $pwd . '/templates', //Templates dir
//path of front resources //path of front resources
'PWD_ASSETS' => $pwd . '/assets', //Assets dir 'PWD_ASSETS' => $pwd . '/assets', //Assets dir
'HTTP_PWD_ASSETS' => $http_pwd . '/assets', //HTTP path of asset dir
//images //images
'PWD_IMG' => $pwd . '/assets' . '/img', 'PWD_IMG' => $pwd . '/assets' . '/img',
'HTTP_PWD_IMG' => $http_pwd . '/assets' . '/img',
//css //css
'PWD_CSS' => $pwd . '/assets' . '/css', 'PWD_CSS' => $pwd . '/assets' . '/css',
'HTTP_PWD_CSS' => $http_pwd . '/assets' . '/css',
//javascript //javascript
'PWD_JS' => $pwd . '/assets' . '/js', 'PWD_JS' => $pwd . '/assets' . '/js',
'HTTP_PWD_JS' => $http_pwd . '/assets' . '/js',
//fonts //fonts
'PWD_FONT' => $pwd . '/assets' . '/font', 'PWD_FONT' => $pwd . '/assets' . '/font',
'HTTP_PWD_FONT' => $http_pwd . '/assets' . '/font',
]; ];

View File

@ -21,6 +21,7 @@
$environment = []; $environment = [];
$env = []; $env = [];
// Load descartes base env
require_once(__DIR__ . '/env.php'); require_once(__DIR__ . '/env.php');
$environment = array_merge($environment, $env); $environment = array_merge($environment, $env);
@ -31,11 +32,8 @@
$environment = array_merge($environment, $env); $environment = array_merge($environment, $env);
} }
//Define all Descartes constants
define_array($environment);
### GLOBAL ENV ### ### GLOBAL ENV ###
$environment = []; //Load global app env
$env = []; $env = [];
if (file_exists(__DIR__ . '/../env.php')) if (file_exists(__DIR__ . '/../env.php'))
{ {
@ -43,19 +41,30 @@
$environment = array_merge($environment, $env); $environment = array_merge($environment, $env);
} }
define_array($environment);
### SPECIFIC ENV ### ### SPECIFIC ENV ###
$environment = []; // Load specific environment env
$env = []; $env = [];
if (isset($environment['ENV']) && file_exists(__DIR__ . '/../env.' . $environment['ENV'] . '.php'))
if (defined('ENV') && file_exists(__DIR__ . '/../env.' . ENV . '.php'))
{ {
require_once(__DIR__ . '/../env.' . ENV . '.php'); require_once(__DIR__ . '/../env.' . $environment['ENV'] . '.php');
$environment = array_merge($environment, $env); $environment = array_merge($environment, $env);
} }
### BUILD HTTP PWD CONSTS ###
// We compute http pwd at last minute to allow for simple overriding by user
// by simply defining custom HTTP_* (PROTOCOL, SERVER_NAME, SERVER_PORT, DIR_PATH)
$http_pwd = $environment['HTTP_PROTOCOL'] . $environment['HTTP_SERVER_NAME'] . $environment['HTTP_SERVER_PORT'] . $environment['HTTP_DIR_PATH'];
$env = [
"HTTP_PWD" => $http_pwd,
'HTTP_PWD_ASSETS' => $http_pwd . '/assets', //HTTP path of asset dir
'HTTP_PWD_IMG' => $http_pwd . '/assets' . '/img',
'HTTP_PWD_CSS' => $http_pwd . '/assets' . '/css',
'HTTP_PWD_JS' => $http_pwd . '/assets' . '/js',
'HTTP_PWD_FONT' => $http_pwd . '/assets' . '/font',
];
$environment = array_merge($environment, $env);
define_array($environment); define_array($environment);
} }

View File

@ -2,23 +2,25 @@
/* /*
This file define constants and options for the app This file define constants and options for the app
*/ */
$dir_path = '/raspisms';
$http_pwd = $environment['HTTP_PROTOCOL'] . $dir_path . $environment['HTTP_SERVER_PORT'] . $environment['HTTP_DIR_PATH'];
$env = [ $env = [
'ENV' => '%APP_ENV%', #env name (probably 'dev' or 'prod'), this value is used to get the env.XXX.php.dist matching env file 'ENV' => '%APP_ENV%', #env name (probably 'dev' or 'prod'), this value is used to get the env.XXX.php.dist matching env file
'SESSION_NAME' => 'raspisms', 'SESSION_NAME' => 'raspisms',
'HTTP_DIR_PATH' => $dir_path, // Override default dir path
//RaspiSMS settings //RaspiSMS settings
'WEBSITE_TITLE' => 'RaspiSMS', 'WEBSITE_TITLE' => 'RaspiSMS',
'WEBSITE_DESCRIPTION' => '', 'WEBSITE_DESCRIPTION' => '',
'WEBSITE_AUTHOR' => 'Raspberry Pi FR', 'WEBSITE_AUTHOR' => 'Raspberry Pi FR',
'PWD_SCRIPTS' => PWD . '/scripts', 'PWD_SCRIPTS' => $environment['PWD'] . '/scripts',
'PWD_RECEIVEDS' => PWD . '/receiveds', 'PWD_RECEIVEDS' => $environment['PWD'] . '/receiveds',
'HTTP_PWD_SOUND' => HTTP_PWD_ASSETS . '/sounds', 'HTTP_PWD_SOUND' => $http_pwd . '/assets' . '/sounds',
'PWD_ADAPTERS' => PWD . '/adapters', 'PWD_ADAPTERS' => $environment['PWD'] . '/adapters',
'PWD_DATA' => PWD . '/data', 'PWD_DATA' => $environment['PWD'] . '/data',
'HTTP_PWD_DATA' => HTTP_PWD . '/data', 'HTTP_PWD_DATA' => $http_pwd . '/data',
'PWD_DATA_PUBLIC' => PWD . '/data/public', 'PWD_DATA_PUBLIC' => $environment['PWD'] . '/data/public',
'HTTP_PWD_DATA_PUBLIC' => HTTP_PWD . '/data/public', 'HTTP_PWD_DATA_PUBLIC' => $http_pwd . '/data/public',
'PWD_LOGS' => '/var/log/raspisms', 'PWD_LOGS' => '/var/log/raspisms',
'PWD_PID' => '/var/run/raspisms', 'PWD_PID' => '/var/run/raspisms',
'APP_SECRET' => '%APP_SECRET%', 'APP_SECRET' => '%APP_SECRET%',