-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move factories into theirs own container
- Loading branch information
Ondřej Ešler
committed
Jul 10, 2020
1 parent
c27c1bb
commit c7a9bc2
Showing
3 changed files
with
55 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace IW\ServiceContainer; | ||
|
||
final class FactoryContainer | ||
{ | ||
/** @var ServiceFactory[] */ | ||
private $factories = []; | ||
|
||
public function alias(string $alias, string $id): void | ||
{ | ||
$this->factories[$alias] = new AliasFactory($id); | ||
} | ||
|
||
public function bind(string $id, callable $factory): void | ||
{ | ||
$this->factories[$id] = new CallableFactory($factory); | ||
} | ||
|
||
public function get(string $id): ServiceFactory | ||
{ | ||
if (isset($this->factories[$id])) { | ||
return $this->factories[$id]; | ||
} | ||
|
||
return $this->factories[$id] = new ClassnameFactory($id); | ||
} | ||
|
||
public function has(string $id): bool | ||
{ | ||
return isset($this->factories[$id]); | ||
} | ||
} |
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