feat: replace exploded base_* with public_url
Fixes #1574 BREAKING CHANGE: The `general` section in the config schema has changed: the `general.base_*`, `general.protocol` and `general.force_ssl` configuration fields have been replaced with a single `general.public_url` field. Be sure to use a valid url with the new configuration field.
This commit is contained in:
parent
d020fbd983
commit
751d430bcc
13 changed files with 297 additions and 144 deletions
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use League\Uri\Uri;
|
||||
|
||||
class Application_Common_HTTPHelper
|
||||
{
|
||||
/**
|
||||
|
@ -30,11 +32,16 @@ class Application_Common_HTTPHelper
|
|||
public static function getStationUrl($secured = true)
|
||||
{
|
||||
$CC_CONFIG = Config::getConfig();
|
||||
$baseUrl = $CC_CONFIG['baseUrl'];
|
||||
$baseDir = $CC_CONFIG['baseDir'];
|
||||
$basePort = $CC_CONFIG['basePort'];
|
||||
$forceSSL = $CC_CONFIG['forceSSL'];
|
||||
$configProtocol = $CC_CONFIG['protocol'];
|
||||
|
||||
$url = Uri::createFromComponents(
|
||||
[
|
||||
'scheme' => $CC_CONFIG['protocol'],
|
||||
'host' => $CC_CONFIG['baseUrl'],
|
||||
'port' => $CC_CONFIG['basePort'],
|
||||
'path' => $CC_CONFIG['baseDir'],
|
||||
]
|
||||
);
|
||||
|
||||
if (empty($baseDir)) {
|
||||
$baseDir = '/';
|
||||
}
|
||||
|
@ -45,26 +52,7 @@ class Application_Common_HTTPHelper
|
|||
$baseDir = $baseDir . '/';
|
||||
}
|
||||
|
||||
// Set in reverse order of preference. ForceSSL configuration takes absolute preference, then
|
||||
// the protocol set in config. If neither are set, the port is used to determine the scheme
|
||||
$scheme = 'http';
|
||||
if ($secured && $basePort == '443') {
|
||||
$scheme = 'https';
|
||||
}
|
||||
if (!empty($configProtocol)) {
|
||||
$scheme = $configProtocol;
|
||||
}
|
||||
if ($forceSSL) {
|
||||
$scheme = 'https';
|
||||
}
|
||||
|
||||
$portStr = '';
|
||||
if (($scheme == 'http' && $basePort !== '80')
|
||||
|| ($scheme == 'https' && $basePort !== '443')) {
|
||||
$portStr = ":{$basePort}";
|
||||
}
|
||||
|
||||
return "{$scheme}://{$baseUrl}{$portStr}{$baseDir}";
|
||||
return rtrim($url, '/') . '/';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,7 +102,7 @@ class ZendActionHttpException extends Exception
|
|||
Exception $previous = null
|
||||
) {
|
||||
Logging::error('Error in action ' . $action->getRequest()->getActionName()
|
||||
. " with status code {$statusCode}: {$message}");
|
||||
. " with status code {$statusCode}: {$message}");
|
||||
$action->getResponse()
|
||||
->setHttpResponseCode($statusCode)
|
||||
->appendBody($message);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
// THIS FILE IS NOT MEANT FOR CUSTOMIZING.
|
||||
use League\Uri\Contracts\UriException;
|
||||
use League\Uri\Uri;
|
||||
|
||||
class Config
|
||||
{
|
||||
|
@ -17,12 +19,24 @@ class Config
|
|||
// //////////////////////////////////////////////////////////////////////////////
|
||||
$CC_CONFIG['apiKey'] = [$values['general']['api_key']];
|
||||
|
||||
// Base URL
|
||||
$CC_CONFIG['protocol'] = $values['general']['protocol'] ?? '';
|
||||
$CC_CONFIG['baseDir'] = $values['general']['base_dir'];
|
||||
$CC_CONFIG['baseUrl'] = $values['general']['base_url'];
|
||||
$CC_CONFIG['basePort'] = $values['general']['base_port'];
|
||||
$CC_CONFIG['forceSSL'] = Config::isYesValue($values['general']['force_ssl'] ?? false);
|
||||
// Explode public_url into multiple component with possible defaults for required fields
|
||||
try {
|
||||
$public_url = Uri::createFromString($values['general']['public_url']);
|
||||
} catch (UriException $e) {
|
||||
echo 'could not parse configuration field general.public_url: ' . $e->getMessage();
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$scheme = $public_url->getScheme() ?? 'http';
|
||||
$host = $public_url->getHost() ?? 'localhost';
|
||||
$port = $public_url->getPort() ?? ($scheme == 'https' ? 443 : 80);
|
||||
$path = rtrim($public_url->getPath() ?? '', '/') . '/'; // Path requires a trailing slash
|
||||
|
||||
$CC_CONFIG['protocol'] = $scheme;
|
||||
$CC_CONFIG['baseUrl'] = $host;
|
||||
$CC_CONFIG['basePort'] = $port;
|
||||
$CC_CONFIG['baseDir'] = $path;
|
||||
|
||||
$CC_CONFIG['dev_env'] = $values['general']['dev_env'] ?? 'production';
|
||||
$CC_CONFIG['auth'] = $values['general']['auth'] ?? 'local';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue