61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
namespace nur\sery\db;
|
|
|
|
/**
|
|
* Class Capacitor: un objet permettant d'attaquer un canal spécique d'une
|
|
* instance de {@link CapacitorStorage}
|
|
*/
|
|
class Capacitor {
|
|
function __construct(CapacitorStorage $storage, CapacitorChannel $channel, bool $ensureExists=true) {
|
|
$this->storage = $storage;
|
|
$this->channel = $channel;
|
|
if ($ensureExists) $this->ensureExists();
|
|
}
|
|
|
|
/** @var CapacitorStorage */
|
|
protected $storage;
|
|
|
|
/** @var CapacitorChannel */
|
|
protected $channel;
|
|
|
|
function exists(): bool {
|
|
return $this->storage->_exists($this->channel);
|
|
}
|
|
|
|
function ensureExists(): void {
|
|
$this->storage->_ensureExists($this->channel);
|
|
}
|
|
|
|
function reset(): void {
|
|
$this->storage->_reset($this->channel);
|
|
}
|
|
|
|
function charge($item, ?callable $func=null, ?array $args=null): int {
|
|
return $this->storage->_charge($this->channel, $item, $func, $args);
|
|
}
|
|
|
|
function discharge($filter=null, ?bool $reset=null): iterable {
|
|
return $this->storage->_discharge($this->channel, $reset);
|
|
}
|
|
|
|
function count($filter=null): int {
|
|
return $this->storage->_count($this->channel, $filter);
|
|
}
|
|
|
|
function one($filter): ?array {
|
|
return $this->storage->_one($this->channel, $filter);
|
|
}
|
|
|
|
function all($filter): iterable {
|
|
return $this->storage->_all($this->channel, $filter);
|
|
}
|
|
|
|
function each($filter, ?callable $func=null, ?array $args=null): int {
|
|
return $this->storage->_each($this->channel, $filter, $func, $args);
|
|
}
|
|
|
|
function close(): void {
|
|
$this->storage->close();
|
|
}
|
|
}
|