-2

I added the Symfony Dependency injection container (composer require symfony/dependency-injection): https://symfony.com/doc/current/components/dependency_injection.html

Run the: composer dump-autoload -o to reorganize classes (/www/vendor/composer/autoload_classmap.php file is empty after installing new libraries via composer).

have this running in my init.php file:

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

and breaks on compile().

What am I missing?

Cannot find any lead to resolve this problem.

What am I doing wrong?

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

composer.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"
    }
}
Imnotapotato
  • 5,308
  • 13
  • 80
  • 147
  • 1
    i dont understand why are you doing something like this, why are you using "symfony/dependency-injection" if you arent using whole symfonmy framework – Zeljka Jan 21 '19 at 09:37
  • Because I want to use Symfonys DIC, rather than Pimple/PHP DI/DICE/ect'. How is this bad? @Zeljka – Imnotapotato Jan 21 '19 at 09:39
  • Maybe Im wrong, but for me that is insane.. Its ok to use some symfony components (libraries).. But dependency injection is something else, if you know whats is it, how to use it, OOP .. thats little bit crazy.. sorry thats my opinion – Zeljka Jan 21 '19 at 09:44
  • 3
    I think i mentioned this before, but if your goal is to deliver a working app, then use the full framework (symfony, or laravel), with all the fantastic documentation and community support that comes with it. Once you have a few years under your belt, you will have built up the requisite knowledge to wire up components yourself to better solve your problems if the default is lacking. At the moment you simply dont have the level of understanding to do this. – Steve Jan 21 '19 at 11:51
  • 1
    The benefit of wireing up 3rd partly components is you can define your own architecture. Defining your own architecture is hard and requires experiance you dont have. Thats one of the prime benefits of a framework - solving the architecture problem for you. – Steve Jan 21 '19 at 11:58
  • 1
    If you just want a higher level understanding of how it all fits together, so you dont feel so lost when working with a framework, then follow this rather good tutorial from symfony: https://symfony.com/doc/current/create_framework/index.html When you are done, throw out your code and build your project in the framework proper, so you have access to the community and documentation you will need going forward – Steve Jan 21 '19 at 12:00

1 Answers1

2

Reason seems to be pretty simple: you have required symfony/dependency-injection but Symfony\Component\Config\Resource\ClassExistenceResource obviously belongs to symfony/config. If you will review dependencies of symfony/dependency-injection you will see that it requires symfony/config only as dev dependency. Hence simple inclusion of symfony/config should fix the issue.

Reason of this error is another question and probably should be reported to Symfony developers.

Flying
  • 4,422
  • 2
  • 17
  • 25