composer/spdx-licenses
PHP library providing the official SPDX license and exception lists plus validation for SPDX license expressions. Look up licenses by identifier or name, check OSI approval or deprecation status, and validate license strings for Composer and tooling.
validate() method.composer require composer/spdx-licenses and use SpdxLicenses class.app()->make(SpdxLicenses::class)).spdx:audit command for CLI-based compliance checks.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| PHP Version | Drops PHP 5.3–7.1 in v1.6.0; Laravel 9+ requires PHP 8.0+. | Upgrade to v1.6.0+ for modern PHP support. |
| SPDX Version Drift | License list updates frequently (e.g., SPDX 3.28 in v1.5.10). | Pin to a stable version (e.g., ^1.6) and monitor SPDX changes. |
| Validation Logic | Regex-based validation may miss edge cases in complex SPDX expressions. | Unit test against known SPDX edge cases (e.g., AND, OR, WITH clauses). |
| Performance | getLicenses() loads all licenses into memory (~100KB). |
Cache the SpdxLicenses instance in Laravel’s container or a singleton. |
| Deprecation Warnings | Some licenses (e.g., Common-Public-License-1.0) are deprecated. |
Log warnings and surface them via Laravel’s logging or a custom exception. |
getLicenses() be called frequently (e.g., per request)? If so, cache aggressively.InvalidArgumentException) or log and continue?app('spdx')) or a contextual service (e.g., only in audit routes)?SpdxLicenses as a singleton or context-bound service.post-autoload-dump).| Phase | Action | Tools/Libraries |
|---|---|---|
| Assessment | Audit current composer.json files for invalid/deprecated licenses. |
SpdxLicenses::validate() + custom script. |
| Pilot | Integrate into one Laravel project (e.g., a compliance dashboard). | ServiceProvider + Artisan command. |
| CI/CD Hook | Add license validation to GitHub Actions/GitLab CI (fail builds on violations). | GitHub Action: composer validate --check-licenses. |
| Middleware | Block requests from non-compliant dependencies in production. | Laravel middleware + SpdxLicenses. |
| Full Rollout | Enforce across all Laravel projects via a composer plugin or package template. | Custom Composer plugin. |
composer/spdx-licenses:^1.6 (PHP 7.2+).composer/spdx-licenses:^1.5 (PHP 5.3+).composer/audit).SpdxLicenses to a ServiceProvider (e.g., App\Providers\SpdxServiceProvider).$this->app->singleton(SpdxLicenses::class, function ($app) {
return new SpdxLicenses();
});
composer.json files:
php artisan spdx:audit --fail-on=deprecated,non-osi
- name: Check SPDX Licenses
run: composer validate --check-licenses
public function handle(Request $request, Closure $next) {
$license = $request->dependency->license;
if (!$this->spdx->isOsiApprovedByIdentifier($license)) {
abort(403, "Non-compliant license detected.");
}
return $next($request);
}
composer install:
// src/Plugin.php
public function onPostAutoloadDump() {
$licenses = new SpdxLicenses();
foreach ($this->getComposer()->getRepositoryManager()->getLocalRepository()->getPackages() as $package) {
if (!$licenses->isOsiApprovedByIdentifier($package->getLicense())) {
throw new \RuntimeException("Non-OSI license detected: {$package->getLicense()}");
}
}
}
isDeprecatedByIdentifier() to log warnings or block deprecated licenses.if ($this->spdx->isDeprecatedByIdentifier($license)) {
\Log::warning("Deprecated license detected: {$license}");
// Optionally: throw new \
How can I help you explore Laravel packages today?