Skip to content

Commit

Permalink
Add Collection and Model interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-novotny committed Jul 22, 2022
1 parent a365cf1 commit c8ad2ab
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 4 additions & 11 deletions src/BaseCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,18 +16,16 @@
* @template TItemKey of array-key
* @template TItemValue
* @template TKey of array-key
* @template TValue of \Inspirum\Arrayable\Arrayable<TItemKey, TItemValue>
* @implements \ArrayAccess<TKey, TValue>
* @implements \IteratorAggregate<TKey, TValue>
* @implements \Inspirum\Arrayable\Arrayable<TKey, array<TItemKey, TItemValue>>
* @template TValue of \Inspirum\Arrayable\Arrayable<TItemKey,TItemValue>
* @implements \Inspirum\Arrayable\Collection<TItemKey,TItemValue,TKey,TValue>
*/
abstract class BaseCollection implements ArrayAccess, Countable, IteratorAggregate, Arrayable, JsonSerializable, Stringable
abstract class BaseCollection implements Collection
{
/**
* @param array<TKey, TValue> $items
*/
public function __construct(
protected array $items,
protected array $items = [],
) {
}

Expand Down
6 changes: 2 additions & 4 deletions src/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<TKey, TValue>
* @implements \Inspirum\Arrayable\Model<TKey, TValue>
*/
abstract class BaseModel implements Arrayable, JsonSerializable, Stringable
abstract class BaseModel implements Model
{
/**
* @return array<TKey, TValue>
Expand Down
24 changes: 24 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Inspirum\Arrayable;

use ArrayAccess;
use Countable;
use IteratorAggregate;
use JsonSerializable;
use Stringable;

/**
* @template TItemKey of array-key
* @template TItemValue
* @template TKey of array-key
* @template TValue of \Inspirum\Arrayable\Arrayable<TItemKey, TItemValue>
* @extends \ArrayAccess<TKey, TValue>
* @extends \IteratorAggregate<TKey, TValue>
* @extends \Inspirum\Arrayable\Arrayable<TKey, array<TItemKey, TItemValue>>
*/
interface Collection extends ArrayAccess, Countable, IteratorAggregate, Arrayable, JsonSerializable, Stringable
{
}
17 changes: 17 additions & 0 deletions src/Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Inspirum\Arrayable;

use JsonSerializable;
use Stringable;

/**
* @template TKey of array-key
* @template TValue
* @extends \Inspirum\Arrayable\Arrayable<TKey, TValue>
*/
interface Model extends Arrayable, JsonSerializable, Stringable
{
}

0 comments on commit c8ad2ab

Please sign in to comment.