-
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 overwrite strategies
- Added Build class to collect setup entries and create container - Removed bulk add methods from Setup (possible with constructor) - Moved overwrite checks to Setup using Build::has() method - Added Setup::fallback() strategy (add when missing or ignore) - Renamed Setup::add() method to Setup::set() - Separated overwrite violation exception from integrity exception - Renamed static constructors to Setup::development() and Setup::production()
- Loading branch information
Showing
23 changed files
with
585 additions
and
704 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?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\Setup; | ||
|
||
use Polymorphine\Container\RecordContainer; | ||
use Polymorphine\Container\CompositeContainer; | ||
use Polymorphine\Container\Records; | ||
use Psr\Container\ContainerInterface; | ||
|
||
|
||
class Build implements Collection | ||
{ | ||
protected $records; | ||
protected $containers; | ||
|
||
public function __construct(array $records = [], array $containers = []) | ||
{ | ||
$this->records = $records; | ||
$this->containers = $containers; | ||
} | ||
|
||
public function container(): ContainerInterface | ||
{ | ||
return $this->containers | ||
? new CompositeContainer($this->records(), $this->containers) | ||
: new RecordContainer($this->records()); | ||
} | ||
|
||
public function has(string $id): bool | ||
{ | ||
return isset($this->records[$id]) || isset($this->containers[$id]); | ||
} | ||
|
||
public function setRecord(string $id, Records\Record $record): void | ||
{ | ||
$this->records[$id] = $record; | ||
} | ||
|
||
public function setContainer(string $id, ContainerInterface $container): void | ||
{ | ||
$this->containers[$id] = $container; | ||
} | ||
|
||
public function decorator(string $id): Wrapper | ||
{ | ||
if (!isset($this->records[$id])) { | ||
throw Exception\OverwriteRuleException::undefined($id); | ||
} | ||
|
||
return new Wrapper($id, $this->records[$id], new Entry($id, $this)); | ||
} | ||
|
||
protected function records(): Records | ||
{ | ||
return new Records($this->records); | ||
} | ||
} |
Oops, something went wrong.