0

I tried Kevin Bond's Solution on this question. It works fine when using the application in the browser but throws the following exception on console commands. I triplechecked my syntax for typos... The code is exactly the same as in the above linked question. The only thing I changed is the bundle name.

$ 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.                                                                                                                                                     

Exception trace:

() at /.../vendor/symfony/symfony/src/Symfony/Component/Debug/DebugClassLoader.php:186
Symfony\Component\Debug\DebugClassLoader->loadClass() at n/a:n/a
spl_autoload_call() at /.../src/AppBundle/AppBundle.php:17
AppBundle\AppBundle->build() at /.../app/bootstrap.php.cache:2632
Symfony\Component\HttpKernel\Kernel->prepareContainer() at /.../app/bootstrap.php.cache:2611
Symfony\Component\HttpKernel\Kernel->buildContainer() at /.../app/bootstrap.php.cache:2564
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /home/.../app/bootstrap.php.cache:2344
Symfony\Component\HttpKernel\Kernel->boot() at /.../vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:70
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /.../vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
Symfony\Component\Console\Application->run() at /.../app/console:27

I tried any way of debugging I could imagine. Please help. Only thing I can do for now is commenting out the call in my AppBundle.php when using console and commenting it back in when using the browser.

  • The user and the file permissions don't seem to matter.
  • Emptying the cache does not help.

Things tried so far:

  • Fix permissions of class

    $ sudo chmod -R 777 src/AppBundle/DependencyInjection/ $ sudo -u daemon php app/console cache:clear --env=dev => same error.

  • Delete cache & try to warmup

    $ sudo rm -rf app/cache/* $ sudo chmod 777 app/cache $ sudo app/console cache:warmup => same error.

4

2 回答 2

0

手动删除缓存(rm -rf 样式),然后以 root 身份进行预热。修复权限,你就是 GTG。

于 2015-02-05T12:50:23.557 回答
0

我真的很沮丧,不知道我做错了什么。我以非常肮脏的方式修复了它...

我的 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));
    }
}

我真的不喜欢这样,非常感谢能真正解决这个问题。

于 2015-02-06T12:08:53.943 回答