Skip to content

Instantly share code, notes, and snippets.

@tomjn
Created September 20, 2013 22:58
Show Gist options
  • Select an option

  • Save tomjn/6645042 to your computer and use it in GitHub Desktop.

Select an option

Save tomjn/6645042 to your computer and use it in GitHub Desktop.
in a wordpress environment this will generate a composer.json string, WIP
<?php
function get_composer_json() {
$plugins = get_plugins();
$data = array();
$data['rarst/wordpress'] = '>='.get_bloginfo( 'version' );
$data['php'] = '>=5.2.4';
foreach ( $plugins as $plugin ) {
$key = 'wpackagist/'.sanitize_title( $plugin['Name'] );
$data[ $key ] = $plugin['Version'];
}
$manifest = array();
$manifest['name'] = 'wpsite/'.sanitize_title( get_bloginfo( 'name' ) );
$repositories = array();
$repositories[] = array(
'type' => 'vcs',
'url' => 'http://rarst.net'
);
$manifest['description'] = get_bloginfo( 'description' );
$manifest['homepage'] = home_url();
$manifest['version'] = get_bloginfo( 'version' );
$manifest['repositories'] = $repositories;
$manifest['extra'] = array(
'installer-paths' => array(
'./' => array( 'rarst/wordpress' )
)
);
$manifest['require'] = $data;
$json = json_encode( $manifest, ( JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ) );
return $json;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment