问题
i was working in my application and i'm using some packages, but i have the necessity to change or add some logic in it. I read that we must don't change code of the packages when they are on the vendor directory, but i didn't find how i can do instead. any ideas?
回答1:
This differs from package to package.
The one-size-fits-all solution is to fork the package, essentially copying it and modifying code in the replicated version.
Often, packages may offer methods to extend or build on their work. This will be very dependent on the package, and I'd suggest you refer to it's documentation for more help down that front.
If you take the first route, you must be aware of some things:
The second you fork a package, you will be responsible for maintaining it.
If you fork the package, you will end up with a package that cannot be maintained by it's original author because you have changed it. If you keep it in composer and edit the original package, it will get overwritten the next time you run composer update
. Additionally, if you're versioning your work, your package modifications will not be carried across. but if you fork it properly, it will have no ties to the original package. This means that your package may become outdated unless you spend effort maintaining it's updates.
If you're using composer, this will most likely involve forking the original package repo and modifying code in that repo instead. (Do NOT do this to just your local package files). This is probably the best solution, because it means if the original repo has made changes to it's package, you can perform merges with your repo to bring their updates into your code (whilst not affecting your changes unless the update does directly interact with the code you're modfying). From there, add your new forked repo into your composer.json
file and work with that.
来源:https://stackoverflow.com/questions/21727503/how-to-edit-package-on-vendor-laravel-4