vaimo / composer-patches
Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added
Installs: 3 216 479
Dependents: 17
Suggesters: 0
Security: 0
Stars: 291
Watchers: 11
Forks: 41
Open Issues: 36
Type:composer-plugin
Requires
- php: >=7.0.0
- composer-plugin-api: ^1.0 || ^2.0
- composer-runtime-api: ^1.0 || ^2.0
- ext-json: *
- loophp/phposinfo: ^1.6
- seld/jsonlint: ^1.7.1
- vaimo/topological-sort: ^1.0
Requires (Dev)
- composer/composer: ^1.0 || ^2.0
- phpcompatibility/php-compatibility: >=9.1.1
- phpmd/phpmd: >=2.6.0
- sebastian/phpcpd: >=1.4.3
- squizlabs/php_codesniffer: >=2.9.2
- vaimo/composer-changelogs: ^1.0.0
- vaimo/composer-patches-proxy: 1.0.0
Conflicts
- dev-master
- 5.2.0
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.0
- 4.22.4
- 4.22.3
- 4.22.2
- 4.22.1
- 4.22.0
- 4.21.1
- 4.21.0
- 4.20.2
- 4.20.1
- 4.20.0
- 4.19.3
- 4.19.2
- 4.19.1
- 4.19.0
- 4.18.3
- 4.18.2
- 4.18.1
- 4.18.0
- 4.17.10
- 4.17.9
- 4.17.8
- 4.17.7
- 4.17.6
- 4.17.5
- 4.17.4
- 4.17.3
- 4.17.2
- 4.17.1
- 4.17.0
- 4.16.2
- 4.16.1
- 4.16.0
- 4.15.0
- 4.14.0
- 4.13.0
- 4.12.0
- 4.11.0
- 4.10.0
- 4.9.0
- 4.8.2
- 4.8.1
- 4.8.0
- 4.7.0
- 4.6.1
- 4.6.0
- 4.5.0
- 4.4.3
- 4.4.2
- 4.4.1
- 4.4.0
- 4.3.0
- 4.2.1
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.0
- 3.53.4
- 3.53.3
- 3.53.2
- 3.53.1
- 3.53.0
- 3.52.1
- 3.52.0
- 3.51.2
- 3.51.1
- 3.51.0
- 3.50.3
- 3.50.2
- 3.50.1
- 3.50.0
- 3.49.3
- 3.49.2
- 3.49.1
- 3.49.0
- 3.48.10
- 3.48.9
- 3.48.8
- 3.48.7
- 3.48.6
- 3.48.5
- 3.48.4
- 3.48.3
- 3.48.2
- 3.48.1
- 3.48.0
- 3.47.2
- 3.47.1
- 3.47.0
- 3.46.0
- 3.45.0
- 3.44.0
- 3.43.0
- 3.42.2
- 3.42.1
- 3.42.0
- 3.41.0
- 3.40.0
- 3.39.2
- 3.39.1
- 3.39.0
- 3.38.0
- 3.37.1
- 3.37.0
- 3.36.0
- 3.35.3
- 3.35.2
- 3.35.1
- 3.35.0
- 3.34.1
- 3.34.0
- 3.33.1
- 3.33.0
- 3.32.1
- 3.32.0
- 3.31.0
- 3.30.1
- 3.30.0
- 3.29.1
- 3.29.0
- 3.28.1
- 3.28.0
- 3.27.0
- 3.26.0
- 3.25.3
- 3.25.2
- 3.25.1
- 3.25.0
- 3.24.1
- 3.24.0
- 3.23.5
- 3.23.4
- 3.23.3
- 3.23.2
- 3.23.1
- 3.23.0
- 3.22.4
- 3.22.2
- 3.22.1
- 3.22.0
- 3.21.0
- 3.20.0
- 3.19.5
- 3.19.4
- 3.19.3
- 3.19.2
- 3.19.1
- 3.19.0
- 3.18.0
- 3.17.3
- 3.17.2
- 3.17.1
- 3.17.0
- 3.16.0
- 3.15.0
- 3.14.1
- 3.14.0
- 3.13.2
- 3.13.1
- 3.13.0
- 3.12.0
- 3.11.0
- 3.10.4
- 3.10.2
- 3.10.1
- 3.9.0
- 3.8.1
- 3.8.0
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.0
- dev-dependabot/composer/symfony/process-5.4.46
- dev-fix/false-positive-is-patcher-uninstall
- dev-release/4
- dev-release/3
- dev-fix/bundles-failure
- dev-devbox
This package is auto-updated.
Last update: 2024-12-06 21:03:55 UTC
README
Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level in package config or separate JSON file. Declaration-free mode (using embedded info within patch files) is available as well.
The way the patches are applied (the commands, pre-checks) by the plugin is fully configurable (including the actual commands that are executed to apply the patch) from the composer.json of the project.
Note that the plugin is kept on very old PHP version as legacy software is usually the most common context where patches are needed.
Full Documentation
- Basic Usage - Defining patches via configuration files or embedded metadata
- Advanced Usage - Advanced usage options when defining patches
- Configuration - Configuration options for the patch applier
- Commands - Details on the CLI commands that ship with the plugin
- Environment Variables - Environment variables to change plugin behavior
- Error Handling - Handling encountered errors
- Development - Details on the development workflow of the plugin
- Examples - Examples on usage of the plugin
- Changes - List of changes/fixes per plugin release
Quick Start
Composer packages can be targeted with patches in two ways:
- Embedded metadata (recommended default approach)
- JSON declaration and embedded (recommended for remote patches)
Usage: Embedded Metadata
{ "require": { "some/package-name": "1.2.3" }, "extra": { "patcher": { "search": "patches" } } }
Contents of patches/changes.patch:
This patch changes... absolutely everything @package some/package-name --- Models/Example.php.org +++ Models/Example.php @@ -31,7 +31,7 @@ */ protected function someFunction($someArg) { - $var1 = 123; + $var1 = 456; // patched by composer-patches /** * rest of the logic of the function */
As a good practice you might want to add a hint, that the file was patched.
Full list of tag options (that cover all features of the plugin can be found HERE).
Note that tags cover most of the features of the module so every explanation given for the json declaration of the patches applies for tags as well.
Usage: JSON Declaration
{ "require": { "some/package-name": "1.2.3" }, "extra": { "patches": { "some/package-name": { "This patch changes ... absolutely everything": "patches/changes.patch", "remote patch": "http://www.example.com/remote-patch.patch", "remote patch with checksum check": { "source": "http://www.example.com/other-patch.patch", "sha1": "5a52eeee822c068ea19f0f56c7518d8a05aef16e" } } } } }
Contents of patches/changes.patch:
--- Models/Example.php.org +++ Models/Example.php @@ -31,7 +31,7 @@ */ protected function someFunction($someArg) { - $var1 = 123; + $var1 = 456; /** * rest of the logic of the function */
Applier Configuration
The way patches are applied can be manipulated by changing the configuration of the patcher or by introducing additional patch appliers.
In most cases there should not be much of a need to reconfigure the module as it does ship with reasonable defaults. The appliers supported by default: patch, git.
More information on said topic can be found HERE.
Upgrades
When upgrading the module, one might encounter odd crashes about classes not being found or class constructor arguments being wrong.
This usually means that the class structure or constructor footprint in some of the classes have changed after the upgrade which means that the plugin might be running with some classes from the old and some classes from the new version.
Due to the fact that the patcher kicks in very late in the process of installing a project (before
auto-loader generation), developers are advised to re-execute composer install
.
Ideally, plugins should always be updated with explicit --no-plugins
flag added to the composer update
call to avoid issues that plugin usage with potentially mixed logic from two different plugin releases
being in use.