Php Symfony 2.6.4:名称空间问题?使用自定义验证程序传递会在命令行上引发异常,但在浏览器中可以正常工作

Php Symfony 2.6.4:名称空间问题?使用自定义验证程序传递会在命令行上引发异常,但在浏览器中可以正常工作,php,validation,symfony,symfony-2.6,php-5.6,Php,Validation,Symfony,Symfony 2.6,Php 5.6,我尝试了凯文·邦德对这个问题的解决方案。在浏览器中使用应用程序时,它工作正常,但在控制台命令上引发以下异常。我三次检查了拼写错误的语法。。。 代码与上述链接问题中的代码完全相同。我唯一更改的是bundle名称 $ php app/console <? // src/AppBundle/DependencyInjection/Compiler/ValidatorPass.php namespace AppBundle\DependencyInjection\Compiler; use S

我尝试了凯文·邦德对这个问题的解决方案。在浏览器中使用应用程序时,它工作正常,但在控制台命令上引发以下异常。我三次检查了拼写错误的语法。。。 代码与上述链接问题中的代码完全相同。我唯一更改的是bundle名称

$ php app/console 
<?
// src/AppBundle/DependencyInjection/Compiler/ValidatorPass.php
namespace AppBundle\DependencyInjection\Compiler;

use Symfony\Component\Finder\Finder;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

class ValidatorPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $validatorBuilder = $container->getDefinition('validator.builder');
        $validatorFiles = array();
        $finder = new Finder();

        foreach ($finder->files()->in(__DIR__ . '/../../Resources/config /validation') as $file) {
            $validatorFiles[] = $file->getRealPath();
        }

        $validatorBuilder->addMethodCall('addYamlMappings', array($validatorFiles));
    }
}


[RuntimeException]                                     
The autoloader expected class "AppBundle\DependencyInjection\Compiler\ValidatorPass"
to be defined in file "/home/mt/devel/netsite/phpprojekte/circle8/events/src/AppBundle/DependencyInjection/Compiler/ValidatorPass.php".
The file was found but the class was not in it, the class name or namespace probably has a typo.                                                                                                                                                     
我尝试了我能想象到的任何调试方法。请帮忙。 现在我唯一能做的就是在使用控制台时在我的AppBundle.php中注释掉调用,在使用浏览器时再注释回来

  • 用户和文件权限似乎并不重要
  • 清空缓存没有帮助
到目前为止已经尝试过的事情:
  • 修复类的权限

    $sudo chmod-R 777 src/AppBundle/DependencyInjection/
    $sudo-u守护进程php应用程序/控制台缓存:clear--env=dev
    =>同样的错误

  • 删除缓存并尝试预热

    $sudo rm-rf应用程序/cache/*
    $sudo chmod 777应用程序/缓存
    $sudo应用程序/控制台缓存:预热
    =>同样的错误


手动删除缓存(rm-rf样式),然后作为根用户预热。修复权限,你就是GTG。

我真的很沮丧,不知道我做错了什么。我用肮脏的方式把它修好了

我的AppBundle.php现在如下所示:

<?php

namespace AppBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;

use Symfony\Component\Finder\Finder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

//use AppBundle\DependencyInjection\Compiler\ValidatorPass;

class AppBundle extends Bundle
{
    // ...

    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new ValidatorPass());
    }

    // ...
}

class ValidatorPass implements CompilerPassInterface {

    public function process(ContainerBuilder $container)
    {
        $validatorBuilder = $container->getDefinition('validator.builder');
        $validatorFiles = array();
        $finder = new Finder();

        foreach ($finder->files()->in(__DIR__ . '/Resources/config/validation') as $file) {
            $validatorFiles[] = $file->getRealPath();
        }

        $validatorBuilder->addMethodCall('addYamlMappings', array($validatorFiles));
    }
}

文件权限?web服务器可能可读,但命令行用户不可读好主意,但没有帮助:“$sudo chmod-R 777 src/AppBundle/DependencyInjection/$sudo-u daemon php app/console cache:clear--env=dev'=>相同错误。”daemon'是我的lampp服务器运行时的用户。文件必须可读,symfony才能将源代码包含到错误消息中…谢谢,但是…><代码>$sudo rm-rf app/cache/*$sudo chmod 777 app/cache$sudo app/console cache:warmup
=>对于此问题,文件和相关用户的权限似乎并不重要。您对产品和开发都这样做了吗?是的,我这样做了。手动删除缓存文件没有问题。但是我不能调用命令来预热缓存,即使是作为root用户。因此,如果root用户不能做到这一点,就不会有权限问题。缓存已消失,因此不存在缓存问题。当我在AppBundle.php中注释掉对ValidatorPass的调用时,它就起作用了,但这违背了目的:)名称空间问题如何?这正是Symfony在错误消息中告诉我的。但它同样在服务器上工作。我整天都在编写和测试验证文件。每次我测试我的表单时,都会调用这段代码,并且执行得很好。我检查了多次:*AppBundle.php中的拼写*用于验证通过的uses子句*创建新验证通过的行*ValidationPass.php的路径*在错误消息中找到并显示,但无论如何*ValidationPass.php中的拼写*命名空间行*类定义行
<?php

namespace AppBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;

use Symfony\Component\Finder\Finder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

//use AppBundle\DependencyInjection\Compiler\ValidatorPass;

class AppBundle extends Bundle
{
    // ...

    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new ValidatorPass());
    }

    // ...
}

class ValidatorPass implements CompilerPassInterface {

    public function process(ContainerBuilder $container)
    {
        $validatorBuilder = $container->getDefinition('validator.builder');
        $validatorFiles = array();
        $finder = new Finder();

        foreach ($finder->files()->in(__DIR__ . '/Resources/config/validation') as $file) {
            $validatorFiles[] = $file->getRealPath();
        }

        $validatorBuilder->addMethodCall('addYamlMappings', array($validatorFiles));
    }
}