# Composer autoloading inside apigility

**URL:** <https://discourse.laminas.dev/t/composer-autoloading-inside-apigility/1107>\
**Category:** API Tools\
**Tags:** apigility\
**Created:** [July 8, 2019, 4:55pm UTC](https://discourse.laminas.dev/t/composer-autoloading-inside-apigility/1107 "2019-07-08T16:55:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![testuser](https://avatars.discourse-cdn.com/v4/letter/t/e495f1/32.png) [@testuser](https://discourse.laminas.dev/u/testuser)\
**Post date:** [July 8, 2019, 4:55pm UTC](https://discourse.laminas.dev/t/composer-autoloading-inside-apigility/1107/1 "2019-07-08T16:55:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![testuser](https://avatars.discourse-cdn.com/v4/letter/t/e495f1/32.png) [@testuser](https://discourse.laminas.dev/u/testuser)\
**Post date:** [July 8, 2019, 4:57pm UTC](https://discourse.laminas.dev/t/composer-autoloading-inside-apigility/1107/2 "2019-07-08T16:57:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![samsonasik](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/samsonasik/32/777_2.png) [@samsonasik](https://discourse.laminas.dev/u/samsonasik)\
**Post date:** [July 9, 2019, 4:29pm UTC](https://discourse.laminas.dev/t/composer-autoloading-inside-apigility/1107/3 "2019-07-09T16:29:38Z")

</div>

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`

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

```

then run `composer update`

---

<div class="post-metadata">

**Author:** ![testuser](https://avatars.discourse-cdn.com/v4/letter/t/e495f1/32.png) [@testuser](https://discourse.laminas.dev/u/testuser)\
**Post date:** [July 9, 2019, 5:07pm UTC](https://discourse.laminas.dev/t/composer-autoloading-inside-apigility/1107/4 "2019-07-09T17:07:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [July 9, 2019, 7:13pm UTC](https://discourse.laminas.dev/t/composer-autoloading-inside-apigility/1107/5 "2019-07-09T19:13:05Z")

</div>

> [@testuser](#):
>
> It seems this is just the only way to put together apigility and psr-4.

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.

---

<div class="post-metadata">

**Author:** ![haclong](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/haclong/32/1634_2.png) [@haclong](https://discourse.laminas.dev/u/haclong)\
**Post date:** [December 24, 2023, 1:53pm UTC](https://discourse.laminas.dev/t/composer-autoloading-inside-apigility/1107/6 "2023-12-24T13:53:09Z")

</div>

@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 ?

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [January 3, 2024, 8:26pm UTC](https://discourse.laminas.dev/t/composer-autoloading-inside-apigility/1107/7 "2024-01-03T20:26:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![haclong](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/haclong/32/1634_2.png) [@haclong](https://discourse.laminas.dev/u/haclong)\
**Post date:** [January 4, 2024, 8:45am UTC](https://discourse.laminas.dev/t/composer-autoloading-inside-apigility/1107/8 "2024-01-04T08:45:31Z")

</div>

Perfect! Thank you for the confirmation

Envoyé à partir de [Outlook pour Android](https://aka.ms/AAb9ysg)
