2020-04-25 21:57:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace danog\MadelineProto\Db;
|
|
|
|
|
2020-04-28 02:41:06 +02:00
|
|
|
use Amp\Producer;
|
|
|
|
use Amp\Promise;
|
|
|
|
use function Amp\call;
|
|
|
|
|
2020-04-27 02:21:18 +02:00
|
|
|
class MemoryArray extends \ArrayIterator implements DbArray
|
2020-04-25 21:57:55 +02:00
|
|
|
{
|
2020-04-27 02:21:18 +02:00
|
|
|
protected function __construct($array = [], $flags = 0)
|
|
|
|
{
|
|
|
|
parent::__construct((array) $array, $flags | self::STD_PROP_LIST);
|
|
|
|
}
|
2020-04-25 21:57:55 +02:00
|
|
|
|
2020-04-28 02:41:06 +02:00
|
|
|
public static function getInstance(string $name, $value, string $tablePrefix, array $settings): DbArray
|
2020-04-25 21:57:55 +02:00
|
|
|
{
|
|
|
|
if ($value instanceof DbArray) {
|
|
|
|
$value = $value->getArrayCopy();
|
|
|
|
}
|
|
|
|
return new static($value);
|
|
|
|
}
|
2020-04-28 02:41:06 +02:00
|
|
|
|
|
|
|
public static function getDbConnection(array $settings)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function offsetGetAsync(string $offset): Promise
|
|
|
|
{
|
|
|
|
return call(fn() => $this->offsetGet($offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function offsetSetAsync(string $offset, $value): Promise
|
|
|
|
{
|
|
|
|
return call(fn() => $this->offsetSet($offset, $value));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIterator(): Producer
|
|
|
|
{
|
|
|
|
return new Producer(function (callable $emit) {
|
|
|
|
foreach ($this as $value) {
|
|
|
|
yield $emit($value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-04-25 21:57:55 +02:00
|
|
|
}
|