Strategy to override a class in a library installed with Composer

前端 未结 4 1898
抹茶落季
抹茶落季 2020-12-13 00:50

I am using Codeigniter and Composer. One of the requirements is PHPExcel. Now I need to change a function in one of the classes. What should be the best strategy to do it? S

4条回答
  •  我在风中等你
    2020-12-13 01:19

    Adding these last 2 lines to the autoload section of my composer.json is what worked for me when I wanted to override just one file within the vendors directory:

    "autoload": {        
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        },
        "exclude-from-classmap": ["vendor/somepackagehere/blah/Something.php"],
        "files": ["app/Overrides/Something.php"]
    },
    

    Remember that the namespace within app/Overrides/Something.php needs to match whatever the original was in vendor/somepackagehere/blah/Something.php.

    Remember to run composer dump-autoload after editing the composer.json.

    Docs: https://getcomposer.org/doc/04-schema.md#files

提交回复
热议问题