mirror of
https://github.com/Intervention/image.git
synced 2025-08-21 21:15:11 +02:00
Add Collection::get() method
This commit is contained in:
@@ -109,6 +109,11 @@ class Collection implements CollectionInterface, IteratorAggregate, Countable
|
|||||||
return $this->items[$key];
|
return $this->items[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function has(int $key): bool
|
||||||
|
{
|
||||||
|
return array_key_exists($key, $this->items);
|
||||||
|
}
|
||||||
|
|
||||||
public function query(string $query, $default = null)
|
public function query(string $query, $default = null)
|
||||||
{
|
{
|
||||||
$items = $this->getItemsFlat();
|
$items = $this->getItemsFlat();
|
||||||
|
@@ -6,6 +6,7 @@ interface CollectionInterface
|
|||||||
{
|
{
|
||||||
public function push($item): CollectionInterface;
|
public function push($item): CollectionInterface;
|
||||||
public function get(int $key);
|
public function get(int $key);
|
||||||
|
public function has(int $key);
|
||||||
public function first();
|
public function first();
|
||||||
public function last();
|
public function last();
|
||||||
public function count(): int;
|
public function count(): int;
|
||||||
|
@@ -86,6 +86,14 @@ class CollectionTest extends TestCase
|
|||||||
$this->assertEquals('test', $collection->get(3, 'test'));
|
$this->assertEquals('test', $collection->get(3, 'test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHas(): void
|
||||||
|
{
|
||||||
|
$collection = new Collection(['foo', 'bar']);
|
||||||
|
$this->assertTrue($collection->has(0));
|
||||||
|
$this->assertTrue($collection->has(1));
|
||||||
|
$this->assertFalse($collection->has(2));
|
||||||
|
}
|
||||||
|
|
||||||
public function testToArray()
|
public function testToArray()
|
||||||
{
|
{
|
||||||
$collection = new Collection(['foo', 'bar', 'baz']);
|
$collection = new Collection(['foo', 'bar', 'baz']);
|
||||||
|
Reference in New Issue
Block a user