Download the PHP package makinacorpus/argument-resolver without Composer
On this page you can find all versions of the php package makinacorpus/argument-resolver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download makinacorpus/argument-resolver
More information about makinacorpus/argument-resolver
Files in makinacorpus/argument-resolver
Package argument-resolver
Short Description Callback argument resolver interface and implementations.
License GPL-2.0-or-later
Informations about the package argument-resolver
Callback argument resolver
Provide a callback argument resolver interface and implementation, very similar
to symfony/http-kernel
's ArgumentResolver
class implementation, but usable
out of Symfony project and HTTP context.
This API does not depend upon any other, and has copy-pasted some code from the Symfony component:
- This choice has been made because Symfony's code hardwires the Request object dependency as a part of its API where we need to be able to use this API out of the HTTP context.
- This makes this component resilient to Symfony code changes in the long term and simplifies maintainance.
1.0 Roadmap
- [x] API basics
- [x] Retrieve features from
makinacorpus/access-control
- [x] Basic Symfony bundle
- [x] Service argument value resolver
Get started
Installation
Install it using composer:
As Symfony bundle setup
Then add to your config/bundles.php
file:
Basic usage
Consider the following function:
This will reconciliate arguments from argument value resolvers:
And that's it. This has no real added value as-is, but it becomes handy when working with dynamic service method calls in a large complex app.
Symfony integration
Basics
More than one argument resolver can coexist in container, each one will have a dedicated string identifier, for example:
- when using
makinacorpus/access-control
, theaccess-control
argument resolver will be created, - when using
makinacorpus/corebus
, thecorebus
argument resolver will be created.
For plugging in custom value resolver, there is two different tags:
- use the
custom.argument_resolver.default
tag for registering a value resolver to all argument resolvers, - use the
custom.argument_resolver.NAME
tag, whereNAME
is one of the argument resolver identifiers for register a given value converter.
Define a new argument resolver
Whatever situation is yours, creating a new resolver in a project, or in a
custom bundle, you must add a new service using the argument_resolver
tag
to define a new service, such as:
You may also want to provide some additional custom value resolvers:
Notice that the name after the last .
in the custom.argument_resolver.my_custom_name
string refers to the argument resolver id
attribute.
In your services, use the my_custom_bundle.argument_resolver
service for
injection, since you defined for your own usage.
Some compiler passes will do the hard job of autowiring anything that needs to be autowired for you.