Files
kiri-core/Database/Base/CollectionIterator.php
T

51 lines
835 B
PHP
Raw Normal View History

2020-09-08 00:49:15 +08:00
<?php
namespace Database\Base;
use Database\ActiveRecord;
2020-09-08 00:57:42 +08:00
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
2020-09-08 00:49:15 +08:00
/**
* Class CollectionIterator
* @package Database\Base
*/
class CollectionIterator extends \ArrayIterator
{
/** @var ActiveRecord */
private $model;
2020-09-08 00:57:42 +08:00
/**
* CollectionIterator constructor.
* @param $model
* @param array $array
* @param int $flags
* @throws \ReflectionException
* @throws NotFindClassException
*/
2020-09-08 00:49:15 +08:00
public function __construct($model, $array = array(), $flags = 0)
{
$this->model = $model;
2020-09-08 00:57:42 +08:00
if (is_string($model)) {
$this->model = Snowflake::createObject($model);
}
2020-09-08 00:49:15 +08:00
parent::__construct($array, $flags);
}
/**
* @return ActiveRecord|mixed
*/
public function current()
{
2020-09-08 00:56:28 +08:00
return (clone $this->model)->setAttributes(parent::current());
2020-09-08 00:49:15 +08:00
}
}