Export PhpStorm Advanced Metadata from DI containers
Export PhpStorm Advanced Metadata from DI containers to enable code completion.
The library is inspired by Pimple Container Dumper for Silex but doesn't require IDE plugin because it uses native PhpStorm export format. It also supports Slim and is extensible to support more DI containers and frameworks in future.
Install by composer
composer require sandfoxme/phpstorm-metadata-export --dev
The library has full support for the Pimple DI version 3.*
The library has partial support for the Zend ServiceManager. Please note that there's no open and public way of iterating over SM entries so the implementation is tied to the internal structure not covered by the semantic version compatibility promise. Feel free to open an issue if it is broken for some scenario
Obviously the implementation also cannot create hints for abstract factories
The library is tested against Zend SM version 3.3 and should work with any 3.* version
The library has integration classes available for Slim and Silex.
By default exporter will create directory
.phpstorm.meta.php in the root path of your project
vendor directory is) and put metadata file to it on every request.
It is a good idea to enable integration components only in development environment.
Don't forget to gitignore your
<?php use SandFoxMe\PhpStorm\Metadata\Generator; $container = new Container(); file_put_contents( '/path/to/project/.phpstorm.meta.php/my_export_file.meta.php', Generator::get([$container]) ); // OR Generator::store( '/path/to/project/.phpstorm.meta.php/my_export_file.meta.php', [$container] );
Add middleware class
SandFoxMe\PhpStorm\Metadata\Integration\Slim\ContainerExportMiddleware to your Slim app.
<?php use Slim\App; use SandFoxMe\PhpStorm\Metadata\Integration\Slim\ContainerExportMiddleware; $app = new App(); $app->add(new ContainerExportMiddleware($app->getContainer())); // You can also override metadata filename like this $app->add(new ContainerExportMiddleware($app->getContainer(), [ // it is a good idea to use full path here 'filename' => '/path/to/project/.phpstorm.meta.php/my_export_file.meta.php', ]));
Add service provider class
SandFoxMe\PhpStorm\Metadata\Integration\Silex\ContainerExportProvider to your Silex app.
<?php use Silex\Application; use SandFoxMe\PhpStorm\Metadata\Integration\Silex\ContainerExportProvider; $app = new Application(); $app->register(new ContainerExportProvider()); // You can also override metadata filename like this $app->register(new ContainerExportProvider(), [ // it is a good idea to use full path here 'phpstorm.metadata.filename' => '/path/to/project/.phpstorm.meta.php/my_export_file.meta.php', ]);
Version 1.1 adds Psr15 compliant middleware implementation. It generally uses the same approach as Slim Middleware.
The classname is
<?php use SandFoxMe\PhpStorm\Metadata\Integration\Psr15\ContainerExportMiddleware; $middleware = new ContainerExportMiddleware($container); // You can also override metadata filename like this $middleware = new ContainerExportMiddleware($container, [ // it is a good idea to use full path here 'filename' => '/path/to/project/.phpstorm.meta.php/my_export_file.meta.php', ]); // Register middleware the way your compliant framework allows it $myPsr15CompliantApp->registerMiddleware($middleware);
The library is available as open source under the terms of the MIT License. See LICENSE.md