1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-22 21:42:53 +02: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]; return $positions[$key];
} }
/**
* {@inheritdoc}
*
* @see CollectionInterface::get()
*/
public function get(int|string $query, $default = null): mixed public function get(int|string $query, $default = null): mixed
{ {
if ($this->count() == 0) { if ($this->count() == 0) {

View File

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

View File

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