PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 2, 2022

[FIXED] PHP composer, don't lose package code changes on update

 March 02, 2022     composer-php, php, save     No comments   

Issue

I am working on a project which requires many edits to be made on the required packages. Everything works just fine until an update comes on the horizon. Once a package gets updated, all made changes on it are instantly replaced with the newer version(even there is no actual update on the updated file).

My question is, how can I keep my edits over the modified packages and still be able to run composer update without the fear of losing my edits and starting all over again.


Solution

Short answer: You can't. The update will always pull the code as it exists in the repository and overwrite the local copy. That's how packages work.

Longer answer: You can't. Editing packages is a bad idea. If you find you need to edit the package you are implementing it wrong as there should be no need to modify that code. If you need additional functionality you can:

  1. Add a wrapper. Create a class, called a facade, that implements that package but with the changed functionality you desire.
  2. Fork it and add new functionality and see if it can be added to the package. The functionality you desire may be useful to others and could be merged into the package if the author agrees. Then it will exist for all of your future updates.
  3. Fork it, make your changes, and include that. If for some reason the first two options don't work you can make your own fork of the project and put your changes there. Then whenever you need to update the package to get the latest code you can create a new fork and migrate/merge your changes to it.


Answered By - John Conde
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing