-
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.
Merge pull request #20 from valantic/choices-repo
Repository for Choices
- Loading branch information
Showing
11 changed files
with
110 additions
and
132 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
15 changes: 15 additions & 0 deletions
15
src/Exception/Repository/ItemNotFoundInRepositoryException.php
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Valantic\PimcoreFormsBundle\Exception\Repository; | ||
|
||
use Valantic\PimcoreFormsBundle\Exception\BaseException; | ||
|
||
class ItemNotFoundInRepositoryException extends BaseException | ||
{ | ||
public function __construct(string $key) | ||
{ | ||
parent::__construct(sprintf('Item %s not found in repository', $key)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Valantic\PimcoreFormsBundle\Repository; | ||
|
||
use Valantic\PimcoreFormsBundle\Exception\Repository\ItemNotFoundInRepositoryException; | ||
|
||
/** | ||
* @template TItem | ||
* | ||
* @internal | ||
*/ | ||
abstract class AbstractRepository | ||
{ | ||
/** @var TItem[] */ | ||
protected array $items; | ||
|
||
public function __construct( | ||
/** @var \Iterator<TItem> */ | ||
protected iterable $iterables, | ||
) { | ||
} | ||
|
||
/** @return TItem */ | ||
public function get(string $key) | ||
{ | ||
return $this->all()[$key] ?? throw new ItemNotFoundInRepositoryException($key); | ||
} | ||
|
||
/** @return TItem[] */ | ||
protected function all(): array | ||
{ | ||
$this->items ??= $this->initializeItemsFromIterables(); | ||
|
||
return $this->items; | ||
} | ||
|
||
/** | ||
* @return array<class-string<TItem>,TItem> | ||
*/ | ||
protected function initializeItemsFromIterables(): array | ||
{ | ||
$arr = []; | ||
|
||
foreach ($this->iterables as $iterable) { | ||
$arr[$iterable::class] = $iterable; | ||
} | ||
|
||
return $arr; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Valantic\PimcoreFormsBundle\Repository; | ||
|
||
use Valantic\PimcoreFormsBundle\Form\Type\ChoicesInterface; | ||
|
||
/** | ||
* @extends AbstractRepository<ChoicesInterface> | ||
* | ||
* @internal | ||
*/ | ||
class ChoicesRepository extends AbstractRepository | ||
{ | ||
} |
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
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