public function addPackage(array $packageNames, $areDevPackages = false)
    {
        $fs = new Filesystem();
        $file = $this->embeddedComposer->getExternalComposerFilename();

        if ($fs->exists($file) === false) {
            $fs->dumpFile($file, "{\n}\n");
        }

        if (filesize($file) === 0) {
            $fs->dumpFile($file, "{\n}\n");
        }

        $json = new JsonFile($file);

        $requirements = $this->formatPackageNames($packageNames);
        $versionParser = new VersionParser();

        foreach ($requirements as $constraint) {
            $versionParser->parseConstraints($constraint);
        }

        $composerDefinition = $json->read();

        $requireKey = $areDevPackages ? 'require-dev' : 'require';

        foreach ($requirements as $package => $version) {
            $composerDefinition[$requireKey][$package] = $version;
        }

        $json->write($composerDefinition);

        return $composerDefinition[$requireKey];
    }
public function addPackage(array $packageNames, $areDevPackages = false)
    {
        $fs = new Filesystem();
        $file = $this->embeddedComposer->getExternalComposerFilename();

        if ($fs->exists($file) === false) {
            $fs->dumpFile($file, "{\n}\n");
        }

        if (filesize($file) === 0) {
            $fs->dumpFile($file, "{\n}\n");
        }

        $json = new JsonFile($file);

        $requirements = $this->formatPackageNames($packageNames);
        $versionParser = new VersionParser();

        foreach ($requirements as $constraint) {
            $versionParser->parseConstraints($constraint);
        }

        $composerDefinition = $json->read();

        $requireKey = $areDevPackages ? 'require-dev' : 'require';

        foreach ($requirements as $package => $version) {
            $composerDefinition[$requireKey][$package] = $version;
        }

        $json->write($composerDefinition);

        return $composerDefinition[$requireKey];
    }
public function addPackage ( array $ packageNames , $ areDevPackages = false ) { $ fs = new Filesystem ( ) ; $ file = $ this -> embeddedComposer -> getExternalComposerFilename ( ) ; if ( $ fs -> exists ( $ file ) === false ) { $ fs -> dumpFile ( $ file , "{\n}\n" ) ; } if ( filesize ( $ file ) === 0 ) { $ fs -> dumpFile ( $ file , "{\n}\n" ) ; } $ json = new JsonFile ( $ file ) ; $ requirements = $ this -> formatPackageNames ( $ packageNames ) ; $ versionParser = new VersionParser ( ) ; foreach ( $ requirements as $ constraint ) { $ versionParser -> parseConstraints ( $ constraint ) ; } $ composerDefinition = $ json -> read ( ) ; $ requireKey = $ areDevPackages ? 'require-dev' : 'require' ; foreach ( $ requirements as $ package => $ version ) { $ composerDefinition [ $ requireKey ] [ $ package ] = $ version ; } $ json -> write ( $ composerDefinition ) ; return $ composerDefinition [ $ requireKey ] ; }
Adds a new set of packages to the current Composer file.

@param array $packageNames
@param bool  $areDevPackages

@return array List of package's name as a key and the package's version
as value
Adds a new set of packages to the current Composer file .