This PR was merged into the 4.3-dev branch.
Discussion
----------
[DI] Add an url EnvProcessor
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | https://github.com/symfony/symfony-docs/pull/11128
This PR add a new env processor `url` to convert an URL (or DSN) into an array.
The main goal is to simplify the project configuration and reduce the number of env variable when working with bundle which are not able to deal with DSN
(pick some random project in symfony/recipes-contrib: https://github.com/symfony/recipes-contrib/blob/master/facile-it/mongodb-bundle/0.6/manifest.json or https://github.com/symfony/recipes-contrib/blob/master/wouterj/eloquent-bundle/1.0/manifest.json)
```yaml
# before
MONGODB_HOST=localhost
MONGODB_PORT=27017
MONGODB_USER=
MONGODB_PASSWORD=
MONGODB_DB=symfony
mongo_db_bundle:
data_collection: '%kernel.debug%'
clients:
default:
hosts:
- { host: '%env(MONGODB_HOST)%', port: '%env(int:MONGODB_PORT)%' }
username: '%env(MONGODB_USER)%'
password: '%env(MONGODB_PASSWORD)%'
connectTimeoutMS: 3000
connections:
default:
database_name: '%env(MONGODB_DB)%'
# after
MONGODB_DSN=mongodb://localhost:27017/symfony
mongo_db_bundle:
data_collection: '%kernel.debug%'
clients:
default:
hosts:
- { host: '%env(key:host:url:MONGODB_DSN)%', port: '%env(key:port:url:MONGODB_DSN)%' }
username: '%env(key:user:url:MONGODB_DSN)%'
password: '%env(key:pass:url:MONGODB_DSN)%'
connectTimeoutMS: 3000
connections:
default:
database_name: '%env(key:path:url:MONGODB_DSN)%'
```
Added also a `query_string` processor to parse query string
```
DATABASE_DSN=mysql://localhost/db?charset=utf8
foo:
bar:
charset: '%env(key:charset:query_string🔑query:url:DATABASE_DSN)%'
```
Commits
-------
f253c9b7ca
Add an url EnvProcessor
9.4 KiB
CHANGELOG
4.3.0
- added
%env(trim:...)%
processor to trim a string value - added
%env(default:param_name:...)%
processor to fallback to a parameter or to null when using%env(default::...)%
- added
%env(url:...)%
processor to convert an URL or DNS into an array of components - added
%env(query_string:...)%
processor to convert a query string into an array of key values - added support for deprecating aliases
- made
ContainerParametersResource
final and not implementSerializable
anymore - added
ReverseContainer
: a container that turns services back to their ids - added ability to define an index for a tagged collection
- added ability to define an index for services in an injected service locator argument
4.2.0
- added
ContainerBuilder::registerAliasForArgument()
to support autowiring by type+name - added support for binding by type+name
- added
ServiceSubscriberTrait
to ease implementingServiceSubscriberInterface
using methods' return types - added
ServiceLocatorArgument
and!service_locator
config tag for creating optimized service-locators - added support for autoconfiguring bindings
- added
%env(key:...)%
processor to fetch a specific key from an array - deprecated
ServiceSubscriberInterface
, use the same interface from theSymfony\Contracts\Service
namespace instead - deprecated
ResettableContainerInterface
, useSymfony\Contracts\Service\ResetInterface
instead
4.1.0
- added support for variadics in named arguments
- added PSR-11
ContainerBagInterface
and itsContainerBag
implementation to access parameters as-a-service - added support for service's decorators autowiring
- deprecated the
TypedReference::canBeAutoregistered()
andTypedReference::getRequiringClass()
methods - environment variables are validated when used in extension configuration
- deprecated support for auto-discovered extension configuration class which does not implement
ConfigurationInterface
4.0.0
-
Relying on service auto-registration while autowiring is not supported anymore. Explicitly inject your dependencies or create services whose ids are their fully-qualified class name.
Before:
namespace App\Controller; use App\Mailer; class DefaultController { public function __construct(Mailer $mailer) { // ... } // ... }
services: App\Controller\DefaultController: autowire: true
After:
// same PHP code
services: App\Controller\DefaultController: autowire: true # or # App\Controller\DefaultController: # arguments: { $mailer: "@App\Mailer" } App\Mailer: autowire: true
-
removed autowiring services based on the types they implement
-
added a third
$methodName
argument to thegetProxyFactoryCode()
method of theDumperInterface
-
removed support for autowiring types
-
removed
Container::isFrozen
-
removed support for dumping an ucompiled container in
PhpDumper
-
removed support for generating a dumped
Container
without populating the method map -
removed support for case insensitive service identifiers
-
removed the
DefinitionDecorator
class, replaced byChildDefinition
-
removed the
AutowireServiceResource
class and relatedAutowirePass::createResourceForClass()
method -
removed
LoggingFormatter
,Compiler::getLoggingFormatter()
andaddLogMessage()
class and methods, use theContainerBuilder::log()
method instead -
removed
FactoryReturnTypePass
-
removed
ContainerBuilder::addClassResource()
, use theaddObjectResource()
or thegetReflectionClass()
method instead. -
removed support for top-level anonymous services
-
removed silent behavior for unused attributes and elements
-
removed support for setting and accessing private services in
Container
-
removed support for setting pre-defined services in
Container
-
removed support for case insensitivity of parameter names
-
removed
AutowireExceptionPass
andAutowirePass::getAutowiringExceptions()
, useDefinition::addError()
and theDefinitionErrorExceptionPass
instead
3.4.0
- moved the
ExtensionCompilerPass
to before-optimization passes with priority -1000 - deprecated "public-by-default" definitions and aliases, the new default will be "private" in 4.0
- added
EnvVarProcessorInterface
and corresponding "container.env_var_processor" tag for processing env vars - added support for ignore-on-uninitialized references
- deprecated service auto-registration while autowiring
- deprecated the ability to check for the initialization of a private service with the
Container::initialized()
method - deprecated support for top-level anonymous services in XML
- deprecated case insensitivity of parameter names
- deprecated the
ResolveDefinitionTemplatesPass
class in favor ofResolveChildDefinitionsPass
- added
TaggedIteratorArgument
with YAML (!tagged foo
) and XML (<service type="tagged"/>
) support - deprecated
AutowireExceptionPass
andAutowirePass::getAutowiringExceptions()
, useDefinition::addError()
and theDefinitionErrorExceptionPass
instead
3.3.0
- deprecated autowiring services based on the types they implement; rename (or alias) your services to their FQCN id to make them autowirable
- added "ServiceSubscriberInterface" - to allow for per-class explicit service-locator definitions
- added "container.service_locator" tag for defining service-locator services
- added anonymous services support in YAML configuration files using the
!service
tag. - added "TypedReference" and "ServiceClosureArgument" for creating service-locator services
- added
ServiceLocator
- a PSR-11 container holding a set of services to be lazily loaded - added "instanceof" section for local interface-defined configs
- added prototype services for PSR4-based discovery and registration
- added
ContainerBuilder::getReflectionClass()
for retrieving and tracking reflection class info - deprecated
ContainerBuilder::getClassResource()
, useContainerBuilder::getReflectionClass()
orContainerBuilder::addObjectResource()
instead - added
ContainerBuilder::fileExists()
for checking and tracking file or directory existence - deprecated autowiring-types, use aliases instead
- added support for omitting the factory class name in a service definition if the definition class is set
- deprecated case insensitivity of service identifiers
- added "iterator" argument type for lazy iteration over a set of values and services
- added file-wide configurable defaults for service attributes "public", "tags", "autowire" and "autoconfigure"
- made the "class" attribute optional, using the "id" as fallback
- using the
PhpDumper
with an uncompiledContainerBuilder
is deprecated and will not be supported anymore in 4.0 - deprecated the
DefinitionDecorator
class in favor ofChildDefinition
- allow config files to be loaded using a glob pattern
- [BC BREAK] the
NullDumper
class is now final
3.2.0
- allowed to prioritize compiler passes by introducing a third argument to
PassConfig::addPass()
, toCompiler::addPass
and toContainerBuilder::addCompilerPass()
- added support for PHP constants in YAML configuration files
- deprecated the ability to set or unset a private service with the
Container::set()
method - deprecated the ability to check for the existence of a private service with the
Container::has()
method - deprecated the ability to request a private service with the
Container::get()
method - deprecated support for generating a dumped
Container
without populating the method map
3.0.0
- removed all deprecated codes from 2.x versions
2.8.0
- deprecated the abstract ContainerAware class in favor of ContainerAwareTrait
- deprecated IntrospectableContainerInterface, to be merged with ContainerInterface in 3.0
- allowed specifying a directory to recursively load all configuration files it contains
- deprecated the concept of scopes
- added
Definition::setShared()
andDefinition::isShared()
- added ResettableContainerInterface to be able to reset the container to release memory on shutdown
- added a way to define the priority of service decoration
- added support for service autowiring
2.7.0
- deprecated synchronized services
2.6.0
- added new factory syntax and deprecated the old one
2.5.0
- added DecoratorServicePass and a way to override a service definition (Definition::setDecoratedService())
- deprecated SimpleXMLElement class.
2.4.0
- added support for expressions in service definitions
- added ContainerAwareTrait to add default container aware behavior to a class
2.2.0
- added Extension::isConfigEnabled() to ease working with enableable configurations
- added an Extension base class with sensible defaults to be used in conjunction with the Config component.
- added PrependExtensionInterface (to be able to allow extensions to prepend application configuration settings for any Bundle)
2.1.0
- added IntrospectableContainerInterface (to be able to check if a service has been initialized or not)
- added ConfigurationExtensionInterface
- added Definition::clearTag()
- component exceptions that inherit base SPL classes are now used exclusively (this includes dumped containers)
- [BC BREAK] fixed unescaping of class arguments, method ParameterBag::unescapeValue() was made public