简体   繁体   English

symfony2 CLI [Symfony \\ Component \\ Debug \\ Exception \\ ContextErrorException]

[英]symfony2 CLI [Symfony\Component\Debug\Exception\ContextErrorException]

I'm having a problem whilst trying to create a command with Symfony2's Console component, in a full Symfony stack app. 在完整的Symfony堆栈应用程序中尝试使用Symfony2的控制台组件创建命令时遇到问题。

If i try to pass my services in via DI, the command throws the following error when i try to run it: 如果我尝试通过DI传递我的服务,该命令在我尝试运行它时会抛出以下错误:

[Symfony\Component\Debug\Exception\ContextErrorException]  
Notice: Trying to get property of non-object

If I create the command with ContainerAwareCommand and try to get my service with 如果我使用ContainerAwareCommand创建命令并尝试使用我的服务

$this->getContainer()->get('mtgu.api.card.list.response.data'); $这个 - > getContainer() - >获取( 'mtgu.api.card.list.response.data');

I get 我明白了

  [LogicException]                                                               
  The container cannot be retrieved as the application instance is not yet set.

My service is defiantly being loaded, as its used in a front end controller. 正如前端控制器中使用的那样,我的服务正在被加载。 This problem gets stranger, as if I pass a repository service - I don't get this problem! 这个问题变得陌生,好像我通过了存储库服务 - 我没有遇到这个问题!

Is there some trick to setting up a service to be passible by this? 是否有一些技巧可以将服务设置为可通过? Or have I messed up my configuration somehow? 或者我以某种方式搞砸了我的配置?

Im "autoloading" all my services by doing this in my DI Extension rather than including them all through the the main services.yml. 我通过在我的DI扩展中执行此操作来“自动加载”我的所有服务,而不是通过主要的services.yml将它们全部包含在内。 I thought this or the ordering of the yml includes maybe effecting it - but I have tried manually including everything but still no joy! 我认为这或yml的顺序包括可能影响它 - 但我已经尝试手动包括一切但仍然没有快乐!

$finder = new Finder();
$finder->name('services.yml');
/**
* @var $file SplFileInfo
*/
foreach($finder->in(__DIR__.'/../') as $file) {
$loader = new Loader\YamlFileLoader($container, new FileLocator($file->getPath()));
$loader->load('services.yml');
}

Vendor/Bundle/Command/services.yml 供应商/包/命令/ services.yml

services:

mtgu.command.slugify:
    class: MightyStudios\MtguBundle\Command\SlugifyCommand
    tags:
        - { name: console.command }
    arguments:
      - @mtgu.api.card.list.response.data

I think this maybe just some config issue, but Google has failed me to find the answer! 我想这可能只是一些配置问题,但谷歌让我无法找到答案! Has anyone else run into this problem and can they shed any light!? 有没有其他人遇到这个问题,他们可以放弃任何光明!?

Many thanks 非常感谢

A better structure would be to put your services files in the Resources/config directory of your bundle (See also all core bundles). 更好的结构是将您的服务文件放在捆绑包的Resources/config目录中(另请参阅所有核心捆绑包)。 However, that's aside. 但是,那不在意。

The problem is described by the exception: The container cannot be retrieved as the application instance is not yet set. 该问题由异常描述: 由于尚未设置应用程序实例,因此无法检索容器。 Which is thrown in the ContainerAwareCommand#getContainer() method when $this->application is null . $this->applicationnull时,在ContainerAwareCommand#getContainer()方法中抛出哪个。 The application is set in the first line of the Application#add() method. 应用程序设置在Application#add()方法的第一行。

This means that you call $this->getContainer() before you add the command to the application. 这意味着在将命令添加到应用程序之前调用$this->getContainer() Maybe you use it in your constructor? 也许你在构造函数中使用它?

If so, remove it and only use the container in Command#execute() , Command#interact() or Command#initialize() . 如果是这样,请将其删除,只使用Command#execute()Command#interact()Command#initialize()的容器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何捕获[Symfony \\ Component \\ Debug \\ Exception \\ ContextErrorException] - How to catch [Symfony\Component\Debug\Exception\ContextErrorException] Symfony2 + Doctrine-fixtures + DB2:[Symfony \\ Component \\ Debug \\ Exception \\ ContextErrorException]警告:db2_bind_param():描述参数失败 - Symfony2 + Doctrine-fixtures + DB2: [Symfony\Component\Debug\Exception\ContextErrorException] Warning: db2_bind_param(): Describe Param Failed Symfony2 Faker填充ContextErrorException - Symfony2 Faker Populate ContextErrorException 从Symfony2捕获ContextErrorException - Catch ContextErrorException from Symfony2 Symfony2 ContextErrorException:警告:filemtime():stat失败 - Symfony2 ContextErrorException: Warning: filemtime(): stat failed 自定义身份验证提供程序中的Symfony2 ContextErrorException - Symfony2 ContextErrorException in Custom Authentication Provider Vagrant + Symfony2环境ContextErrorException怪异 - Vagrant + Symfony2 Environment ContextErrorException Weirdness “Symfony\\Component\\Debug\\Exception\\FatalThrowableError” - The "Symfony\Component\Debug\Exception\FatalThrowableError" 将应用程序上载到共享主机后,Symfony2会抛出ContextErrorException - Symfony2 throws ContextErrorException after uploading the application to shared host symfony2:生产服务器上的ContextErrorException“用于反序列化的错误数据格式” - symfony2: ContextErrorException on production server “Erroneous data format for unserializing”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM