use Dotclear autoloader

master
Jean-Christian Paul Denis 2023-04-06 22:44:35 +02:00
parent dc4980d9aa
commit 52b16c0e3f
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
3 changed files with 9 additions and 37 deletions

View File

@ -79,7 +79,7 @@ abstract class Action
*/ */
final public function __construct() final public function __construct()
{ {
$this->class_name = str_replace(Utils::getActionsNS(), '', get_called_class()); $this->class_name = str_replace(__NAMESPACE__ . '\\Module\\', '', get_called_class());
$this->module = new dcModuleDefine('undefined'); $this->module = new dcModuleDefine('undefined');
$settings = dcCore::app()->blog->settings->get(My::id())->get('settings_' . $this->class_name); $settings = dcCore::app()->blog->settings->get(My::id())->get('settings_' . $this->class_name);

View File

@ -20,7 +20,6 @@ use dcPage;
use dcFavorites; use dcFavorites;
use dcNsProcess; use dcNsProcess;
use Dotclear\Helper\File\Files; use Dotclear\Helper\File\Files;
use Dotclear\Helper\Clearbricks;
/** /**
* Improve admin class * Improve admin class
@ -65,10 +64,14 @@ class Backend extends dcNsProcess
dcCore::app()->auth->isSuperAdmin() dcCore::app()->auth->isSuperAdmin()
); );
foreach (Files::scandir(Utils::getActionsDir()) as $file) { $dir = __DIR__ . DIRECTORY_SEPARATOR . 'module' . DIRECTORY_SEPARATOR;
if (is_file(Utils::getActionsDir() . $file) && '.php' == substr($file, -4)) { $ns = __NAMESPACE__ . '\\Module\\';
Clearbricks::lib()->autoload([Utils::getActionsNS() . substr($file, 0, -4) => Utils::getActionsDir() . $file]);
dcCore::app()->addBehavior('improveAddAction', [Utils::getActionsNS() . substr($file, 0, -4), 'create']); /* @phpstan-ignore-line */ dcCore::app()->autoload->addNamespace($ns, $dir);
foreach (Files::scandir($dir) as $file) {
if (str_ends_with($file, '.php') && is_file($dir . $file)) {
dcCore::app()->addBehavior('improveAddAction', [$ns . basename($file, '.php'), 'create']); /* @phpstan-ignore-line */
} }
} }

View File

@ -1,31 +0,0 @@
<?php
/**
* @brief improve, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
namespace Dotclear\Plugin\improve;
/**
* Improve utils class
*/
class Utils
{
public static function getActionsDir(): string
{
return __DIR__ . '/module/';
}
public static function getActionsNS(): string
{
return __NAMESPACE__ . '\\Module\\';
}
}