Composer autoloading inside apigility

When we created “New API” (for example, “Status”) via admin panel of apigility it is created new module inside “module” directory of our project. There is “public function getAutoloaderConfig()…” inside new module “Status” inside Module.php.

Is this good in 2019?

How can I put together apigility and PSR-4?

I am trying to figured out how apigility works and and what it does when we do something via admin panel.

If you didn’t has the psr-4 config for “Status” module in composer.json, you can update your module class with remove the getAutoloaderConfig() method, then update composer.json under autoload -> psr4

    "autoload": {
        "psr-4": {
            "Falk\\": "module/Falk/src"
        }
    },

then run composer update

1 Like

It seems this is just the only way to put together apigility and psr-4. And psr-4 can’t be managed from the admin panel.

PSR-4 describes autoloading classes from file paths. Which autoloader should be used or where the configuration comes from is not a part of the specification.
Composer is one option, another can be the getAutoloaderConfig method in the module class.

1 Like

@froschdesign hi, well, for autoloading, we can either use the Composer autoloading feature, or the Laminas/Loader/Autoloader module with the getAutoloaderConfig.
BUT, as far as i know, based on the documentation, we can either use Composer autoloading feature (using the use_laminas_loader = false option) OR the Laminas/Loader/Autoloader feature (using the use_laminas_loader = true option).
It doesn’t seem to have the capability to use both options (true and false) in the same application.

If we choose to use the Composer Autoloader feature, then we will have to remove the getAutoloaderConfig method in the module class AND move the module class to the src/ directory. I don’t know if it is doable with the API Tools Admin UI. Will API Tools Admin recreate another module class in the module root if there’s none there even if the module is autoloaded ?

4 years later…Composer is the way to go. Ignore everything else, because the laminas-loader will be dropped.

Perfect! Thank you for the confirmation

Envoyé à partir de Outlook pour Android