The Wayback Machine - https://web.archive.org/web/20190325075357/https://github.com/symfony/dependency-injection
Skip to content
The DependencyInjection component allows you to standardize and centralize the way objects are constructed in your application. https://symfony.com/dependency-injection
Branch: master
Clone or download
nicolas-grekas feature #28975 [DI] Add an url EnvProcessor (jderusse)
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        | symfony/symfony-docs#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
Latest commit bc457d3 Mar 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Argument Support indexing tagged locators by FQCN as fallback Mar 11, 2019
Compiler [DI] revert bad patch in previous PR Mar 17, 2019
Config Drop \Serializable Feb 17, 2019
Dumper Support indexing tagged locators by FQCN as fallback Mar 11, 2019
Exception [DI] fix casting AutowiringFailedException to string when its callbac… Mar 17, 2019
Extension Merge branch '3.4' into 4.2 Feb 23, 2019
LazyProxy
Loader Support indexing tagged locators by FQCN as fallback Mar 11, 2019
ParameterBag Merge branch '3.4' into 4.2 Feb 23, 2019
Tests
.gitignore
Alias.php
CHANGELOG.md
ChildDefinition.php Merge branch '3.4' into 4.2 Feb 23, 2019
Container.php
ContainerAwareInterface.php
ContainerAwareTrait.php [DI] minor docblock fixes Oct 24, 2017
ContainerBuilder.php
ContainerInterface.php
Definition.php
EnvVarProcessor.php
EnvVarProcessorInterface.php
ExpressionLanguage.php
ExpressionLanguageProvider.php
LICENSE
Parameter.php
README.md
Reference.php Replace more docblocks by type-hints Nov 7, 2017
ResettableContainerInterface.php
ReverseContainer.php
ServiceLocator.php
ServiceSubscriberInterface.php
TaggedContainerInterface.php remove api tags from code Sep 28, 2015
TypedReference.php
Variable.php
composer.json
phpunit.xml.dist

README.md

You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.