private function initComposerJson($path, $repositoryUrl, $packageName)
    {
        $json = [];
        $composerJson = $path.'/composer.json';
        if (file_exists($composerJson)) {
            $json = json_decode(file_get_contents($composerJson), true);
        }

        if (!isset($json['name'])) {
            $json['name'] = $packageName;
        }

        if (!isset($json['version'])) {
            $json['version'] = '0.0.1';
        }

        if (!isset($json['repositories'])) {
            $json['repositories'] = [['type' => 'git', 'url' => $repositoryUrl]];
        } else {
            $hasRepositoryUrl = false;
            foreach ($json['repositories'] as $item) {
                if ($item['type'] == 'git') {
                    $hasRepositoryUrl = true;
                    break;
                }
            }
            if (!$hasRepositoryUrl) {
                $json['repositories'][] = ['type' => 'git', 'url' => $repositoryUrl];
            }
        }

        $size = file_put_contents(
            $composerJson,
            json_encode(
                $json,
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
            )
        );

        if (!$size) {
            $this->error("Error to write file '{$composerJson}'.");
        }
    }
private function initComposerJson($path, $repositoryUrl, $packageName)
    {
        $json = [];
        $composerJson = $path.'/composer.json';
        if (file_exists($composerJson)) {
            $json = json_decode(file_get_contents($composerJson), true);
        }

        if (!isset($json['name'])) {
            $json['name'] = $packageName;
        }

        if (!isset($json['version'])) {
            $json['version'] = '0.0.1';
        }

        if (!isset($json['repositories'])) {
            $json['repositories'] = [['type' => 'git', 'url' => $repositoryUrl]];
        } else {
            $hasRepositoryUrl = false;
            foreach ($json['repositories'] as $item) {
                if ($item['type'] == 'git') {
                    $hasRepositoryUrl = true;
                    break;
                }
            }
            if (!$hasRepositoryUrl) {
                $json['repositories'][] = ['type' => 'git', 'url' => $repositoryUrl];
            }
        }

        $size = file_put_contents(
            $composerJson,
            json_encode(
                $json,
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
            )
        );

        if (!$size) {
            $this->error("Error to write file '{$composerJson}'.");
        }
    }
private function initComposerJson ( $ path , $ repositoryUrl , $ packageName ) { $ json = [ ] ; $ composerJson = $ path . '/composer.json' ; if ( file_exists ( $ composerJson ) ) { $ json = json_decode ( file_get_contents ( $ composerJson ) , true ) ; } if ( ! isset ( $ json [ 'name' ] ) ) { $ json [ 'name' ] = $ packageName ; } if ( ! isset ( $ json [ 'version' ] ) ) { $ json [ 'version' ] = '0.0.1' ; } if ( ! isset ( $ json [ 'repositories' ] ) ) { $ json [ 'repositories' ] = [ [ 'type' => 'git' , 'url' => $ repositoryUrl ] ] ; } else { $ hasRepositoryUrl = false ; foreach ( $ json [ 'repositories' ] as $ item ) { if ( $ item [ 'type' ] == 'git' ) { $ hasRepositoryUrl = true ; break ; } } if ( ! $ hasRepositoryUrl ) { $ json [ 'repositories' ] [ ] = [ 'type' => 'git' , 'url' => $ repositoryUrl ] ; } } $ size = file_put_contents ( $ composerJson , json_encode ( $ json , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ) ; if ( ! $ size ) { $ this -> error ( "Error to write file '{$composerJson}'." ) ; } }
Initialize composer.json file.

@param mixed $path
@param mixed $repositoryUrl
@param mixed $packageName
Initialize composer . json file .