PHP code example of evilfreelancer / composer-json-generator

1. Go to this page and download the library: Download evilfreelancer/composer-json-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

evilfreelancer / composer-json-generator example snippets




use \ComposerJson\Generator;
use \ComposerJson\Schemas\Composer;
use \ComposerJson\Schemas\Author;
use \ComposerJson\Schemas\Psr4;

// Initiate generator
$generator = new Generator();

// Initiate composer object
$composer = new Composer();

/*
 * Set basic parameters of new composer.json file
 */

$composer->name        = 'evilfreelancer/composer-json-generator';
$composer->type        = 'library';
$composer->description = 'Small library for generating composer.json file with validation by composer\'s schema';
$composer->keywords    = ['composer', 'json', 'generator'];
$composer->license     = 'MIT';

/*
 * Autoloader details
 */

// For normal usage
$psr4 = new Psr4();

$psr4->options = [
    "ComposerJson\\" => './src/',
];

$composer->autoload[] = $psr4;

// For tests
$psr4 = new Psr4();

$psr4->options = [
    "ComposerJson\\Tests\\" => './tests/',
];

$composer->autoloadDev[] = $psr4;

/*
 * Authors of project
 */

$author           = new Author();
$author->name     = 'Paul Rock';
$author->email    = '[email protected]';
$author->homepage = 'https://twitter.com/EvilFreelancer';
$author->role     = 'Developer';

$composer->authors[] = $author;

/*
 * Require rules
 */

$composer->



use \ComposerJson\Generator;

$generator = new Generator();
$generator->read(__DIR__ . '/composer.json');

$array = $generator->toArray();
$json  = $generator->toJson();

//var_dump($array);
echo $json . PHP_EOL;