ssnepenthe/composer-utilities

This package is abandoned and no longer maintained. No replacement package was suggested.

Some basic utilities for working with Composer projects.

0.2.2 2016-02-29 21:43 UTC

This package is auto-updated.

Last update: 2022-02-02 16:48:27 UTC


README

Some basic utilities for for retrieving information about Composer projects from composer.json and composer.lock.

The WordPress implementations assume that you are using the composer/installers composer plugin, the johnpbloch/wordpress package for core and wpackagist.org as a composer repository.

Usage

Instantiate with paths to your composer.json and composer.lock files.

Generic json:

use SSNepenthe\ComposerUtilities\Json;

$json = new Json( __DIR__ . '/composer.json' );

Composer Specific:

use SSNepenthe\ComposerUtilities\Composer\Json;
use SSNepenthe\ComposerUtilities\Composer\Lock;

$json = new Json( __DIR__ . '/composer.json' );
$lock = new Lock( __DIR__ . '/composer.lock' );

WordPress Specific:

use SSNepenthe\ComposerUtilities\WordPress\Json;
use SSNepenthe\ComposerUtilities\WordPress\Lock;

$json = new Json( __DIR__ . '/composer.json' );
$lock = new Lock( __DIR__ . '/composer.lock' );

SSNepenthe\ComposerUtilities\Json is the base class that provides some convenience methods for working with json files:

$json->json(); // a string containing the full contents of the passed json file, throws RuntimeException if the file does not exist
$json->object(); // same as json_decode( $json->json() ) but throws a RuntimeException if there are any errors decoding the file
$json->path(); // the path passed to the contructor

SSNepenthe\ComposerUtilities\Composer\Json extends SSNepenthe\ComposerUtilities\Json, adding the following methods:

$json->hash(); // md5 hash of the file
$json->path_by_name( 'type:wordpress-plugin' ); // the install path as set in composer.json extra->{'installer-paths'}, null if not set
$json->paths(); // an array of all paths from extra->{'installer-paths'}
$json->vendor_path(); // alias of $json->path_by_name( 'vendor-dir' )

SSNepenthe\ComposerUtilities\WordPress\Json extends SSNepenthe\ComposerUtilities\Composer\Json, adding the following methods:

$json->mu_plugin_path(); // alias of $json->path_by_name( 'type:wordpress-muplugin' )
$json->plugin_path(); // alias of $json->path_by_name( 'type:wordpress-plugin' )
$json->theme_path(); // alias of $json->path_by_name( 'type:wordpress-theme' )
$json->wordpress_path(); // alias of $json->path_by_name( 'wordpress-install-dir' )

SSNepenthe\ComposerUtilities\Composer\Lock extends SSNepenthe\ComposerUtilities\Json, adding the following methods:

$lock->dev_packages(); // alias of $lock->packages( true )
$lock->hash(); // md5 hash of the composer.lock file
$lock->json_hash(); // md5 hash of the composer.json file from which this lock file was generated
$lock->name_index(); // an index of packages useful for searching by name
$lock->package_by_name( 'johnpbloch/wordpress' ); // get the package named 'johnpbloch/wordpress'
$lock->packages(); // an array of composer dependencies, pass true as first parameter to get dev-dependencies instead
$lock->packages_by_type( 'wordpress-plugin' ); // an array of all packages with type of wordpress-plugin
$lock->type_index(); // an index of packages useful for searching by type

Note that individual packages are returned as an instance of SSNepenthe\ComposerUtilities\Composer\Package with the following methods:

$package->is_composer_plugin(); // alias of $package->is_of_type( 'composer-plugin' )
$package->is_library(); // alias of $package->is_of_type( 'library' )
$package->is_of_type( 'wordpress-plugin' ); // bool
$package->name(); // string
$package->type(); // string
$package->version(); // string

SSNepenthe\ComposerUtilities\WordPress\Lock extends SSNepenthe\ComposerUtilities\Composer\Lock, adding the following methods:

$lock->core_packages(); // alias of $lock->packages_by_type( 'wordpress-core' )
$lock->mu_plugin_packages(); // alias of $lock->packages_by_type( 'wordpress-muplugin' )
$lock->plugin_packages(); // alias of $lock->packages_by_type( 'wordpress-plugin' )
$lock->theme_packages(); // alias of $lock->packages_by_type( 'wordpress-theme' )
$lock->wordpress_packages(); // an array of all WordPress packages

Note that individual packages will be returned as an instance of SSNepenthe\ComposerUtilities\WordPress\Package, which extends SSNepenthe\ComposerUtilities\Composer\Package with the following methods:

$package->is_wp_core(); // alias of $package->is_of_type( 'wordpress-core' )
$package->is_wp_mu_plugin(); // alias of $package->is_of_type( 'wordpress-muplugin' )
$package->is_wp_package(); // bool
$package->is_wp_plugin(); // alias of $package->is_of_type( 'wordpress-plugin' )
$package->is_wp_theme(); // alias of $package->is_of_type( 'wordpress-theme' )
$package->is_wpackagist_package(); // bool