-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional factory/extension interfaces and dependency inspection (#54
) * add dependency enumeration feature. * add optional interfaces for factories/extensions. * add callable types: these were tested with Psalm and PHPStan, and worked as expected with both - this provides static analysis with at least two popular tools (probably PHPStorm as well) and to the rest of the world they are just documentation.
- Loading branch information
1 parent
a55e717
commit 7dcd502
Showing
5 changed files
with
68 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
} | ||
}, | ||
"require": { | ||
"php": ">= 8.0.0", | ||
"psr/container": "^1.0 || ^2.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,21 @@ | ||
<?php | ||
|
||
namespace Interop\Container; | ||
|
||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* An extension optionally implements this interface to reflect it's dependencies. | ||
*/ | ||
interface ExtensionDefinitionInterface | ||
{ | ||
/** | ||
* Extends a given service, using the given container to resolve dependencies. | ||
* | ||
* @param ContainerInterface $container The container that should be used to resolve dependencies | ||
* @param mixed $previous The previous service | ||
* | ||
* @return mixed The extended service. | ||
*/ | ||
public function __invoke(ContainerInterface $container, mixed $previous): mixed; | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace Interop\Container; | ||
|
||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* A factory optionally implements this interface to reflect it's dependencies. | ||
*/ | ||
interface FactoryDefinitionInterface | ||
{ | ||
/** | ||
* Creates the entry, using the given container to resolve dependencies. | ||
* | ||
* @param ContainerInterface $container The container that should be used to resolve dependencies | ||
* | ||
* @return mixed The created entry | ||
*/ | ||
public function __invoke(ContainerInterface $container): mixed; | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace Interop\Container; | ||
|
||
/** | ||
* A `ServiceProviderInterface` implementation may optionally implements this interface, | ||
* which provides a means of reflecting the dependencies of the provided services. | ||
*/ | ||
interface ServiceDependencyInterface | ||
{ | ||
/** | ||
* @return array<string,string[]> map where entry ID => list of dependency IDs | ||
*/ | ||
public function getDependencies(): array; | ||
} |
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