kerrialn/composer-json-parser

Access your composer.json as an object

1.1.0 2024-10-18 06:37 UTC

This package is auto-updated.

Last update: 2024-11-18 06:53:02 UTC


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) "^"
//          }
//        }

        
     }
    
}