composer/spdx-licenses
SPDX licenses list and validation library extracted from Composer. Look up licenses and exceptions by identifier or name, check OSI approval and deprecation, and validate SPDX license expressions using official SPDX License List data.
getLicenseByIdentifier, validate) can be wrapped in Laravel services (e.g., LicenseValidatorService) or extended via traits for project-specific logic (e.g., custom license blacklists).composer require composer/spdx-licenses).SpdxLicenses::validate($input).AppServiceProvider for global access:
public function register() {
$this->app->singleton(SpdxLicenses::class, fn() => new SpdxLicenses());
}
php artisan spdx:validate for project-wide license checks).| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| SPDX version drift | Package auto-updates with SPDX releases (e.g., 3.28.0 in v1.5.10). | Pin to a specific version (e.g., ^1.5) to avoid breaking changes. |
| Deprecated licenses | Library flags deprecated licenses (e.g., isDeprecatedByIdentifier). |
Implement Laravel notifications or CI/CD failures for deprecated dependencies. |
| Validation edge cases | Regex-based validation may miss malformed SPDX expressions. | Unit-test with real-world composer.json snippets and SPDX edge cases. |
| Performance | Lookup is O(1) for identifiers, but bulk operations (e.g., getLicenses()) may be slow for large projects. |
Cache results in Laravel’s cache system (e.g., Cache::remember). |
| PHP 8.2+ deprecations | Resolved in v1.5.7, but future PHP versions may introduce breaking changes. | Monitor PHP RFCs and update dependencies proactively. |
| False positives | Custom license identifiers may not be recognized. | Extend the library with project-specific license mappings via a decorator pattern. |
Compliance Scope:
Integration Points:
Performance:
SpdxLicenses::getLicenses() be called frequently? If so, caching should be implemented.vendor/ dependencies)? Consider parallel processing with Laravel Queues.Maintenance:
php artisan make:license-migration)?Extensibility:
getLicenses().Error Handling:
Testing:
MIT AND Apache-2.0 are handled correctly?Laravel Ecosystem:
composer install via a custom Composer plugin or post-install script.SpdxLicenses as a singleton for global access (e.g., app(SpdxLicenses::class)).spdx:validate command for ad-hoc checks:
php artisan spdx:validate --file=composer.json --fail-on=deprecated
LicenseComplianceMiddleware).Composer\Installer\PackageEvent or Illuminate\Foundation\Application\Booted.PHP Stack:
| Phase | Action | Tools/Dependencies |
|---|---|---|
| Assessment | Audit existing composer.json files for SPDX compliance. |
composer validate, custom scripts |
| Proof of Concept | Implement a Laravel service to validate licenses in vendor/ and composer.json. |
SpdxLicenses, PHPUnit |
| Core Integration | Add Composer plugin or post-install hook to fail on non-compliant licenses. | Composer Plugin API, Laravel Events |
| CI/CD Enforcement | Integrate with GitHub Actions/GitLab CI to block PRs with invalid licenses. | GitHub Actions, spdx-licenses package |
| Runtime Checks | Extend with middleware or policies for license-aware feature toggles. | Laravel Middleware, Policies |
| Reporting | Generate SPDX reports or dashboard widgets for license compliance. | Laravel Nova, custom views |
Phase 1: Validation Layer
SpdxLicenses into a Laravel service for license validation.validate, isOsiApprovedByIdentifier).$validator = new SpdxLicenses();
if (!$validator->validate($package->getLicense())) {
throw new LicenseValidationException("Invalid SPDX license: {$package->getLicense()}");
}
Phase 2: Composer Integration
use Composer\Plugin\PluginInterface;
use Composer\EventDispatcher\EventSubscriberInterface;
use Composer\Install
How can I help you explore Laravel packages today?