-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
132 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/doctrine-collections-decorator package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Collections\Decorator\Tests\Model; | ||
|
||
class Book | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/doctrine-collections-decorator package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\Collections\Decorator\Tests\Model; | ||
|
||
use Doctrine\Common\Collections\Collection; | ||
use Rekalogika\Collections\Decorator\AbstractCollectionDecorator; | ||
|
||
/** | ||
* @extends AbstractCollectionDecorator<array-key,Book> | ||
*/ | ||
class TypedCollectionDecorator extends AbstractCollectionDecorator | ||
{ | ||
/** | ||
* @param Collection<array-key,Book> $wrapped | ||
*/ | ||
public function __construct(private Collection $wrapped) | ||
{ | ||
} | ||
|
||
protected function getWrapped(): Collection | ||
{ | ||
return $this->wrapped; | ||
} | ||
|
||
private static function ensure(mixed $book): Book | ||
{ | ||
if (!$book instanceof Book) { | ||
throw new \InvalidArgumentException('Invalid input'); | ||
} | ||
|
||
return $book; | ||
} | ||
|
||
public function add(mixed $element): void | ||
{ | ||
$this->getWrapped()->add(self::ensure($element)); | ||
} | ||
|
||
public function set(string|int $key, mixed $value): void | ||
{ | ||
$this->getWrapped()->set($key, self::ensure($value)); | ||
} | ||
} |