Using Composer's Autoload

后端 未结 6 632
挽巷
挽巷 2020-11-30 19:55

I have been looking around the net with no luck on this issue. I am using composer\'s autoload with this code in my composer.json:

\"autoload\":         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 20:18

    The composer documentation states that:

    After adding the autoload field, you have to re-run install to re-generate the vendor/autoload.php file.

    Assuming your "src" dir resides at the same level as "vendor" dir:

    • src
      • AppName
    • vendor
    • composer.json

    the following config is absolutely correct:

    {
        "autoload": {
            "psr-0": {"AppName": "src/"}
        }
    }
    

    but you must re-update/install dependencies to make it work for you, i.e. run:

    php composer.phar update
    

    This command will get the latest versions of the dependencies and update the file "vendor/composer/autoload_namespaces.php" to match your configuration.

    Also as noted by @Dom, you can use composer dump-autoload to update the autoloader without having to go through an update.

提交回复
热议问题