mirror of
https://github.com/Intervention/image.git
synced 2025-08-19 04:01:30 +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];
|
||||
}
|
||||
|
||||
public function has(int $key): bool
|
||||
{
|
||||
return array_key_exists($key, $this->items);
|
||||
}
|
||||
|
||||
public function query(string $query, $default = null)
|
||||
{
|
||||
$items = $this->getItemsFlat();
|
||||
|
@@ -6,6 +6,7 @@ interface CollectionInterface
|
||||
{
|
||||
public function push($item): CollectionInterface;
|
||||
public function get(int $key);
|
||||
public function has(int $key);
|
||||
public function first();
|
||||
public function last();
|
||||
public function count(): int;
|
||||
|
@@ -86,6 +86,14 @@ class CollectionTest extends TestCase
|
||||
$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()
|
||||
{
|
||||
$collection = new Collection(['foo', 'bar', 'baz']);
|
||||
|
Reference in New Issue
Block a user