zfcampus / zf-apigility-admin

Admin API and UI for Apigility
BSD 3-Clause "New" or "Revised" License
90 stars 64 forks source link

New API modules should be added to autoload/psr-4 section in composer.json #372

Open kaloyan-raev opened 7 years ago

kaloyan-raev commented 7 years ago

Currently we have the following autoload section in the composer.json of the Apigility Skeleton Application:

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

Creating a new API module (e.g. "Test") in the Admin UI creates a new ZF module, but the composer.json is not updated with its source folder. I would expect the autoload section to be updated like this:

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

Respectively, deleting an API module should update the autoload/psr-4 section too.

ezimuel commented 7 years ago

@kaloyan-raev we managed the module autoloading using the Zend\Autoloader in Module.php. Basically, when you create a new API (module), Apigility builds a Module.php file containing the following code:

public function getAutoloaderConfig()
    {
        return [
            'ZF\Apigility\Autoloader' => [
                'namespaces' => [
                    __NAMESPACE__ => __DIR__ . '/src',
                ],
            ],
        ];
    }

This function is consumed by the zend-loader to load load the Module/API files. We didn't use the composer.json autoloading because this will require a composer execution to update the vendor/autoload.php file.

kaloyan-raev commented 7 years ago

OK. I see...

We didn't use the composer.json autoloading because this will require a composer execution to update the vendor/autoload.php file.

Is this that bad?

My point is that having the Zend modules explicitly declared in the autoload section of composer.json would help build better IDE tooling.

michalbundyra commented 7 years ago

@kaloyan-raev you can use https://github.com/zfcampus/zf-composer-autoloading, it is standalone tool to enable module's composer autoloading

weierophinney commented 4 years ago

This repository has been closed and moved to laminas-api-tools/api-tools-admin; a new issue has been opened at https://github.com/laminas-api-tools/api-tools-admin/issues/13.