better way to manage cleaners stack
This commit is contained in:
parent
69cb2d8e9d
commit
09b9939b65
@ -14,8 +14,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dotclear\Plugin\Uninstaller;
|
namespace Dotclear\Plugin\Uninstaller;
|
||||||
|
|
||||||
use ArrayObject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleaner abstract class.
|
* Cleaner abstract class.
|
||||||
*
|
*
|
||||||
@ -55,17 +53,6 @@ abstract class AbstractCleaner
|
|||||||
$this->actions = $actions;
|
$this->actions = $actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create and add the Cleaner to a stack.
|
|
||||||
*
|
|
||||||
* @param ArrayObject $stack The cleaners stack
|
|
||||||
*/
|
|
||||||
public static function create(ArrayObject $stack): void
|
|
||||||
{
|
|
||||||
$class = static::class;
|
|
||||||
$stack->append(new $class());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize Cleaner properties.
|
* Initialize Cleaner properties.
|
||||||
*
|
*
|
||||||
|
@ -14,7 +14,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Dotclear\Plugin\Uninstaller;
|
namespace Dotclear\Plugin\Uninstaller;
|
||||||
|
|
||||||
use ArrayObject;
|
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
@ -27,24 +26,28 @@ class Cleaners
|
|||||||
private array $cleaners = [];
|
private array $cleaners = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor register the cleaners.
|
* Contructor load cleaners.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$cleaners = new ArrayObject();
|
# --BEHAVIOR-- UninstallerConstruct: Uninstaller
|
||||||
|
dcCore::app()->callBehavior('UninstallerCleanersConstruct', $this);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
/**
|
||||||
# --BEHAVIOR-- UninstallerAddCleaner: ArrayObject
|
* Add a cleaner.
|
||||||
dcCore::app()->callBehavior('UninstallerAddCleaner', $cleaners);
|
*
|
||||||
|
* @param AbstractCleaner $cleaner The cleaner instance
|
||||||
foreach ($cleaners as $cleaner) {
|
*
|
||||||
if (is_a($cleaner, AbstractCleaner::class) && !isset($this->cleaners[$cleaner->id])) {
|
* @return Cleaners Self instance
|
||||||
$this->cleaners[$cleaner->id] = $cleaner;
|
*/
|
||||||
}
|
public function add(AbstractCleaner $cleaner): Cleaners
|
||||||
}
|
{
|
||||||
} catch (Exception $e) {
|
if (!isset($this->cleaners[$cleaner->id])) {
|
||||||
dcCore::app()->error->add($e->getMessage());
|
$this->cleaners[$cleaner->id] = $cleaner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,14 +35,18 @@ class Prepend extends dcNsProcess
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add cleaners to Uninstaller
|
// Add cleaners to Uninstaller
|
||||||
dcCore::app()->addBehavior('UninstallerAddCleaner', [Cleaner\Settings::class, 'create']);
|
dcCore::app()->addBehavior('UninstallerCleanersConstruct', function (Uninstaller $uninstaller): void {
|
||||||
dcCore::app()->addBehavior('UninstallerAddCleaner', [Cleaner\Tables::class, 'create']);
|
$uninstaller->cleaners
|
||||||
dcCore::app()->addBehavior('UninstallerAddCleaner', [Cleaner\Versions::class, 'create']);
|
->add(new Cleaner\Settings())
|
||||||
dcCore::app()->addBehavior('UninstallerAddCleaner', [Cleaner\Logs::class, 'create']);
|
->add(new Cleaner\Tables())
|
||||||
dcCore::app()->addBehavior('UninstallerAddCleaner', [Cleaner\Caches::class, 'create']);
|
->add(new Cleaner\Versions())
|
||||||
dcCore::app()->addBehavior('UninstallerAddCleaner', [Cleaner\Vars::class, 'create']);
|
->add(new Cleaner\Logs())
|
||||||
dcCore::app()->addBehavior('UninstallerAddCleaner', [Cleaner\Themes::class, 'create']);
|
->add(new Cleaner\Caches())
|
||||||
dcCore::app()->addBehavior('UninstallerAddCleaner', [Cleaner\Plugins::class, 'create']);
|
->add(new Cleaner\Vars())
|
||||||
|
->add(new Cleaner\Themes())
|
||||||
|
->add(new Cleaner\Plugins())
|
||||||
|
;
|
||||||
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user