2024-05-20 09:34:54 +04:00
|
|
|
<?php
|
|
|
|
namespace nur\sery\db;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AbstractCapacitor: implémentation de base d'un {@link ICapacitor}
|
|
|
|
*/
|
|
|
|
abstract class AbstractCapacitor implements ICapacitor {
|
2024-05-20 10:46:18 +04:00
|
|
|
abstract protected function getChannel(?string $name): CapacitorChannel;
|
2024-05-20 09:34:54 +04:00
|
|
|
|
|
|
|
abstract function _exists(CapacitorChannel $channel): bool;
|
|
|
|
|
|
|
|
/** tester si le canal spécifié existe */
|
2024-05-20 10:46:18 +04:00
|
|
|
function exists(?string $channel): bool {
|
2024-05-20 09:34:54 +04:00
|
|
|
return $this->_exists($this->getChannel($channel));
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract function _reset(CapacitorChannel $channel): void;
|
|
|
|
|
|
|
|
/** supprimer le canal spécifié */
|
2024-05-20 10:46:18 +04:00
|
|
|
function reset(?string $channel): void {
|
2024-05-20 09:34:54 +04:00
|
|
|
$this->_reset($this->getChannel($channel));
|
|
|
|
}
|
|
|
|
|
2024-05-20 10:46:18 +04:00
|
|
|
abstract function _charge(CapacitorChannel $channel, $item, ?callable $func, ?array $args): bool;
|
2024-05-20 09:34:54 +04:00
|
|
|
|
2024-05-20 10:46:18 +04:00
|
|
|
function charge(?string $channel, $item, ?callable $func=null, ?array $args=null): bool {
|
|
|
|
return $this->_charge($this->getChannel($channel), $item, $func, $args);
|
2024-05-20 09:34:54 +04:00
|
|
|
}
|
|
|
|
|
2024-05-20 10:46:18 +04:00
|
|
|
abstract function _discharge(CapacitorChannel $channel, $filter, ?bool $reset): iterable;
|
2024-05-20 09:34:54 +04:00
|
|
|
|
2024-05-20 10:46:18 +04:00
|
|
|
function discharge(?string $channel, $filter=null, ?bool $reset=null): iterable {
|
|
|
|
return $this->_discharge($this->getChannel($channel), $filter, $reset);
|
2024-05-20 09:34:54 +04:00
|
|
|
}
|
|
|
|
|
2024-05-20 10:46:18 +04:00
|
|
|
abstract function _get(CapacitorChannel $channel, $filter);
|
2024-05-20 09:34:54 +04:00
|
|
|
|
2024-05-20 10:46:18 +04:00
|
|
|
function get(?string $channel, $filter) {
|
|
|
|
return $this->_get($this->getChannel($channel), $filter);
|
2024-05-20 09:34:54 +04:00
|
|
|
}
|
|
|
|
|
2024-05-20 10:46:18 +04:00
|
|
|
abstract function _each(CapacitorChannel $channel, $filter, callable $func, ?array $args): void;
|
2024-05-20 09:34:54 +04:00
|
|
|
|
2024-05-20 10:46:18 +04:00
|
|
|
function each(?string $channel, $filter, callable $func, ?array $args=null): void {
|
|
|
|
$this->_each($this->getChannel($channel), $filter, $func, $args);
|
2024-05-20 09:34:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract function close(): void;
|
|
|
|
}
|