Remove unnecessary comments, update notes, add AbstractParameterResolver
This commit is contained in:
parent
5ee5de9ef1
commit
f1c1b3fb56
7 changed files with 30 additions and 2850 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,4 +2,5 @@
|
||||||
/vendor
|
/vendor
|
||||||
/node_modules
|
/node_modules
|
||||||
/coverage
|
/coverage
|
||||||
/.phpunit.result.cache
|
/.phpunit.result.cache
|
||||||
|
composer.lock
|
36
CHANGELOG.md
36
CHANGELOG.md
|
@ -1,35 +1,13 @@
|
||||||
# Luma | Dependency Injection Component Change Log
|
# Loom | Dependency Injection Component Change Log
|
||||||
|
|
||||||
## [1.3.0] - 2024-05-05
|
## [1.0.0] 2025-04-26
|
||||||
### Added
|
### Added
|
||||||
- Add support for configuration parameters as service arguments
|
- Initial release.
|
||||||
|
- Cloned from `lumax/dependency-injection-component`.
|
||||||
|
- Add `Loom` namespace.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- N/A
|
- Small refactors to the existing codebase.
|
||||||
|
|
||||||
### Deprecated
|
|
||||||
- N/A
|
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- N/A
|
- Remove dependence on `lumax/luma`.
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- N/A
|
|
||||||
|
|
||||||
### Security
|
|
||||||
- Updated dependencies
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## [1.2.2] - 2024-03-02
|
|
||||||
- Minor housekeeping; `package.json` cleanup, `composer.json` cleanup
|
|
||||||
- Update build pipelines
|
|
||||||
|
|
||||||
## [1.2.1] - 2024-02-23
|
|
||||||
- Update build pipelines
|
|
||||||
|
|
||||||
## [1.2.0] - 2024-02-22
|
|
||||||
- Added CHANGELOG
|
|
||||||
- Added automated build pipeline
|
|
||||||
- `DependencyManager` now throws a RuntimeException if `loadDependenciesFromFile` is called with an invalid filetype (such as JSON).
|
|
||||||
- Increased test coverage to 100%
|
|
|
@ -1,8 +1,8 @@
|
||||||
# Luma | Dependency Injection Component
|
# Loom | Dependency Injection Component
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<!-- Version Badge -->
|
<!-- Version Badge -->
|
||||||
<img src="https://img.shields.io/badge/Version-1.3.0-blue" alt="Version 1.3.0">
|
<img src="https://img.shields.io/badge/Version-1.0.0-blue" alt="Version 1.0.0">
|
||||||
<!-- PHP Coverage Badge -->
|
<!-- PHP Coverage Badge -->
|
||||||
<img src="https://img.shields.io/badge/PHP Coverage-96.36%25-green" alt="PHP Coverage 96.36%">
|
<img src="https://img.shields.io/badge/PHP Coverage-96.36%25-green" alt="PHP Coverage 96.36%">
|
||||||
<!-- License Badge -->
|
<!-- License Badge -->
|
||||||
|
@ -18,7 +18,7 @@ A PHP package for managing dependencies and dependency injection.
|
||||||
You can install this package via [Composer](https://getcomposer.org/):
|
You can install this package via [Composer](https://getcomposer.org/):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
composer require lumax/dependency-injection-component
|
composer require loomlabs/loom.di-component
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
2779
composer.lock
generated
2779
composer.lock
generated
File diff suppressed because it is too large
Load diff
10
src/AbstractParameterResolver.php
Normal file
10
src/AbstractParameterResolver.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Loom\DependencyInjectionComponent;
|
||||||
|
|
||||||
|
abstract class AbstractParameterResolver
|
||||||
|
{
|
||||||
|
abstract public function resolve(string $parameter): string|int|array;
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Loom\DependencyInjectionComponent;
|
namespace Loom\DependencyInjectionComponent;
|
||||||
|
|
||||||
use Loom\DependencyInjectionComponent\Exception\NotFoundException;
|
use Loom\DependencyInjectionComponent\Exception\NotFoundException;
|
||||||
|
|
|
@ -1,27 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Loom\DependencyInjectionComponent;
|
namespace Loom\DependencyInjectionComponent;
|
||||||
|
|
||||||
use Luma\Framework\Luma;
|
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
class DependencyManager
|
class DependencyManager
|
||||||
{
|
{
|
||||||
private DependencyContainer $container;
|
public function __construct(private DependencyContainer $container, private ?AbstractParameterResolver $parameterResolver = null)
|
||||||
|
|
||||||
/**
|
|
||||||
* @param DependencyContainer $container
|
|
||||||
*/
|
|
||||||
public function __construct(DependencyContainer $container)
|
|
||||||
{
|
{
|
||||||
$this->container = $container;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $filename
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @throws Exception\NotFoundException
|
* @throws Exception\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function loadDependenciesFromFile(string $filename): void
|
public function loadDependenciesFromFile(string $filename): void
|
||||||
|
@ -33,11 +24,6 @@ class DependencyManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $filename
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function loadConfigFile(string $filename): array
|
private function loadConfigFile(string $filename): array
|
||||||
{
|
{
|
||||||
if (!str_ends_with($filename, '.yaml')) {
|
if (!str_ends_with($filename, '.yaml')) {
|
||||||
|
@ -54,10 +40,6 @@ class DependencyManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $services
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @throws Exception\NotFoundException
|
* @throws Exception\NotFoundException
|
||||||
*/
|
*/
|
||||||
private function registerServices(array $services): void
|
private function registerServices(array $services): void
|
||||||
|
@ -73,11 +55,6 @@ class DependencyManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $config
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function validateServiceConfig(array $config): void
|
private function validateServiceConfig(array $config): void
|
||||||
{
|
{
|
||||||
if (!isset($config['class']) || !class_exists($config['class'])) {
|
if (!isset($config['class']) || !class_exists($config['class'])) {
|
||||||
|
@ -86,10 +63,6 @@ class DependencyManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $arguments
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @throws Exception\NotFoundException
|
* @throws Exception\NotFoundException
|
||||||
*/
|
*/
|
||||||
private function resolveServiceArguments(array $arguments): array
|
private function resolveServiceArguments(array $arguments): array
|
||||||
|
@ -100,21 +73,16 @@ class DependencyManager
|
||||||
if (is_string($argument) && str_starts_with($argument, '@')) {
|
if (is_string($argument) && str_starts_with($argument, '@')) {
|
||||||
$serviceAlias = ltrim($argument, '@');
|
$serviceAlias = ltrim($argument, '@');
|
||||||
$resolvedArguments[] = $this->container->get($serviceAlias);
|
$resolvedArguments[] = $this->container->get($serviceAlias);
|
||||||
} elseif (is_string($argument) && str_starts_with($argument, ':') && str_ends_with($argument, ':')) {
|
} elseif (is_string($argument) && str_starts_with($argument, ':') && str_ends_with($argument, ':') && $this->parameterResolver) {
|
||||||
$resolvedArguments[] = Luma::getConfigParam(trim($argument, ':'));
|
$resolvedArguments[] = $this->parameterResolver->resolve(trim($argument, ':'));
|
||||||
} else {
|
} else {
|
||||||
$resolvedArguments[] = $argument;
|
$resolvedArguments[] = $argument;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $resolvedArguments;
|
return $resolvedArguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $class
|
|
||||||
* @param array $arguments
|
|
||||||
*
|
|
||||||
* @return object
|
|
||||||
*/
|
|
||||||
private function instantiateService(string $class, array $arguments): object
|
private function instantiateService(string $class, array $arguments): object
|
||||||
{
|
{
|
||||||
if (empty($arguments)) {
|
if (empty($arguments)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue