Files
ABSDEV/Modules/Marketplace/Services/VersionConstraint.php
T
Mark Gregory f09a680531 Marketplace package catalogue
* Modules, themes, and extensions
* Publisher profiles and verification metadata
* Installed-package tracking
* Semantic version compatibility checks
* PHP, Laravel, and Content Manager compatibility checks
* Dependency resolution
* SHA-256 checksum validation
* Package signature requirements
* Installation and update history
* Enable and disable controls
* Removal handling
* Rollback records
* Licence records
* Marketplace administration UI
* Authenticated REST endpoints
* Console audit and synchronisation commands
* Permissions and sidebar integration
* Feature tests
2026-07-24 13:49:14 +01:00

23 lines
1.2 KiB
PHP

<?php
namespace Modules\Marketplace\Services;
final class VersionConstraint
{
public function matches(string $version,string $constraint): bool
{
$constraint=trim($constraint);
if ($constraint==='' || $constraint==='*') return true;
foreach (preg_split('/\s*\|\|\s*/',$constraint) ?: [] as $alternative) {
$ok=true;
foreach (preg_split('/\s*,?\s+/',trim($alternative)) ?: [] as $part) {
if ($part==='') continue;
if (str_starts_with($part,'^')) { $base=substr($part,1); $major=(int) explode('.',$base)[0]; $ok=$ok && version_compare($version,$base,'>=') && version_compare($version,($major+1).'.0.0','<'); continue; }
if (str_starts_with($part,'~')) { $base=substr($part,1); $bits=array_pad(explode('.',$base),3,'0'); $upper=$bits[0].'.'.((int)$bits[1]+1).'.0'; $ok=$ok && version_compare($version,$base,'>=') && version_compare($version,$upper,'<'); continue; }
if (preg_match('/^(>=|<=|>|<|=)?\s*([0-9][0-9A-Za-z.\-+]*)$/',$part,$m)) $ok=$ok && version_compare($version,$m[2],$m[1] ?: '=');
else $ok=$ok && $version===$part;
}
if ($ok) return true;
}
return false;
}
}