You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
666 B
44 lines
666 B
<?php
|
|
|
|
namespace DbCopy;
|
|
|
|
class Cursor implements ICursor
|
|
{
|
|
private $_closed;
|
|
private $_buffer;
|
|
private $_callback;
|
|
|
|
public function __construct(callable $callback)
|
|
{
|
|
$this->_callback = $callback;
|
|
$this->_closed = false;
|
|
$this->_buffer = [];
|
|
}
|
|
|
|
public function closed(): bool
|
|
{
|
|
return $this->_closed;
|
|
}
|
|
|
|
public function get(): ?array
|
|
{
|
|
if ($this->_closed)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (sizeof($this->_buffer) == 0)
|
|
{
|
|
// Fill more data
|
|
$callback = $this->_callback;
|
|
$this->_buffer = $callback();
|
|
if (sizeof($this->_buffer) == 0)
|
|
{
|
|
$this->_closed = true;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return array_shift($this->_buffer);
|
|
}
|
|
}
|
|
|