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
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user