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.

  • File permissions? Might be readable for the web server but not from your command-line user – Javier C. H. Feb 05 '15 at 11:52
  • Good idea, but doesn't help: '$ sudo chmod -R 777 src/AppBundle/DependencyInjection/ $ sudo -u daemon php app/console cache:clear --env=dev' => same error. 'daemon' is the user my lampp server runs as. And the file has to be readable for symfony to be able to include the source into the error message... – chocokiko chocokiko Feb 05 '15 at 12:38

2 Answers2

0

Manually delete the cache (rm -rf style) and then warmup as root. Fix permissions and you're GTG.

Noy
  • 1,258
  • 2
  • 11
  • 28
  • Thanks, but... >.< `$ sudo rm -rf app/cache/* $ sudo chmod 777 app/cache $ sudo app/console cache:warmup` => same error For this problem the permissions on the files and the user concerned do not seem to matter. – chocokiko chocokiko Feb 05 '15 at 13:28
  • Did you do this for both prod and dev? – Noy Feb 05 '15 at 13:39
  • Yes i did. deleting the cache files by hand is no problem. But i cannot call the command to warm up the cache even as root. So it can't be a permission problem if root can't do it. The cache is gone so it's not a cache problem. It works when I comment out the call to ValidatorPass in my AppBundle.php but that defeats the purpose :) – chocokiko chocokiko Feb 05 '15 at 13:52
  • How about namespace issues? – Noy Feb 05 '15 at 15:19
  • That is exactly what Symfony tells me in the error message. But again it **works** on the server. I have been writing and testing validation files all day. Every time i test my forms this code gets called and is executed **just fine**. I checked multiple times: * Spelling in AppBundle.php * uses clause for Validation Pass * the line creating a new ValidationPass * The path of ValidationPass.php * it **is** found and displayed i n the error message but anyway * Spelling in ValidationPass.php * namespace Line * class definition line – chocokiko chocokiko Feb 05 '15 at 15:25
  • For the source see [above linked question](https://stackoverflow.com/questions/24064813/how-to-split-validation-yaml-files-in-symfony-2-5/24210501#24210501?newreg=7f83034e81454ca89f64226bbe38f552) – chocokiko chocokiko Feb 05 '15 at 15:30
0

I got really frustrated and do not know what I am doing wrong. I fixed it the REALLY dirty way...

My AppBundle.php now looks like this:

<?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));
    }
}

I really don't like this and would be very grateful for a real solution to the problem.