65 lines
2.1 KiB
PHP
65 lines
2.1 KiB
PHP
|
<?php
|
||
|
namespace nur\sery\db;
|
||
|
|
||
|
/**
|
||
|
* Class AbstractCapacitor: implémentation de base d'un {@link ICapacitor}
|
||
|
*/
|
||
|
abstract class AbstractCapacitor implements ICapacitor {
|
||
|
abstract protected function getChannel(?string $name=null): CapacitorChannel;
|
||
|
|
||
|
abstract function _exists(CapacitorChannel $channel): bool;
|
||
|
|
||
|
/** tester si le canal spécifié existe */
|
||
|
function exists(?string $channel=null): bool {
|
||
|
return $this->_exists($this->getChannel($channel));
|
||
|
}
|
||
|
|
||
|
abstract function _reset(CapacitorChannel $channel): void;
|
||
|
|
||
|
/** supprimer le canal spécifié */
|
||
|
function reset(?string $channel=null): void {
|
||
|
$this->_reset($this->getChannel($channel));
|
||
|
}
|
||
|
|
||
|
abstract function _charge($item, CapacitorChannel $channel): void;
|
||
|
|
||
|
/** charger une valeur dans le canal */
|
||
|
function charge($item, ?string $channel=null): void {
|
||
|
$this->_charge($item, $this->getChannel($channel));
|
||
|
}
|
||
|
|
||
|
abstract function _discharge($keys=null, CapacitorChannel $channel=null, ?bool $reset=null): iterable;
|
||
|
|
||
|
/** décharger les données du canal spécifié */
|
||
|
function discharge($keys=null, ?string $channel=null, ?bool $reset=null): iterable {
|
||
|
return $this->_discharge($keys, $this->getChannel($channel), $reset);
|
||
|
}
|
||
|
|
||
|
abstract function _get($keys, CapacitorChannel $channel=null);
|
||
|
|
||
|
/**
|
||
|
* obtenir l'élément identifié par les clés spécifiées sur le canal spécifié
|
||
|
*
|
||
|
* si $keys n'est pas un tableau, il est transformé en ["_id" => $keys]
|
||
|
*/
|
||
|
function get($keys, ?string $channel=null) {
|
||
|
return $this->_get($keys, $this->getChannel($channel));
|
||
|
}
|
||
|
|
||
|
abstract function _each($keys, callable $func, ?array $args=null, CapacitorChannel $channel=null): void;
|
||
|
|
||
|
/**
|
||
|
* appeler une fonction pour chaque élément du canal spécifié.
|
||
|
*
|
||
|
* $keys permet de filtrer parmi les élements chargés
|
||
|
*
|
||
|
* si $func retourne un tableau, il est utilisé pour mettre à jour
|
||
|
* l'enregistrement.
|
||
|
*/
|
||
|
function each($keys, callable $func, ?array $args=null, ?string $channel=null): void {
|
||
|
$this->_each($keys, $func, $args, $this->getChannel($channel));
|
||
|
}
|
||
|
|
||
|
abstract function close(): void;
|
||
|
}
|