Monday, January 24, 2022

[FIXED] Composer doesn't autoload packages

Issue

I'm currently developing a framework but I couldn't figure out how am I going to set autoloading. First I created a package with sample class and composer.json. I've autoloaded that sample class by:

"autoload": {
    "classmap": [
      "libs/"
    ]
}

I've checked /vendor/mypackage/vendor/composer/autoload_classmap.php and confirmed that package's autoloader is working fine. But the problem is I can't reach that package's class from main app unless I directly include that package's autoload.php.

UPDATE

/vendor/foo/mypackage/composer.json

"autoload": {
  "psr-4": {
     "Http\\": "libs/"
   }
}

/vendor/foo/mypackage/libs/Request.php

namespace Http;
class Request {}

Solution

Solved it by myself. I just had to reinstall package whenever I change pacakge's composer.json.



Answered By - İbrahim Duran

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.