dcAdvancedCleaner/src/ManageVars.php

86 lines
2.2 KiB
PHP
Raw Normal View History

2023-04-16 00:48:32 +00:00
<?php
/**
* @brief dcAdvancedCleaner, 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\dcAdvancedCleaner;
use Dotclear\Plugin\Uninstaller\{
2023-05-01 13:49:22 +00:00
CleanerParent,
CleanersStack,
2023-04-16 00:48:32 +00:00
Uninstaller
};
use Exception;
class ManageVars
{
2023-05-01 17:34:54 +00:00
/** @var ManageVars self instance */
2023-04-16 00:48:32 +00:00
private static $container;
2023-05-01 17:34:54 +00:00
/** @var CleanersStack The cleaners stack */
2023-05-01 13:49:22 +00:00
public readonly CleanersStack $cleaners;
2023-05-01 17:34:54 +00:00
/** @var null|CleanerParent The post form cleaner */
2023-05-01 13:49:22 +00:00
public readonly ?CleanerParent $cleaner;
2023-05-01 17:34:54 +00:00
/** @var string $related The post form related action id */
public readonly string $related;
2023-05-01 17:34:54 +00:00
/** @var array<int,string> The post form selected ns */
2023-04-16 00:48:32 +00:00
public readonly array $entries;
2023-05-01 17:34:54 +00:00
/** @var string The post form action id */
2023-04-16 00:48:32 +00:00
public readonly string $action;
2023-05-01 17:34:54 +00:00
/** @var array<string,string> The form actions combo */
2023-04-16 00:48:32 +00:00
public readonly array $combo;
protected function __construct()
{
$this->cleaners = Uninstaller::instance()->cleaners;
$related = $_REQUEST['related'] ?? '';
2023-04-16 00:48:32 +00:00
$entries = $_REQUEST['entries'] ?? [];
$action = $_POST['action'] ?? '';
$cleaner = null;
$combo = [];
2023-05-01 13:49:22 +00:00
foreach ($this->cleaners as $k) {
2023-04-16 00:48:32 +00:00
$combo[$k->name] = $k->id;
2023-04-25 08:17:37 +00:00
if ($k->id == ($_REQUEST['part'] ?? '/')) {
2023-04-16 00:48:32 +00:00
$cleaner = $k;
}
}
if ($cleaner === null) {
$related = '';
2023-04-16 00:48:32 +00:00
if (!($cleaner = $this->cleaners->get('caches'))) {
throw new Exception(__('Failed to load cleaner'));
}
}
$this->cleaner = $cleaner;
$this->related = $related;
2023-04-16 00:48:32 +00:00
$this->entries = is_array($entries) ? $entries : [];
$this->action = is_string($action) ? $action : '';
$this->combo = $combo;
}
public static function init(): ManageVars
{
if (!(self::$container instanceof self)) {
self::$container = new self();
}
return self::$container;
}
}