Download the PHP package posternak/composer-file without Composer
On this page you can find all versions of the php package posternak/composer-file. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download posternak/composer-file
More information about posternak/composer-file
Files in posternak/composer-file
Package composer-file
Short Description The joyful way to programmatically read and edit composer.json and composer.lock in PHP — drop it into any script or automation.
License MIT
Informations about the package composer-file
composer-file
The joyful way to programmatically read and edit composer.json and composer.lock in PHP — drop it into any script or automation.
Requirements
- PHP 8.2+
Installation
Usage
The package ships two classes — one for each Composer file.
ComposerJsonFile — read and edit composer.json
Given a composer.json like:
You can read, add, update, remove and iterate over its dependencies:
A few rules to keep in mind:
setPackageVersionConstraint()updates only — it throws if the package isn't already declared inrequireorrequire-dev. UseaddPackage()for new ones.addPackage()adds only — it throws if the package is already declared anywhere. UsesetPackageVersionConstraint()to change an existing constraint.removePackage()is idempotent — calling it on a package that isn't declared is a no-op.
ComposerJsonFile extends Posternak\JsonFile\JsonFile, so you also get the generic has(), get(), set(), remove() and save() methods on it — handy for poking at any other field in the file (autoload, scripts, config, …).
ComposerLockFile — read installed versions from composer.lock
Both getInstalledPackageVersion() and getPackageInfo() throw RuntimeException if the package isn't installed.
Example: bump every package under a vendor prefix
A short script that updates every laravel/* constraint in a project's composer.json:
The same shape works for any "for each package, do X" automation — audits, batch upgrades, CI lockstep checks across multiple repos.
License
Released under the MIT License.