-
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.
feat: 🔖 add support for dynamic class resolution
- Loading branch information
Showing
13 changed files
with
298 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phetit\DependencyInjection\Exception\Dependency; | ||
|
||
/** | ||
* This exception is thrown when a class's dependency fails to be resolved because builtin type | ||
*/ | ||
class InvalidBuiltinTypeException extends InvalidTypeException | ||
{ | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Exception/Dependency/InvalidIntersectionTypeException.php
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phetit\DependencyInjection\Exception\Dependency; | ||
|
||
/** | ||
* This exception is thrown when a class's dependency fails to be resolved because intersection type | ||
*/ | ||
class InvalidIntersectionTypeException extends InvalidTypeException | ||
{ | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phetit\DependencyInjection\Exception\Dependency; | ||
|
||
/** | ||
* This exception is thrown when a class's dependency fails to be resolved because missing type hint | ||
*/ | ||
class InvalidMissingTypeException extends InvalidTypeException | ||
{ | ||
protected string $formatMessage = 'Failed to resolve class "%s" because parameter "%s" has no type hint'; | ||
} |
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phetit\DependencyInjection\Exception\Dependency; | ||
|
||
use Phetit\DependencyInjection\Exception\ContainerException; | ||
|
||
/** | ||
* This exception is thrown when a class's dependency fails to be resolved because invalid type | ||
*/ | ||
abstract class InvalidTypeException extends ContainerException | ||
{ | ||
protected string $formatMessage = 'Failed to resolve class "%s" because invalid type for parameter "%s"'; | ||
|
||
/** | ||
* @param string $class Class trying to be resolved | ||
* @param string $parameter Dependency trying to be resolved | ||
*/ | ||
public function __construct(string $class, string $parameter) | ||
{ | ||
parent::__construct(sprintf($this->formatMessage, $class, $parameter)); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phetit\DependencyInjection\Exception\Dependency; | ||
|
||
/** | ||
* This exception is thrown when a class's dependency fails to be resolved because union type | ||
*/ | ||
class InvalidUnionTypeException extends InvalidTypeException | ||
{ | ||
} |
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 |
---|---|---|
|
@@ -6,7 +6,4 @@ | |
|
||
class Service | ||
{ | ||
public function __construct(public int $value = 0) | ||
{ | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phetit\DependencyInjection\Tests\Fixtures; | ||
|
||
class ServiceWithDefaultValue | ||
{ | ||
public function __construct( | ||
public Service $service = new ServiceWithoutConstructor(), | ||
public int $value = 0, | ||
) { | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phetit\DependencyInjection\Tests\Fixtures; | ||
|
||
class ServiceWithDependency | ||
{ | ||
public function __construct(public Service $service) | ||
{ | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phetit\DependencyInjection\Tests\Fixtures; | ||
|
||
class ServiceWithNullableDependency | ||
{ | ||
public function __construct(public ?Service $service) | ||
{ | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phetit\DependencyInjection\Tests\Fixtures; | ||
|
||
class ServiceWithoutConstructor extends Service | ||
{ | ||
} |