phpro / grumphp

A PHP code-quality tool
MIT License
4.11k stars 429 forks source link

Introduce the new v2 extension system #1091

Closed veewee closed 1 year ago

veewee commented 1 year ago
Q A
Branch v2
Bug fix? yes
New feature? yes
BC breaks? yes
Deprecations? no
Documented? yes
Fixed tickets

Fixes https://github.com/phpro/grumphp-shim/issues/20

This PR introduces a new GrumPHP extension system for v2. Since the new implementation does not leak the dependency with symfony/dependency-injection to the PHP API of an extension, we can make any extension work in grumphp-shim (PHAR distribition) with scoped dependencies as well.

A well calculated downside of this, is that an extension maintainer is now forced to configure the service declarations in a separate YAML (or xml, ...) file where previously this could be done directly from PHP.

Breaking change:

class MyExtension implements ExtensionInterface
{

-     public function load(ContainerBuilder $container): void { /* ... */ }

+    public function imports(): iterable {
+        yield '/path/to/my/config.yaml';
+    }
}

And make sure all services are registered through a symfony/dependency-injection compatible configuration file. (YAML, XML, INI, ...) - PHP is not supported because of the scoped vendor in the PHAR.

# /path/to/my/config.yaml

services:
  xxxxxx: xxxx

More info : https://symfony.com/doc/current/service_container.html