-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation #1
base: develop
Are you sure you want to change the base?
Changes from all commits
6d17deb
f37abe7
4906a08
c85efad
4e56b38
b76f69e
9a03fc5
e9286f8
0eb5586
702c8c1
b48e506
1c1beef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
# Dhii - Service tools | ||
|
||
A set of tools for working with service providers. | ||
A set of tools for working with service providers that use [`ServiceInterface`](service-interface). | ||
|
||
## Analysis | ||
|
||
This package provides a set of analyzers that can detect various kinds of service-related issues, such as: | ||
|
||
* Circular dependencies | ||
* Dependencies that don't resolve to known services | ||
* Extensions that don't extend a known service | ||
|
||
**Usage**: | ||
|
||
``` | ||
$analyzer = new CircularDependencyAnalyzer(); | ||
$issues = $analyzer->analyze($factories, $extensions); | ||
|
||
foreach ($issues as $issue) { | ||
$severity = $issue->getSeverity(); | ||
$message = $issue->getMessage(); | ||
|
||
switch ($severity) { | ||
case Issue::WARNING: /* do something */ | ||
case Issue::ERROR: /* do something */ | ||
} | ||
} | ||
``` | ||
|
||
All the analyzers implement an [`AnalyzerInterface`](analyzer-interface). Container implementations can choose to | ||
accept an analyzer instance during construction or setup using this interface, and then perform analysis on the | ||
finished state of the container, after all [`ServiceProviderInterface`](service-provider) instances have been accepted. | ||
|
||
Whether a container takes action on the reported issues or not is left up to the implementation. However, it is | ||
strongly recommended that implementations take action according to the severity of the reported issues: | ||
|
||
* `Issue::WARNING` - these issues should be reported to the developer; execution may resume. | ||
* `Issue::ERROR` - these issues represent a fatal error waiting to happen; execution should probably stop. | ||
|
||
[service-interface]: https://github.com/Dhii/services-interface | ||
[analyzer-interface]: https://github.com/Dhii/service-tools/blob/initial/src/AnalyzerInterface.php | ||
[service-provider]: https://github.com/container-interop/service-provider/blob/master/src/ServiceProviderInterface.php |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dhii\Services\Tools; | ||
|
||
use Dhii\Services\ServiceInterface; | ||
|
||
interface AnalyzerInterface | ||
{ | ||
/** | ||
* Analyzes a set of factories and extensions. | ||
* | ||
* @param array<callable|ServiceInterface> $factories The list of factories to analyze. | ||
* @param array<callable|ServiceInterface> $extensions The list of extensions to analyze. | ||
* | ||
* @return iterable<Issue> A list of issues found during analysis. | ||
*/ | ||
public function analyze(array $factories, array $extensions): iterable; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dhii\Services\Tools\Analyzers; | ||
|
||
use Dhii\Services\Tools\AnalyzerInterface; | ||
|
||
/** | ||
* An analyzer implementation that aggregates issues from multiple other analyzers. | ||
*/ | ||
class AggregateAnalyzer implements AnalyzerInterface | ||
{ | ||
/** @var AnalyzerInterface[] */ | ||
protected $analyzers; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param AnalyzerInterface[] $analyzers The analyzers to aggregate. | ||
*/ | ||
public function __construct(array $analyzers) | ||
{ | ||
$this->analyzers = $analyzers; | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function analyze(array $factories, array $extensions): iterable | ||
{ | ||
foreach ($this->analyzers as $analyzer) { | ||
yield from $analyzer->analyze($factories, $extensions); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be
iterable
instead ofarray
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. It's been a while since I wrote this. I'll get back to you on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can't be
iterable
because the desired type is, in actuality,array<string, callable|ServiceInterface>
.