eta-orionis/composer-json-manipulator

Package to load, merge and save composer.json file(s). Cleaned up from symplify/composer-json-manipulator

1.0.1 2023-04-07 18:09 UTC

This package is not auto-updated.

Last update: 2024-11-16 23:49:11 UTC


README

  • load composer.json as an object
  • manipulate using fluent API
  • save it back to a composer.json file

Install

composer require eta-orionis/composer-json-manipulator

Usage

namespace App;

use EtaOrionis\ComposerJsonManipulator\ComposerJson;

class SomeClass
{
    public function run(): void
    {
        $composerJson = ComposerJson::fromFile(getcwd() . '/composer.json');

        // Add a PSR-4 namespace
        $autoLoad = $composerJson->getAutoload();
        $autoLoad['psr-4']['Cool\\Stuff\\'] = './lib/';
        
        $composerJson
            ->setAutoload($autoLoad)
            ->save(getcwd() . '/composer.json');
    }
}