phpstorm symfony2 missing service warning

后端 未结 6 1393
醉酒成梦
醉酒成梦 2021-02-14 08:46

I have installed the Symfony2 plugin for Phpstorm but I can\'t get the IDE to see these existing services or other injected objects. Can these be fixed somehow, so the warnings

相关标签:
6条回答
  • 2021-02-14 09:08

    I had a similar problem and would recommend double checking the following...

    1. As @Marcel suggested, check your Symfony2 plugin is turned on...

      1.1. Settings > Symfony2 plugin

      1.2. Check the paths to the these directories are correct, for some reason I had two symfony projects within a project so the default paths were not accurate

    Symfony2 plugin

    1. You should double check that the plugin's reference to your container XML is accurate, by default it will be "app\cache\dev\appDevDebugProjectContainer.xml" as you can see mine had to be updated and you can see the path is now "EXISTS", it said "ERROR" before

      2.1. Settings > Symfony2 plugin > Container

      2.2. enter image description here

    2. Then, as per @Igor's suggestion clear your cache

    0 讨论(0)
  • 2021-02-14 09:09

    Check to make sure your plugin is at the latest version. I know past versions of the plugin did not resolve the services automatically.

    Otherwise, you can add the following to tell the IDE what variable type $exportHelper is:

    <?php
    
    /* @var $exportHelper \Acme\Bundle\ExportBundle\Service\ExportService */
    $exportHelper = $this->get('Acme.csv.service');
    

    This will then give you auto-completions when typing something like "$exportHelper->".

    0 讨论(0)
  • 2021-02-14 09:09

    If the service is defined in XML and not in YAML then the auto-completion works out-of-the-box without the need to use the @var annotation.

    You can try this sample definition that will provide you with autocomplete when you want to use one of the defined services.

    <?xml version="1.0" encoding="UTF-8" ?>
    <container xmlns="http://symfony.com/schema/dic/services"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    
    
        <services>
            <service id="activityService" class="ActivityManager">
                <argument type="service" id="activityWriter"/>
            </service>
            <service id="activityWriter" class="DirectStatsActivityWriter">
            </service>
        </services>
    </container>
    

    )

    0 讨论(0)
  • 2021-02-14 09:16

    Finally, thanks to the @googol help, I've figured out a way to specify services definitions files in custom paths with a YML format:

    You only have to create or modify the .idea/symfony2.xml file including the following tag: xml <option name="containerFiles"> <list> <container_file path="custom/path/to/your/services_definition.yml" /> </list> </option>

    You'll have to restart the PhpStorm and that's it! :)

    Here you have my complete symfony2.xml file as an example:

    xml <?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="Symfony2PluginSettings"> <option name="pluginEnabled" value="true" /> <option name="twigAnnotateTemplate" value="false" /> <option name="twigAnnotateAsset" value="false" /> <option name="twigAnnotateAssetTags" value="false" /> <option name="twigAnnotateRoute" value="false" /> <option name="twigAnnotateTranslation" value="false" /> <option name="phpAnnotateTemplate" value="false" /> <option name="phpAnnotateService" value="false" /> <option name="phpAnnotateRoute" value="false" /> <option name="phpAnnotateTemplateAnnotation" value="false" /> <option name="phpAnnotateTranslation" value="false" /> <option name="phpHighlightServices" value="true" /> <option name="codeFoldingTwigRoute" value="false" /> <option name="codeFoldingTwigTemplate" value="false" /> <option name="codeFoldingTwigConstant" value="false" /> <option name="containerFiles"> <list> <container_file path="custom/path/to/your/services_definition.yml" /> </list> </option> </component> </project>

    And here you have a feature request in order to include the possibility to add this custom path service definition through the plugin UI settings instead of having to edit the config file manually: https://github.com/Haehnchen/idea-php-symfony2-plugin/issues/573

    0 讨论(0)
  • 2021-02-14 09:20

    So it seems that I didn't enable my Symfony2 plugin and that was the reason nothing Symfony related worked. I assumed it was enabled by default after installation. Oh well

    0 讨论(0)
  • 2021-02-14 09:24

    Clear the cache for development environment. It should fix it if service really exists. Navigate to your project dir in terminal and type:

    app/console ca:c

    0 讨论(0)
提交回复
热议问题