Skip to content

Commit c8ad2ab

Browse files
committed
Add Collection and Model interface
1 parent a365cf1 commit c8ad2ab

File tree

5 files changed

+54
-16
lines changed

5 files changed

+54
-16
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

88

9-
## [Unreleased](https://github.com/inspirum/arrayable-php/compare/v1.0.0...master)
9+
## [Unreleased](https://github.com/inspirum/arrayable-php/compare/v1.1.0...master)
10+
11+
12+
## [v1.1.0 (2022-07-22)](https://github.com/inspirum/balikobot-php/compare/v1.0.0...v1.1.0)
13+
### Added
14+
- Added [**Collection**](./src/Collection.php) interface
15+
- Added [**Model**](./src/Model.php) interface
1016

1117

1218
## v1.0.0 (2022-07-04)

src/BaseCollection.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44

55
namespace Inspirum\Arrayable;
66

7-
use ArrayAccess;
87
use ArrayIterator;
9-
use Countable;
10-
use IteratorAggregate;
11-
use JsonSerializable;
12-
use Stringable;
138
use Traversable;
149
use function array_key_exists;
1510
use function array_map;
@@ -21,18 +16,16 @@
2116
* @template TItemKey of array-key
2217
* @template TItemValue
2318
* @template TKey of array-key
24-
* @template TValue of \Inspirum\Arrayable\Arrayable<TItemKey, TItemValue>
25-
* @implements \ArrayAccess<TKey, TValue>
26-
* @implements \IteratorAggregate<TKey, TValue>
27-
* @implements \Inspirum\Arrayable\Arrayable<TKey, array<TItemKey, TItemValue>>
19+
* @template TValue of \Inspirum\Arrayable\Arrayable<TItemKey,TItemValue>
20+
* @implements \Inspirum\Arrayable\Collection<TItemKey,TItemValue,TKey,TValue>
2821
*/
29-
abstract class BaseCollection implements ArrayAccess, Countable, IteratorAggregate, Arrayable, JsonSerializable, Stringable
22+
abstract class BaseCollection implements Collection
3023
{
3124
/**
3225
* @param array<TKey, TValue> $items
3326
*/
3427
public function __construct(
35-
protected array $items,
28+
protected array $items = [],
3629
) {
3730
}
3831

src/BaseModel.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44

55
namespace Inspirum\Arrayable;
66

7-
use JsonSerializable;
8-
use Stringable;
97
use function json_encode;
108
use const JSON_THROW_ON_ERROR;
119

1210
/**
1311
* @template TKey of array-key
1412
* @template TValue
15-
* @implements \Inspirum\Arrayable\Arrayable<TKey, TValue>
13+
* @implements \Inspirum\Arrayable\Model<TKey, TValue>
1614
*/
17-
abstract class BaseModel implements Arrayable, JsonSerializable, Stringable
15+
abstract class BaseModel implements Model
1816
{
1917
/**
2018
* @return array<TKey, TValue>

src/Collection.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Inspirum\Arrayable;
6+
7+
use ArrayAccess;
8+
use Countable;
9+
use IteratorAggregate;
10+
use JsonSerializable;
11+
use Stringable;
12+
13+
/**
14+
* @template TItemKey of array-key
15+
* @template TItemValue
16+
* @template TKey of array-key
17+
* @template TValue of \Inspirum\Arrayable\Arrayable<TItemKey, TItemValue>
18+
* @extends \ArrayAccess<TKey, TValue>
19+
* @extends \IteratorAggregate<TKey, TValue>
20+
* @extends \Inspirum\Arrayable\Arrayable<TKey, array<TItemKey, TItemValue>>
21+
*/
22+
interface Collection extends ArrayAccess, Countable, IteratorAggregate, Arrayable, JsonSerializable, Stringable
23+
{
24+
}

src/Model.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Inspirum\Arrayable;
6+
7+
use JsonSerializable;
8+
use Stringable;
9+
10+
/**
11+
* @template TKey of array-key
12+
* @template TValue
13+
* @extends \Inspirum\Arrayable\Arrayable<TKey, TValue>
14+
*/
15+
interface Model extends Arrayable, JsonSerializable, Stringable
16+
{
17+
}

0 commit comments

Comments
 (0)