diff --git a/CHANGELOG.md b/CHANGELOG.md index ada94b8..02154fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## V8.0.1 - TBD + +### Added + +- [#49](https://github.com/elie29/zend-di-config/issues/49) Support writing proxy classes to files + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + ## V8.0.0 - 2021-03-23 - V8.0+ supports only PHP8+ and drops other versions diff --git a/README.md b/README.md index 0a36284..55a9006 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Coverage Status](https://coveralls.io/repos/github/elie29/zend-di-config/badge.svg)](https://coveralls.io/github/elie29/zend-di-config) ## Introduction + [zend-phpdi-config](https://packagist.org/packages/elie29/zend-phpdi-config) acts as a bridge to configure a PSR-11 compatible [PHP-DI](http://php-di.org) container using service manager configuration. It can be used with [Laminas](https://getlaminas.org/) and [Mezzio](https://docs.mezzio.dev/) starting from v6.0.0 @@ -39,6 +40,9 @@ $container = $factory( // Enable compilation Config::DI_CACHE_PATH => __DIR__, // Folder path + // Write proxy to file : cf. https://php-di.org/doc/lazy-injection.html + Config::DI_PROXY_PATH => __DIR__, // Folder path + // Disable autowire (enabled by default) Config::USE_AUTOWIRE => false @@ -69,23 +73,25 @@ The `dependencies` sub associative array can contain the following keys: [Expressive delegators documentation](https://docs.laminas.dev/laminas-servicemanager/delegators/) for more details. ->**N.B.:** The whole configuration -- unless `dependencies` -- is merged in a `config` key within the `$container`: +> **N.B.:** The whole configuration -- unless `dependencies` -- is merged in a `config` key within the `$container`: > ->```php ->$config = $container->get('config'); ->``` +> ```php +> $config = $container->get('config'); +> ``` ## CLI command to add a new autowire entry + ![Configuration image](./config-add-entry.png) The cli command `add-autowires-entry` creates the configuration file if it doesn't exist otherwise it adds the entry to the autowires key. Example of adding ConsoleHelper to a config.php: ->```console ->./vendor/bin/add-autowires-entry config.php "Laminas\\Stdlib\\ConsoleHelper" ->[DONE] Changes written to config.php ->``` + +> ```console +> ./vendor/bin/add-autowires-entry config.php "Laminas\\Stdlib\\ConsoleHelper" +> [DONE] Changes written to config.php +> ``` ## Using with Expressive @@ -113,6 +119,7 @@ return call_user_func(function () { ``` ## Example of a ConfigProvider class + ```php shouldWriteProxyToFile($builder); + if (! $this->enableCompilation($builder)) { $this->setDependencies(); $this->addDefinitions($builder); @@ -162,6 +164,14 @@ private function enableCache(ContainerBuilder $builder): void } } + private function shouldWriteProxyToFile(ContainerBuilder $builder): void + { + $path = $this->definitions[self::CONFIG][self::DI_PROXY_PATH] ?? null; + if ($path) { + $builder->writeProxiesToFile(true, $path); + } + } + private function get(string $key): array { if (! isset($this->dependencies[$key]) || ! is_array($this->dependencies[$key])) { diff --git a/src/ConfigInterface.php b/src/ConfigInterface.php index 260ae1e..e93fb1e 100644 --- a/src/ConfigInterface.php +++ b/src/ConfigInterface.php @@ -12,6 +12,7 @@ interface ConfigInterface public const DI_CACHE_PATH = 'di_cache_path'; public const ENABLE_CACHE_DEFINITION = 'enable_cache_definition'; public const USE_AUTOWIRE = 'use_autowire'; + public const DI_PROXY_PATH = 'di_proxy_path'; public function configureContainer(ContainerBuilder $builder): void; }