1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-29 09:47:36 +01:00

Add method to CollectionInterface

This commit is contained in:
Oliver Vogel 2024-01-16 08:55:58 +01:00
parent ede244d252
commit 297eb5c3c4
3 changed files with 39 additions and 0 deletions

View File

@ -117,6 +117,11 @@ class Collection implements CollectionInterface, IteratorAggregate, Countable
return $positions[$key];
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::get()
*/
public function get(int|string $query, $default = null): mixed
{
if ($this->count() == 0) {

View File

@ -2,6 +2,7 @@
namespace Intervention\Image\Drivers\Imagick;
use Collectable;
use Imagick;
use ImagickException;
use Iterator;
@ -209,16 +210,42 @@ class Core implements CoreInterface, Iterator
return $this;
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::first()
*/
public function first(): FrameInterface
{
return $this->frame(0);
}
/**
* {@inheritdoc}
*
* @see CollectableInterface::last()
*/
public function last(): FrameInterface
{
return $this->frame($this->count() - 1);
}
/**
* {@inheritdoc}
*
* @see CollectionInterface::toArray()
*/
public function toArray(): array
{
$frames = [];
foreach ($this as $frame) {
$frames[] = $frame;
}
return $frames;
}
public function __clone(): void
{
$this->imagick = clone $this->imagick;

View File

@ -68,6 +68,13 @@ interface CollectionInterface extends Traversable
*/
public function empty(): CollectionInterface;
/**
* Transform collection as array
*
* @return array
*/
public function toArray(): array;
/**
* Extract items based on given values and discard the rest.
*