composer/spdx-licenses for PHP License Validation
Tools for working with the SPDX license list and validating licenses.
At a glance
- What is it?
- composer/spdx-licenses is a PHP library for looking up SPDX licenses and exceptions and validating SPDX license expressions. It is suited to PHP and Composer projects that need machine-readable license metadata.
- Who is it for?
- Adopt composer/spdx-licenses when a PHP or Composer project needs SPDX identifiers, license exceptions, metadata checks, or expression validation. Do not use it as a complete policy engine or as a substitute for checking the SPDX specifications and your own compliance rules.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 22 days ago.
- What is it written in?
- Mainly PHP, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 20, 2026, and from our analysis. They are not legal advice.
Editorial analysis
What composer/spdx-licenses solves
composer/spdx-licenses addresses the need to work with SPDX license data inside PHP applications. SPDX, or Software Package Data Exchange, defines identifiers and metadata for software licenses. An application may need to determine which record corresponds to MIT License, whether a license is OSI approved, whether an identifier is deprecated, or whether a complete license expression is valid.
The library is aimed at developers building PHP tooling that accepts package metadata, checks license declarations, or resolves human-readable license names. The README says the project was originally written as part of composer/composer and was later extracted into a stand-alone library. Its scope is therefore a reusable PHP dependency, not a separate command-line application or a license research website.
The README documents licenses, license exceptions, and expression validation. It does not document a database server, network API, background worker, or configurable data source. Based on the repository layout, implementation files are under `src/`, while license-related resources are under `res/`. The README does not explain the internal storage format, so applications should depend on the public methods rather than read those files directly.
SPDX lookup and validation operations
The central class is `Composer\Spdx\SpdxLicenses`. The README shows that one instance can retrieve a license by SPDX identifier, retrieve an exception by identifier, translate a license name into an identifier, and check license metadata.
Identifier lookup is handled by `getLicenseByIdentifier('MIT')`. The reverse operation is `getIdentifierByName('MIT License')`, which takes a license name and returns its identifier. This distinction matters when an application receives metadata from different sources and needs a canonical SPDX value before comparing records.
Exceptions are handled separately. The example uses `getExceptionByIdentifier('Autoconf-exception-3.0')`. This indicates that the package includes license exceptions as a distinct data category instead of treating every exception as an ordinary license. Applications that store or display this information should preserve that separation.
The library also exposes status checks. `isOsiApprovedByIdentifier('MIT')` checks whether an identifier is marked as OSI approved, while `isDeprecatedByIdentifier('MIT')` checks whether it is deprecated. `validate($input)` checks whether the input is a valid SPDX license expression. The README points to the SPDX specifications for the expression rules, so this method is intended to implement formal SPDX syntax rather than a general legal-text check.
Installing composer/spdx-licenses with Composer
The README states that PHP 5.3.2 is required and recommends using the latest version of PHP. It also identifies composer/spdx-licenses as a stand-alone package extracted from composer/composer.
Install the latest version from a Composer project with the documented command:
$ composer require composer/spdx-licensesThis adds `composer/spdx-licenses` to the Composer dependencies. The repository includes a `composer.json` file and a `bin/` directory, but the README does not document a separate installation procedure for using the package outside a Composer project. It does not provide a manual download command or an archive installation command.
Before adding the dependency, check the PHP version used by the application against the documented PHP 5.3.2 requirement. The README recommends a current PHP version, but it does not identify a particular current release as required. After installation, the package is consumed through its PHP class rather than through a documented command for editing SPDX data.
A first PHP license lookup
The README's basic usage example creates `SpdxLicenses` and calls its lookup and validation methods. The following is the documented example:
<?php
use Composer\Spdx\SpdxLicenses;
$licenses = new SpdxLicenses();
// get a license by identifier
$licenses->getLicenseByIdentifier('MIT');
// get a license exception by identifier
$licenses->getExceptionByIdentifier('Autoconf-exception-3.0');
// get a license identifier by name
$licenses->getIdentifierByName('MIT License');
// check if a license is OSI approved by identifier
$licenses->isOsiApprovedByIdentifier('MIT');
// check if a license identifier is deprecated
$licenses->isDeprecatedByIdentifier('MIT');
// check if input is a valid SPDX license expression
$licenses->validate($input);The example demonstrates the available API but does not specify the exact class or fields returned by each lookup method. It also does not document the exception behavior for an unknown identifier or invalid expression. An application should therefore confirm the actual return contracts and failure behavior in the installed version rather than assuming undocumented response shapes.
The README does not define `$input` with a concrete value. A first implementation can pass the SPDX expressions already held by its own package metadata. The repository contains a `tests/` directory, but the README does not give a test command, so no test invocation is documented here.
SPDX data provenance and project activity
The README identifies SPDX as the curator of the license information and says that the data is pulled from the SPDX License List Data repository. It also links to the SPDX license index and license exception index. This provenance helps an application explain where its identifiers came from and points maintainers to the upstream data source when records change.
The data source is separate from the PHP implementation. Updating the library and reviewing upstream SPDX data are different operations. The README does not document an update command, synchronization schedule, user-selectable data version, or runtime data source. It also does not explain whether callers can supply custom license records.
The repository is not archived, and its last push was on 2026-10-01. Recent releases listed for the project are 1.6.0 and 1.5.10 on 2026-04-08, followed by 1.5.9 on 2025-05-12. This shows recent repository activity, but it does not define an upgrade policy for every PHP application. Maintenance work therefore includes ordinary dependency review and checking PHP compatibility when upgrading. The repository is licensed under the MIT License, with details in the `LICENSE` file. That statement does not determine how an application must comply with the licenses of its own dependencies or with any license it distributes.
Limits of composer/spdx-licenses
composer/spdx-licenses is a focused PHP library for SPDX data and expression validation. It is not a complete license compatibility checker. The README documents lookup by identifier and name, exception lookup, OSI approval status, deprecation status, and expression validation. It does not document compatibility analysis between arbitrary project licenses, legal interpretation, filesystem scanning, or policy decisions about which license an organization may use.
The package is also unsuitable by itself for free-form legal text. `validate($input)` is defined for SPDX license expressions, not for arbitrary license paragraphs. An application receiving free-form text would need a separate extraction or normalization process before calling the validator. The README does not document such a process.
A PHP project with no need for SPDX identifiers or expression validation may incur dependency and upgrade work for no practical benefit. An application that requires custom license records or control over the selected SPDX data version should first check whether those requirements are documented and supported by the version being considered. The repository layout includes `src/`, `res/`, `tests/`, and static-analysis configuration, but the README exposes no configuration option for changing the data set.
Comparing the library with a policy tool
A real alternative is a full policy or license-analysis tool rather than relying only on `SpdxLicenses`. The difference is scope. composer/spdx-licenses provides a small PHP API for canonical SPDX lookup, exceptions, metadata flags, and expression validation. The README does not document repository-wide scanning, policy conflict detection, obligation reporting, or file classification by license text.
A full policy tool is more relevant when an organization needs enforcement and reporting across an entire codebase rather than a library call inside one application. The README does not identify a competing package or provide its commands, so this review does not claim feature parity or describe an unverified tool as a direct replacement.
The practical decision follows the documented boundary. Use this library when software needs canonical SPDX identifiers, exception records, OSI approval information, deprecation information, or syntax validation for SPDX expressions. Consider a broader policy tool when software must inspect a repository and apply organizational rules. Because the README does not specify unknown-input behavior or data refresh controls, test those cases in the exact package version before making the library the only component of a compliance workflow.
Editorial conclusion
Adopt composer/spdx-licenses when a PHP or Composer project needs SPDX identifiers, license exceptions, metadata checks, or expression validation. Do not use it as a complete policy engine or as a substitute for checking the SPDX specifications and your own compliance rules. Verify the supported PHP version first, then confirm the identifiers and expressions used by your application.
Frequently asked questions
What is composer/spdx-licenses used for?
It is a PHP library for working with SPDX license information. It supports license and exception lookup, name-to-identifier resolution, OSI approval checks, deprecation checks, and validation of SPDX license expressions.
How do you install composer/spdx-licenses?
The README documents installing the latest version with `composer require composer/spdx-licenses`. Composer can then autoload the package for use in a PHP project.
Does composer/spdx-licenses require a modern PHP version?
The README states that PHP 5.3.2 is required and recommends using the latest PHP version. It does not name a specific minimum modern PHP release.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/composer-spdx-licenses)Was this useful?