kerrialn / composer-json-parser
Access your composer.json as an object
1.1.0
2024-10-18 06:37 UTC
Requires
- php: ^8.2
- doctrine/orm: ^3.1
Requires (Dev)
- phpunit/phpunit: ^9.5
- rector/rector: ^1.2
- symplify/easy-coding-standard: ^12
README
A tool that converts your composer.json file to an object and allows you to find any composer data quickly.
Install
composer require kerrialn/composer-json-parser
Usage
Basic usage
$composer = (new Parser()) ->withName() ->withRequire() ->withRequireDev() ->withAutoload() ->withMinimumStability() ->withScripts() ->getComposer(); // Will output a Composer object
Need to find a specific package?
declare(strict_types=1); namespace App; use ComposerJsonParser\Parser; class ExampleClass { public function someMethod() : void { $composer = (new Parser())->withRequire()->getComposer(); $doctrineOrmPackage = $composer->getRequire()->findFirst(fn (int $key, Package $package) => $package->getName() == 'php'); var_dump($doctrineOrmPackage); // object(ComposerJsonParser\Model\Package)#22 (3) { // ["name":"ComposerJsonParser\Model\Package":private]=> // string(12) "doctrine/orm" // ["type":"ComposerJsonParser\Model\Package":private]=> // enum(ComposerJsonParser\Enum\PackageTypeEnum::DEVELOPMENT) // ["packageVersion":"ComposerJsonParser\Model\Package":private]=> // object(ComposerJsonParser\Model\PackageVersion)#23 (2) { // ["version"]=> // float(3.1) // ["versionConstraints"]=> // string(1) "^" // } // } } }