代码之家  ›  专栏  ›  技术社区  ›  Imnotapotato

未捕获错误:找不到类“symfony\component\config\resource\classexistenceresource”

  •  -2
  • Imnotapotato  · 技术社区  · 6 年前

    我添加了symfony依赖注入容器( composer require symfony/dependency-injection ): https://symfony.com/doc/current/components/dependency_injection.html

    运行: composer dump-autoload -o 重新组织类( /www/vendor/composer/autoload_classmap.php 通过composer安装新库后,文件为空)。

    把这个放在我的 init.php 文件:

    use Symfony\Component\DependencyInjection\ContainerBuilder;
    use Symfony\Component\DependencyInjection\Reference;
    use MyApp\Core\App; 
    use MyApp\Core\Database; 
    use MyApp\Models\SystemUser; 
    use MyApp\Models\Customer; 
    use MyApp\Core\Log;
    $container = new ContainerBuilder();
    
        $container->autowire( Log::class );
        $container->autowire( Database::class );
        $container->autowire( SystemUser::class );
        $container->autowire( Customer::class );
        $container->autowire( App::class )
            ->setPublic( true );
    
        $container->compile();
    
        $app = $container->get( App::class );
    

    打破 compile() .

    我错过了什么?

    找不到任何线索来解决此问题。

    我做错什么了?

    PHP Fatal error:  Uncaught Error: Class 'Symfony\Component\Config\Resource\ClassExistenceResource' not found in /www/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:385
    Stack trace:
    #0 /www/vendor/symfony/dependency-injection/Compiler/AutowirePass.php(225): Symfony\Component\DependencyInjection\Compiler\AutowirePass->createTypeNotFoundMessage(Object(Symfony\Component\DependencyInjection\TypedReference), 'argument "$db" ...')
    #1 /www/vendor/symfony/dependency-injection/Compiler/AutowirePass.php(256): Symfony\Component\DependencyInjection\Compiler\AutowirePass->Symfony\Component\DependencyInjection\Compiler\{closure}()
    #2 /www/vendor/symfony/dependency-injection/Compiler/AutowirePass.php(165): Symfony\Component\DependencyInjection\Compiler\AutowirePass->autowireMethod(Object(ReflectionMethod), Array)
    #3 /www/vendor/symfony/dependency-injection/Compiler/AutowirePass.php(123): Symfony\Component\DependencyInjection\Compiler\AutowirePass->autowireCalls(Object(ReflectionClass), true)
    #4 /www/vendor/symfony/dependency-injection/Compiler/AutowirePass.php(71): Symfony\Component\DependencyInjection\Compiler\AutowirePass->doProcessValue(Object(Symfony\Component\DependencyInjection\Definition), true)
    #5 /www/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php(82): Symfony\Component\DependencyInjection\Compiler\AutowirePass->processValue(Object(Symfony\Component\DependencyInjection\Definition), true)
    #6 /www/vendor/symfony/dependency-injection/Compiler/AutowirePass.php(100): Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue(Array, true)
    #7 /www/vendor/symfony/dependency-injection/Compiler/AutowirePass.php(71): Symfony\Component\DependencyInjection\Compiler\AutowirePass->doProcessValue(Array, true)
    #8 /www/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php(46): Symfony\Component\DependencyInjection\Compiler\AutowirePass->processValue(Array, true)
    #9 /www/vendor/symfony/dependency-injection/Compiler/AutowirePass.php(52): Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
    #10 /www/vendor/symfony/dependency-injection/Compiler/Compiler.php(95): Symfony\Component\DependencyInjection\Compiler\AutowirePass->process(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
    #11 /www/vendor/symfony/dependency-injection/ContainerBuilder.php(750): Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
    #12 /www/myapp/init.php(50): Symfony\Component\DependencyInjection\ContainerBuilder->compile()
    #13 /www/public/index.php(10): require_once('/www/myapp/...')
    #14 {main}
      thrown in /www/vendor/symfony/dependency-injection/Compiler/AutowirePass.php on line 385
    

    作曲家JSON

    {
        "name": "potato/www",
    
        "authors": [
            {
                "name": "potato potato",
                "email": "potato@MyApp.com"
            }
        ],
    
        "require": {
            "monolog/monolog": "^1.24",
            "filp/whoops": "^2.3",
            "symfony/dependency-injection": "^4.2"
        }, 
    
        "autoload":{
            "psr-4": {
                "MyApp\\": "myapp"
            }
        },
        "require-dev": {
            "squizlabs/php_codesniffer": "^3.3"
        }
    }
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Flying    6 年前

    原因似乎很简单:你需要 symfony/dependency-injection 但是 Symfony\Component\Config\Resource\ClassExistenceResource 显然属于 symfony/config . 如果您要检查 symfony/依赖注入 你会发现它需要 SimfON/CONFIG 仅作为 dev 附属国。因此简单地包括 SimfON/CONFIG 应该解决这个问题。

    此错误的原因是另一个问题,可能应该向symfony开发人员报告。

    推荐文章