Home  >  Article  >  Backend Development  >  How to use composer to replace a class in a third-party package

How to use composer to replace a class in a third-party package

WBOY
WBOYOriginal
2016-12-01 01:27:391841browse

Fox example: A third-party package used by
has a FlarumCoreUser class
Now I have written a FlarumCoreUser class
I want composer to use the Userclass I created myself when it loads automatically. , how to do it?

I have found a method. The namespace is still the original namespace of that class, so composer will automatically load the class I wrote

<code class="php">"autoload": {
    "classmap": [
        "vendor/path/to/src/User.php"
    ]
},</code>

Reply content:

Fox example: A third-party package used by
has a FlarumCoreUser class
Now I have written a FlarumCoreUser class
I want composer to use the Userclass I created myself when it loads automatically. , how to do it?

I have found a method. The namespace is still the original namespace of that class, so composer will automatically load the class I wrote

<code class="php">"autoload": {
    "classmap": [
        "vendor/path/to/src/User.php"
    ]
},</code>

There is a third-party library. You have to rewrite it and load your rewritten code. What does this mean?
If your third-party library is hosted on github, you fork the project, then clone it locally, and modify it Push to github, and then quote the address of your fork project in composer.json.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn