From c8ad2ab4567012181f1955074fdde4e209ad85ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Novotn=C3=BD?= Date: Fri, 22 Jul 2022 19:51:02 +0200 Subject: [PATCH] Add Collection and Model interface --- CHANGELOG.md | 8 +++++++- src/BaseCollection.php | 15 ++++----------- src/BaseModel.php | 6 ++---- src/Collection.php | 24 ++++++++++++++++++++++++ src/Model.php | 17 +++++++++++++++++ 5 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 src/Collection.php create mode 100644 src/Model.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 3303242..3b7268d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased](https://github.com/inspirum/arrayable-php/compare/v1.0.0...master) +## [Unreleased](https://github.com/inspirum/arrayable-php/compare/v1.1.0...master) + + +## [v1.1.0 (2022-07-22)](https://github.com/inspirum/balikobot-php/compare/v1.0.0...v1.1.0) +### Added +- Added [**Collection**](./src/Collection.php) interface +- Added [**Model**](./src/Model.php) interface ## v1.0.0 (2022-07-04) diff --git a/src/BaseCollection.php b/src/BaseCollection.php index b0908a2..542c65a 100644 --- a/src/BaseCollection.php +++ b/src/BaseCollection.php @@ -4,12 +4,7 @@ namespace Inspirum\Arrayable; -use ArrayAccess; use ArrayIterator; -use Countable; -use IteratorAggregate; -use JsonSerializable; -use Stringable; use Traversable; use function array_key_exists; use function array_map; @@ -21,18 +16,16 @@ * @template TItemKey of array-key * @template TItemValue * @template TKey of array-key - * @template TValue of \Inspirum\Arrayable\Arrayable - * @implements \ArrayAccess - * @implements \IteratorAggregate - * @implements \Inspirum\Arrayable\Arrayable> + * @template TValue of \Inspirum\Arrayable\Arrayable + * @implements \Inspirum\Arrayable\Collection */ -abstract class BaseCollection implements ArrayAccess, Countable, IteratorAggregate, Arrayable, JsonSerializable, Stringable +abstract class BaseCollection implements Collection { /** * @param array $items */ public function __construct( - protected array $items, + protected array $items = [], ) { } diff --git a/src/BaseModel.php b/src/BaseModel.php index a29959f..c141830 100644 --- a/src/BaseModel.php +++ b/src/BaseModel.php @@ -4,17 +4,15 @@ namespace Inspirum\Arrayable; -use JsonSerializable; -use Stringable; use function json_encode; use const JSON_THROW_ON_ERROR; /** * @template TKey of array-key * @template TValue - * @implements \Inspirum\Arrayable\Arrayable + * @implements \Inspirum\Arrayable\Model */ -abstract class BaseModel implements Arrayable, JsonSerializable, Stringable +abstract class BaseModel implements Model { /** * @return array diff --git a/src/Collection.php b/src/Collection.php new file mode 100644 index 0000000..213c9ae --- /dev/null +++ b/src/Collection.php @@ -0,0 +1,24 @@ + + * @extends \ArrayAccess + * @extends \IteratorAggregate + * @extends \Inspirum\Arrayable\Arrayable> + */ +interface Collection extends ArrayAccess, Countable, IteratorAggregate, Arrayable, JsonSerializable, Stringable +{ +} diff --git a/src/Model.php b/src/Model.php new file mode 100644 index 0000000..e4446d5 --- /dev/null +++ b/src/Model.php @@ -0,0 +1,17 @@ + + */ +interface Model extends Arrayable, JsonSerializable, Stringable +{ +}