It's not possible to set up a file structure in Silex.



  • I'm trying to set up a file structure in Silex annex.

    $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 in ../src/services/

    namespace Core\services;

    class Subscriber
    {

    }

    In an attempt to cause new Core/services/Subscriber(); catch Not Foundion Exception.
    Except for Yii2 there's a namespace working, and in yii, everything just doesn't think about the auto loading. Specify how to properly organize the Silex application structure and class loading.

    UPD
    Looked at var_dump($loader) after adding nemspes. There's a way for the nymspeys of the Framworth, and for theirs, there's no way.

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

    UPD 2
    Added to composer.json

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

    Classes are now loaded, but I would like to be able to add nemspeis through PHP.



  • You need to add a boater to standard PSR-4.

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

    a by $loader->add() Added by PSR-0.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2