-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: introduce DI container (#4238)
* refactor: introduce DI container * add bin/test
- Loading branch information
Showing
18 changed files
with
231 additions
and
89 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 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
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,29 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
/** | ||
* Add log records to all three levels (for testing purposes) | ||
*/ | ||
|
||
require __DIR__ . '/../lib/bootstrap.php'; | ||
|
||
$config = []; | ||
if (file_exists(__DIR__ . '/../config.ini.php')) { | ||
$config = parse_ini_file(__DIR__ . '/../config.ini.php', true, INI_SCANNER_TYPED); | ||
if (!$config) { | ||
http_response_code(500); | ||
exit("Error parsing config.ini.php\n"); | ||
} | ||
} | ||
Configuration::loadConfiguration($config, getenv()); | ||
|
||
$container = require __DIR__ . '/../lib/dependencies.php'; | ||
|
||
/** @var Logger $logger */ | ||
$logger = $container['logger']; | ||
|
||
$logger->debug('This is a test debug message'); | ||
|
||
$logger->info('This is a test info message'); | ||
|
||
$logger->error('This is a test error message'); |
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
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
class Container implements \ArrayAccess | ||
{ | ||
private array $values = []; | ||
private array $resolved = []; | ||
|
||
public function offsetSet($offset, $value): void | ||
{ | ||
$this->values[$offset] = $value; | ||
} | ||
|
||
#[ReturnTypeWillChange] public function offsetGet($offset) | ||
{ | ||
if (!isset($this->values[$offset])) { | ||
throw new \Exception(sprintf('Unknown container key: "%s"', $offset)); | ||
} | ||
if (!isset($this->resolved[$offset])) { | ||
$this->resolved[$offset] = $this->values[$offset]($this); | ||
} | ||
return $this->resolved[$offset]; | ||
} | ||
|
||
#[ReturnTypeWillChange] public function offsetExists($offset) | ||
{ | ||
} | ||
|
||
public function offsetUnset($offset): void | ||
{ | ||
} | ||
} |
Oops, something went wrong.