https://github.com/thecodingmachine/service-provider-utils
This package contains a set of tools to work with container-interop's service-providers.
https://github.com/thecodingmachine/service-provider-utils
Last synced: 5 months ago
JSON representation
This package contains a set of tools to work with container-interop's service-providers.
- Host: GitHub
- URL: https://github.com/thecodingmachine/service-provider-utils
- Owner: thecodingmachine
- License: mit
- Created: 2016-04-19T15:24:29.000Z (almost 10 years ago)
- Default Branch: 1.0
- Last Pushed: 2016-04-19T15:29:57.000Z (almost 10 years ago)
- Last Synced: 2025-02-16T12:30:29.596Z (about 1 year ago)
- Language: PHP
- Size: 3.91 KB
- Stars: 1
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://scrutinizer-ci.com/g/thecodingmachine/service-provider-utils/?branch=1.0)
[](https://travis-ci.org/thecodingmachine/service-provider-utils)
[](https://coveralls.io/github/thecodingmachine/service-provider-utils?branch=1.0)
# Service-provider utils
This package contains a set of tools to work with [container-interop's service-providers](https://github.com/container-interop/definition-interop/).
## Installation
You can install this package through Composer:
```json
{
"require": {
"thecodingmachine/service-provider-utils": "~1.0"
}
}
```
The packages adheres to the [SemVer](http://semver.org/) specification, and there will be full backward compatibility
between minor versions.
## Usage
This package contains a single utility method that analyses a factory (i.e. a callable) and returns if the second argument (the `$previous` argument) is used or not.
```php
// $previous is not used in this callable
$callable = function(ContainerInterface $container, $previous) {
return new MyService();
});
$factoryAnalyser = new FactoryAnalyzer();
$isPreviousUsed = $factoryAnalyser->isPreviousArgumentUsed($callable);
// $isPreviousUsed === false
```
Note: this function can sometimes return false positives, in particular if your body contains calls to `func_get_args` or refences by variable name (`$$foo`). It should however never return false negatives.