ssnepenthe/composer-utilities

此包已被废弃且不再维护。未建议替代包。

用于处理 Composer 项目的某些基本实用工具。

0.2.2 2016-02-29 21:43 UTC

This package is auto-updated.

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


README

composer.jsoncomposer.lock 文件检索有关 Composer 项目的某些基本实用工具。

WordPress 实现假定您正在使用 composer/installers Composer 插件、johnpbloch/wordpress 包作为核心以及 wpackagist.org 作为 composer 仓库。

使用方法

使用您的 composer.jsoncomposer.lock 文件路径进行实例化。

通用 JSON

use SSNepenthe\ComposerUtilities\Json;

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

Composer 特定

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

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

WordPress 特定

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 是一个基类,提供了一些用于处理 JSON 文件的便利方法

$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 扩展 SSNepenthe\ComposerUtilities\Json,并添加了以下方法

$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 扩展 SSNepenthe\ComposerUtilities\Composer\Json,并添加了以下方法

$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 扩展 SSNepenthe\ComposerUtilities\Json,并添加了以下方法

$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

请注意,各个包作为 SSNepenthe\ComposerUtilities\Composer\Package 的实例返回,具有以下方法

$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 扩展 SSNepenthe\ComposerUtilities\Composer\Lock,并添加了以下方法

$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

请注意,各个包将作为 SSNepenthe\ComposerUtilities\WordPress\Package 的实例返回,该实例扩展了 SSNepenthe\ComposerUtilities\Composer\Package 并具有以下方法

$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