Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* next: shorten expression to build service fix readme declare the builder immutable rename Container to Builder and ServiceLocator to Container split responsibility between builder and concrete container bump psalm version test against lowest dependencies require php 8.1 change email use CS 2 use ramsey/composer-install remove bc check
- Loading branch information
Showing
8 changed files
with
112 additions
and
125 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
File renamed without changes.
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,45 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Innmind\DI; | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
final class Builder | ||
{ | ||
/** @var array<string, callable(Container): object> */ | ||
private array $definitions = []; | ||
|
||
/** | ||
* @param array<string, callable(Container): object> $definitions | ||
*/ | ||
private function __construct(array $definitions) | ||
{ | ||
$this->definitions = $definitions; | ||
} | ||
|
||
/** | ||
* @psalm-pure | ||
*/ | ||
public static function new(): self | ||
{ | ||
return new self([]); | ||
} | ||
|
||
/** | ||
* @param callable(Container): object $definition | ||
*/ | ||
public function add(string $name, callable $definition): self | ||
{ | ||
$definitions = $this->definitions; | ||
$definitions[$name] = $definition; | ||
|
||
return new self($definitions); | ||
} | ||
|
||
public function build(): Container | ||
{ | ||
return Container::of($this->definitions); | ||
} | ||
} |
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.
Oops, something went wrong.