Skip to content

Commit e938b8c

Browse files
Add an interface for entity collections
1 parent 44e6685 commit e938b8c

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

src/Entity/Collection/EntityCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Symfony\Component\Serializer\Encoder\JsonDecode;
77
use Symfony\Component\Serializer\Encoder\JsonEncoder;
88

9-
abstract class EntityCollection implements \Iterator, \Countable
9+
abstract class EntityCollection implements EntityCollectionInterface, \Countable
1010
{
1111
use CollectionRelLinkTrait;
1212

@@ -72,7 +72,7 @@ public function key()
7272
/**
7373
* {@inheritdoc}
7474
*/
75-
public function valid()
75+
public function valid(): bool
7676
{
7777
return isset($this->rawData->list[$this->iteratorPosition]);
7878
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Hussainweb\DrupalApi\Entity\Collection;
4+
5+
/**
6+
* Interface representing a collection of entities loaded from drupal.org.
7+
*/
8+
interface EntityCollectionInterface extends \Iterator
9+
{
10+
11+
/**
12+
* @return bool|\GuzzleHttp\Psr7\Uri
13+
*/
14+
public function getSelfLink();
15+
16+
/**
17+
* @return bool|\GuzzleHttp\Psr7\Uri
18+
*/
19+
public function getFirstLink();
20+
21+
/**
22+
* @return bool|\GuzzleHttp\Psr7\Uri
23+
*/
24+
public function getPreviousLink();
25+
26+
/**
27+
* @return bool|\GuzzleHttp\Psr7\Uri
28+
*/
29+
public function getNextLink();
30+
31+
/**
32+
* @return bool|\GuzzleHttp\Psr7\Uri
33+
*/
34+
public function getLastLink();
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
public function current();
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
public function next();
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function key();
50+
51+
/**
52+
* {@inheritdoc}
53+
*/
54+
public function valid(): bool;
55+
56+
/**
57+
* {@inheritdoc}
58+
*
59+
* If a collection does not support rewinding, implement this method with an
60+
* empty body.
61+
*/
62+
public function rewind();
63+
}

0 commit comments

Comments
 (0)