Skip to content

Commit

Permalink
add vendor configuration file (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuch committed Jan 25, 2025
1 parent 4c932e7 commit c876bc2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
2 changes: 0 additions & 2 deletions classes/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
*/
class Core
{
public const APP_VERSION = '2.2.1';

private const SESSION_NAME = 'session';

private $user = null;
Expand Down
2 changes: 1 addition & 1 deletion classes/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function get(): array
$res['authenticated'] = 'disabled';
}
$res['auth_type'] = $this->core->auth()->authenticationType();
$res['version'] = Core::APP_VERSION;
$res['version'] = APP_VERSION;
$res['php_version'] = phpversion();

return $res;
Expand Down
25 changes: 25 additions & 0 deletions config/vendor_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* File for vendor customization. You can change here paths or some behaviors,
* which vendors such as Linux distributions might want to change.
*
* For changing this file you should know what you are doing. For this reason
* the options given here are not part of the normal configuration.
*/

return [
/**
* Path to a vendor autoload file. Useful when you want to have vendor dependencies somewhere else.
*/
'autoload_file' => ROOT_PATH . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php',

/**
* Path to the configuration file.
*/
'config_file' => ROOT_PATH . 'config' . DIRECTORY_SEPARATOR . 'conf.php',

/**
* Suffix to add to the DmarcSrg version
*/
'version_suffix' => ''
];
24 changes: 19 additions & 5 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,33 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

$va = __DIR__ . '/vendor/autoload.php';
if (!defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . (__DIR__ === DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR));
}

$vc = require_once(ROOT_PATH . 'config' . DIRECTORY_SEPARATOR . 'vendor_config.php');
if (!is_array($vc) || !isset($vc['autoload_file'], $vc['config_file'], $vc['version_suffix'])) {
echo 'Error: Incorrect vendor config file';
exit;
}

define('APP_VERSION', '2.2.1' . strval($vc['version_suffix']));

$va = strval($vc['autoload_file']);
if (is_readable($va)) {
require_once($va);
}

unset($vc, $va);

spl_autoload_register(function ($class) {
$prefix = 'Liuch\\DmarcSrg\\';
$prefix_len = 15;
$base_dir = __DIR__ . '/classes/';
$base_dir = ROOT_PATH . 'classes' . DIRECTORY_SEPARATOR;

if (strncmp($prefix, $class, $prefix_len) === 0) {
$relative_class = substr($class, $prefix_len);
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
$file = $base_dir . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php';
if (file_exists($file)) {
require_once($file);
}
Expand All @@ -45,10 +59,10 @@
'auth' => [ 'Liuch\DmarcSrg\Auth' ],
'admin' => [ 'Liuch\DmarcSrg\Admin' ],
'ehandler' => [ 'Liuch\DmarcSrg\ErrorHandler' ],
'config' => [ 'Liuch\DmarcSrg\Config', [ __DIR__ . '/config/conf.php' ] ],
'config' => [ 'Liuch\DmarcSrg\Config', [ strval($vc['config_file']) ] ],
'status' => [ 'Liuch\DmarcSrg\Status' ],
'database' => [ 'Liuch\DmarcSrg\Database\DatabaseController' ],
'template' => __DIR__ . '/template.html'
'template' => ROOT_PATH . 'template.html'
]);
$core->errorHandler()->setLogger(new Liuch\DmarcSrg\Log\PhpSystemLogger());

Expand Down

0 comments on commit c876bc2

Please sign in to comment.