PHPのパッケージ管理ツールであるComposerでは、licensesコマンドを使うとインストール済みのパッケージに対するライセンスを確認する事ができます。
今回は、licensesコマンドについて説明します。
composerでパッケージをインストール
まずは準備のため、composerでmonologをインストールします。
また、開発時のみ使用するパッケージとしてphpunitを--dev付きでインストールします。
> composer require monolog/monolog
> composer require --dev phpunit/phpunit
インストール後にcomposer show コマンドを実行すると、依存パッケージも含めて、下記の30パッケージがインストールされたことがわかります。
> composer show
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without inv...
monolog/monolog 1.22.1 Sends your logs to files, sockets, inboxes, databases and various web ...
myclabs/deep-copy 1.6.1 Create deep copies (clones) of your objects
phar-io/manifest 1.0.1 Component for reading phar.io manifest information from a PHP Archive ...
phar-io/version 1.0.1 Library for handling version information and constraints
phpdocumentor/reflection-common 1.0 Common reflection classes used by phpdocumentor to reflect the code st...
phpdocumentor/reflection-docblock 3.1.1 With this component, a library can provide support for annotations via...
phpdocumentor/type-resolver 0.2.1
phpspec/prophecy v1.7.0 Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage 5.2.1 Library that provides collection, processing, and rendering functional...
phpunit/php-file-iterator 1.4.2 FilterIterator implementation that filters files based on a list of su...
phpunit/php-text-template 1.2.1 Simple template engine.
phpunit/php-timer 1.0.9 Utility class for timing
phpunit/php-token-stream 1.4.11 Wrapper around PHP's tokenizer extension.
phpunit/phpunit 6.1.3 The PHP Unit Testing framework.
phpunit/phpunit-mock-objects 4.0.1 Mock Object library for PHPUnit
psr/log 1.0.2 Common interface for logging libraries
sebastian/code-unit-reverse-lookup 1.0.1 Looks up which function or method a line of code belongs to
sebastian/comparator 2.0.0 Provides the functionality to compare PHP values for equality
sebastian/diff 1.4.1 Diff implementation
sebastian/environment 3.0.2 Provides functionality to handle HHVM/PHP environments
sebastian/exporter 3.1.0 Provides the functionality to export PHP variables for visualization
sebastian/global-state 2.0.0 Snapshotting of global state
sebastian/object-enumerator 3.0.2 Traverses array structures and object graphs to enumerate all referenc...
sebastian/object-reflector 1.1.1 Allows reflection of object attributes, including inherited and non-pu...
sebastian/recursion-context 3.0.0 Provides functionality to recursively process PHP variables
sebastian/resource-operations 1.0.0 Provides a list of PHP built-in functions that operate on resources
sebastian/version 2.0.1 Library that helps with managing the version number of Git-hosted PHP ...
theseer/tokenizer 1.1.0 A small library for converting tokenized PHP source code into XML and ...
webmozart/assert 1.2.0 Assertions to validate method input/output with nice error messages.
インストールしたパッケージたちのライセンスを確認
インストールしたパッケージたちのライセンスを確認するためには、composer lisences
コマンドを使用します
composer licenses
Name: __root__
Version: No version set (parsed as 1.0.0)
Licenses: none
Dependencies:
Name Version License
doctrine/instantiator 1.0.5 MIT
monolog/monolog 1.22.1 MIT
myclabs/deep-copy 1.6.1 MIT
phar-io/manifest 1.0.1 BSD-3-Clause
phar-io/version 1.0.1 BSD-3-Clause
phpdocumentor/reflection-common 1.0 MIT
phpdocumentor/reflection-docblock 3.1.1 MIT
phpdocumentor/type-resolver 0.2.1 MIT
phpspec/prophecy v1.7.0 MIT
phpunit/php-code-coverage 5.2.1 BSD-3-Clause
phpunit/php-file-iterator 1.4.2 BSD-3-Clause
phpunit/php-text-template 1.2.1 BSD-3-Clause
phpunit/php-timer 1.0.9 BSD-3-Clause
phpunit/php-token-stream 1.4.11 BSD-3-Clause
phpunit/phpunit 6.1.3 BSD-3-Clause
phpunit/phpunit-mock-objects 4.0.1 BSD-3-Clause
psr/log 1.0.2 MIT
sebastian/code-unit-reverse-lookup 1.0.1 BSD-3-Clause
sebastian/comparator 2.0.0 BSD-3-Clause
sebastian/diff 1.4.1 BSD-3-Clause
sebastian/environment 3.0.2 BSD-3-Clause
sebastian/exporter 3.1.0 BSD-3-Clause
sebastian/global-state 2.0.0 BSD-3-Clause
sebastian/object-enumerator 3.0.2 BSD-3-Clause
sebastian/object-reflector 1.1.1 BSD-3-Clause
sebastian/recursion-context 3.0.0 BSD-3-Clause
sebastian/resource-operations 1.0.0 BSD-3-Clause
sebastian/version 2.0.1 BSD-3-Clause
theseer/tokenizer 1.1.0 BSD-3-Clause
webmozart/assert 1.2.0 MIT
上記の出力には、開発時のみ使用する予定のphpunitの情報まで含まれています。
本番環境にリリースするパッケージのみライセンスを確認したい場合は、--no-dev
オプションを付与して実行します。
composer licenses --no-dev
Name: __root__
Version: No version set (parsed as 1.0.0)
Licenses: none
Dependencies:
Name Version License
monolog/monolog 1.22.1 MIT
psr/log 1.0.2 MIT
出力結果を別のプログラムで処理したい場合は、--format=json
オプションをつければjsonファイルで結果を出力できるので便利です。
composer licenses --no-dev --format=json
{
"name": "__root__",
"version": "No version set (parsed as 1.0.0)",
"license": [],
"dependencies": {
"monolog/monolog": {
"version": "1.22.1",
"license": [
"MIT"
]
},
"psr/log": {
"version": "1.0.2",
"license": [
"MIT"
]
}
}
}
こちらもおススメ