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

WBOY
Release: 2023-03-02 12:18:02
Original
1810 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!