This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Config
Fabien Potencier 91904af902 feature #21289 [DI] Add prototype services for PSR4-based discovery and registration (nicolas-grekas)
This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Add prototype services for PSR4-based discovery and registration

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | to be done

Talking with @dunglas, we wondered if this could be a good idea, as a more general approach to folder-based service registration as done in [DunglasActionBundle](https://github.com/dunglas/DunglasActionBundle/blob/master/DependencyInjection/DunglasActionExtension.php).

So here is the implementation.

This allows one to define a set of services as such:
```yaml
services:
    App\:
        resources: ../src/{Controller,Command} # relative to the current file as usual
        autowire: true # or any other attributes really
```

This looks for php files in the "src" folder, derivates PSR-4 class names from them, and uses `class_exists` for final discovery. The resulting services are named after the classes found this way.

The "resource" attribute can be a glob to select only a subset of the classes/files.

This approach has several advantages over [DunglasActionBundle](https://github.com/dunglas/DunglasActionBundle/blob/master/DependencyInjection/DunglasActionExtension.php):
- it is resilient to missing parent classes (see test case)
- it loads classes using the normal code path (the autoloader), thus play well with them (e.g. if one registered a special autoloader).
- it is more predictable, because it uses discovered paths as the only source of ids/classes to register - vs relying on `get_declared_classes`, which would make things context sensitive.

Fits well with current initiatives to me.

Commits
-------

03470b788e [DI] Add "psr4" service attribute for PSR4-based discovery and registration
2017-02-13 06:22:10 +01:00
..
Definition [Config][FrameworkBundle] Allow to dump extension config reference sub path 2017-01-09 22:03:44 +01:00
Exception Use a dedicated exception in the file locator 2016-08-09 07:23:16 -07:00
Loader [DI] Add "psr4" service attribute for PSR4-based discovery and registration 2017-02-12 23:09:17 +01:00
Resource feature #21505 [Config][DI] Add ComposerResource to track the runtime engine + deps (nicolas-grekas) 2017-02-12 12:59:14 +01:00
Tests feature #21505 [Config][DI] Add ComposerResource to track the runtime engine + deps (nicolas-grekas) 2017-02-12 12:59:14 +01:00
Util Fixed bugs in names of classes and methods. 2016-07-26 06:40:54 +02:00
.gitignore Added missing files .gitignore 2013-07-21 14:12:18 +02:00
CHANGELOG.md [DI][Config] Add & use ReflectionClassResource 2017-02-02 14:15:15 +01:00
composer.json fixed composer.json 2016-12-10 09:22:22 +01:00
ConfigCache.php [Config] ConfigCache::isFresh() should return false on __PHP_Incomplete_Class 2016-11-29 11:39:48 +01:00
ConfigCacheFactory.php Implement service-based Resource (cache) validation 2015-09-25 08:31:17 +02:00
ConfigCacheFactoryInterface.php fixes CS 2015-08-24 09:13:45 +02:00
ConfigCacheInterface.php removed dots at the end of @param and @return 2016-06-28 08:24:06 +02:00
FileLocator.php Merge branch '3.1' 2016-09-14 15:49:28 -07:00
FileLocatorInterface.php Use a dedicated exception in the file locator 2016-08-09 07:23:16 -07:00
LICENSE updated LICENSE year 2017-01-02 12:30:00 -08:00
phpunit.xml.dist Add missing exclusions from phpunit.xml.dist 2015-11-18 09:19:46 +01:00
README.md Updated all the README files 2016-03-04 08:12:06 +01:00
ResourceCheckerConfigCache.php [Config] Fix checking cache for non existing meta file 2016-12-09 12:03:17 +01:00
ResourceCheckerConfigCacheFactory.php Implement service-based Resource (cache) validation 2015-09-25 08:31:17 +02:00
ResourceCheckerInterface.php fixed CS 2016-06-29 07:31:50 +02:00

Config Component

The Config component provides several classes to help you find, load, combine, autofill and validate configuration values of any kind, whatever their source may be (YAML, XML, INI files, or for instance a database).

Resources