Metadata Exporter for PhpStorm#
Export PhpStorm Advanced Metadata from DI containers to enable code completion.
The library is inspired by Pimple Container Dumper for Silex but it doesn’t require IDE plugin because it uses native PhpStorm export format. It can integrate with any PSR-15 compliant framework and is extensible to support more DI containers and frameworks in the future.
Installation#
Install by composer
composer require arokettu/phpstorm-metadata-export --dev
Documentation#
Usage#
The library has integration classes available for PSR-15 compliant frameworks and legacy Slim.
By default exporter will create directory .phpstorm.meta.php
in the root path of your project
(where 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 .phpstorm.meta.php
directory.
Using Generator directly#
<?php
use SandFox\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]
);
PSR-15#
The library provides a middleware implementation for PSR-15 compliant framework like Slim 4 or Mezzio.
The classname is SandFox\PhpStorm\Metadata\Integration\ContainerExportMiddleware
.
<?php
use SandFox\PhpStorm\Metadata\Integration\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 framework allows it
$myPsr15CompliantApp->registerMiddleware($middleware);
Slim 3#
ContainerExportMiddleware
can also work as a legacy Slim 3 middleware.
Add it to your Slim 3 app:
<?php
use Slim\App;
use SandFox\PhpStorm\Metadata\Integration\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',
]));
Supported Containers#
Pimple#
The library supports Pimple DI version 3.*
Supported containers:
Pimple\Container
: full supportPimple\Psr11\Container
: may be unstablePimple\Psr11\ServiceLocator
: may be unstable
PHP-DI#
The library has full support for the PHP-DI version 6.*
Laminas (Zend) ServiceManager#
The library has partial support for the Laminas ServiceManager and 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.
Abstract factories and lazy services are not supported. Abstract factories support is impossible. Lazy services support would be too complicated.
The library is tested against Zend SM version 3.3 and should work with any 3.* version
Upgrade#
1.x to 2.0#
PHP requirement was bumped to 7.1.
Legacy namespace
SandFoxMe\
was removed, replace it withSandFox\
if you still use it.Silex integration was removed. Just don’t use EOL’d frameworks, switch to Slim, Mezzio or Symfony Flex. If you still need it, you can create your own provider based on the
ContainerExportProvider
from 1.x branch. (source)SandFox\PhpStorm\Metadata\Integration\Psr15\ContainerExportMiddleware
andSandFox\PhpStorm\Metadata\Integration\Slim\ContainerExportMiddleware
were combined intoSandFox\PhpStorm\Metadata\Integration\ContainerExportMiddleware
. Replace accordingly.
License#
The library is available as open source under the terms of the MIT License. See LICENSE.md