-
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.
Redesigned Setup API & overwrite constraint handling
- Merged Setup with Builder - Moved decorator feature to separate Setup method - Added composedInstance Entry method - Added Wrapper builder for decorator and compose methods - Replaced overwrite flag with explicit "replace" methods - Redesigned abstraction dependencies and inheritance - Moved setup exceptions to Setup namespace - Minor refactorings
- Loading branch information
Showing
18 changed files
with
927 additions
and
585 deletions.
There are no files selected for viewing
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,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Polymorphine/Container package. | ||
* | ||
* (c) Shudd3r <q3.shudder@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Polymorphine\Container\Records\Record; | ||
|
||
use Polymorphine\Container\Records\Record; | ||
use Psr\Container\ContainerInterface; | ||
|
||
|
||
class ComposedInstanceRecord implements Record | ||
{ | ||
private $recursiveId; | ||
private $baseRecord; | ||
private $wrappers; | ||
private $cached; | ||
|
||
public function __construct(string $id, Record $baseRecord, array $wrappers) | ||
{ | ||
$this->recursiveId = $id; | ||
$this->baseRecord = $baseRecord; | ||
$this->wrappers = $wrappers; | ||
} | ||
|
||
public function value(ContainerInterface $container) | ||
{ | ||
if ($this->cached) { return $this->cached; } | ||
$current = $this->baseRecord->value($container); | ||
foreach ($this->wrappers as [$className, $dependencies]) { | ||
$current = new $className(...$this->mapContainerRecords($current, $dependencies, $container)); | ||
} | ||
|
||
return $this->cached = $current; | ||
} | ||
|
||
private function mapContainerRecords($current, array $identifiers, ContainerInterface $container): array | ||
{ | ||
$dependencies = []; | ||
foreach ($identifiers as $id) { | ||
$dependencies[] = $id === $this->recursiveId ? $current : $container->get($id); | ||
} | ||
return $dependencies; | ||
} | ||
} |
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
Oops, something went wrong.