Trying to organize the folder structure in the Silex application.

$loader = require_once __DIR__.'/../vendor/autoload.php'; $app = new Silex\Application(); $app['debug'] = true; $app['autoloader'] = $loader; $loader->add('Core', __DIR__ . '/../src'); $loader->add('Core\services', __DIR__ . '/../src/services'); $app['subscriber_service'] = $app->share(function() { return new Core\services\Subscriber(); }); 

Subscriber.php is located in ../src/services/

 namespace Core\services; class Subscriber { } 

When trying to call new Core \ services \ Subscriber (); catching Not Found Exception. In addition to Yii2, I did not work anywhere with the namespace, and in yii everything is simple and you don’t think about autoloading. Tell me how to properly organize the structure of the application on Silex and autoloading classes.

UPD
Looked at var_dump ($ loader) after adding nejmspesov. For neymspeysov framework I see ways, but for my own this, without ways

 'C' => array(2) { 'Core' => array(1) { ... } 'Core\services' => array(1) { ... } } 

UPD 2
Added to composer.json

 "autoload": { "psr-4": {"Core\\": "src/"} } 

Now classes are loaded, but I would like to be able to add namesplays via PHP.

    1 answer 1

    You need to add a PSR-4 standard loader

     $loader->addPsr4('Core', __DIR__ . '/../src'); 

    and the $loader->add() method adds a PSR-0 loader