2021-05-06 20:15:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-04-14 16:11:25 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2021-05-06 20:15:01 +00:00
|
|
|
namespace Benzine\ORM\Abstracts;
|
|
|
|
|
|
|
|
|
|
abstract class AbstractCollection
|
|
|
|
|
{
|
|
|
|
|
protected array $contained = [];
|
|
|
|
|
|
2022-06-19 01:19:07 +00:00
|
|
|
public function __toArray(): array
|
|
|
|
|
{
|
2021-07-24 07:11:51 +00:00
|
|
|
return $this->contained;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 20:14:42 +00:00
|
|
|
public function first()
|
|
|
|
|
{
|
|
|
|
|
return reset($this->contained);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-06 20:15:01 +00:00
|
|
|
public function getIterator()
|
|
|
|
|
{
|
|
|
|
|
return new \ArrayIterator($this->contained);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 00:36:25 +00:00
|
|
|
public function offsetExists($offset): bool
|
2021-05-06 20:15:01 +00:00
|
|
|
{
|
|
|
|
|
return isset($this->contained[$offset]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 00:36:25 +00:00
|
|
|
public function offsetUnset($offset): void
|
2021-05-06 20:15:01 +00:00
|
|
|
{
|
|
|
|
|
$this->unset($this->contained[$offset]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 00:36:25 +00:00
|
|
|
public function serialize(): string
|
2021-05-06 20:15:01 +00:00
|
|
|
{
|
|
|
|
|
return serialize($this->contained);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 00:36:25 +00:00
|
|
|
public function unserialize($data): void
|
2021-05-06 20:15:01 +00:00
|
|
|
{
|
|
|
|
|
$this->contained = unserialize($data);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 00:36:25 +00:00
|
|
|
public function count(): int
|
2021-05-06 20:15:01 +00:00
|
|
|
{
|
|
|
|
|
return count($this->contained);
|
|
|
|
|
}
|
2022-07-10 09:29:33 +00:00
|
|
|
|
|
|
|
|
public function call($functionName)
|
|
|
|
|
{
|
|
|
|
|
$return = [];
|
|
|
|
|
foreach ($this->contained as $index => $contained) {
|
|
|
|
|
$return[$index] = $contained->{$functionName}();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
2021-05-17 00:36:25 +00:00
|
|
|
}
|