diff --git a/src/ncc/Classes/GiteaExtension/GiteaRepository.php b/src/ncc/Classes/GiteaExtension/GiteaRepository.php index 612527b..8381c12 100644 --- a/src/ncc/Classes/GiteaExtension/GiteaRepository.php +++ b/src/ncc/Classes/GiteaExtension/GiteaRepository.php @@ -47,7 +47,7 @@ /** * @inheritDoc */ - public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult + public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult { try { @@ -64,7 +64,7 @@ /** * @inheritDoc */ - public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult + public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult { return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options); } @@ -162,7 +162,7 @@ */ private static function getTagArchive(RepositoryConfiguration $repository, string $group, string $project, string $tag, ?AuthenticationInterface $authentication=null): RepositoryResult { - if($tag === Versions::LATEST) + if($tag === Versions::LATEST->value) { $tag = self::getLatestTag($repository, $group, $project, $authentication); } @@ -307,7 +307,7 @@ private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult { /** @noinspection DuplicatedCode */ - if($release === Versions::LATEST) + if($release === Versions::LATEST->value) { $release = self::getLatestRelease($repository, $group, $project, $authentication); } @@ -409,7 +409,7 @@ private static function getReleaseArchive(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null): RepositoryResult { /** @noinspection DuplicatedCode */ - if ($release === Versions::LATEST) + if ($release === Versions::LATEST->value) { $release = self::getLatestRelease($repository, $group, $project, $authentication); } diff --git a/src/ncc/Classes/GithubExtension/GithubRepository.php b/src/ncc/Classes/GithubExtension/GithubRepository.php index dfa2ce8..9cacc2a 100644 --- a/src/ncc/Classes/GithubExtension/GithubRepository.php +++ b/src/ncc/Classes/GithubExtension/GithubRepository.php @@ -47,7 +47,7 @@ /** * @inheritDoc */ - public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult + public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult { try { @@ -64,7 +64,7 @@ /** * @inheritDoc */ - public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult + public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST->value, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult { return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options); } @@ -161,7 +161,7 @@ */ private static function getTagArchive(RepositoryConfiguration $repository, string $group, string $project, string $tag, ?AuthenticationInterface $authentication = null): RepositoryResult { - if($tag === Versions::LATEST) + if($tag === Versions::LATEST->value) { $tag = self::getLatestTag($repository, $group, $project, $authentication); } @@ -307,7 +307,7 @@ private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult { /** @noinspection DuplicatedCode */ - if($release === Versions::LATEST) + if($release === Versions::LATEST->value) { $release = self::getLatestRelease($repository, $group, $project, $authentication); } @@ -389,7 +389,7 @@ private static function getReleaseArchive(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication = null): RepositoryResult { /** @noinspection DuplicatedCode */ - if($release === Versions::LATEST) + if($release === Versions::LATEST->value) { $release = self::getLatestRelease($repository, $group, $project, $authentication); } diff --git a/src/ncc/Classes/GitlabExtension/GitlabRepository.php b/src/ncc/Classes/GitlabExtension/GitlabRepository.php index b231efe..e09c9ca 100644 --- a/src/ncc/Classes/GitlabExtension/GitlabRepository.php +++ b/src/ncc/Classes/GitlabExtension/GitlabRepository.php @@ -47,7 +47,7 @@ /** * @inheritDoc */ - public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult + public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult { try { @@ -64,7 +64,7 @@ /** * @inheritDoc */ - public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult + public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult { return self::getReleasePackage($repository, $vendor, $project, $version, $authentication, $options); } @@ -164,7 +164,7 @@ */ private static function getTagArchive(RepositoryConfiguration $repository, string $group, string $project, string $tag, ?AuthenticationInterface $authentication=null): RepositoryResult { - if($tag === Versions::LATEST) + if($tag === Versions::LATEST->value) { $tag = self::getLatestTag($repository, $group, $project, $authentication); } @@ -308,7 +308,7 @@ */ private static function getReleasePackage(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null, array $options=[]): RepositoryResult { - if($release === Versions::LATEST) + if($release === Versions::LATEST->value) { $release = self::getLatestRelease($repository, $group, $project, $authentication); } @@ -393,7 +393,7 @@ private static function getReleaseArchive(RepositoryConfiguration $repository, string $group, string $project, string $release, ?AuthenticationInterface $authentication=null): RepositoryResult { /** @noinspection DuplicatedCode */ - if($release === Versions::LATEST) + if($release === Versions::LATEST->value) { $release = self::getLatestRelease($repository, $group, $project, $authentication); } diff --git a/src/ncc/Classes/PackagistExtension/PackagistRepository.php b/src/ncc/Classes/PackagistExtension/PackagistRepository.php index 98ef09b..157d721 100644 --- a/src/ncc/Classes/PackagistExtension/PackagistRepository.php +++ b/src/ncc/Classes/PackagistExtension/PackagistRepository.php @@ -46,9 +46,9 @@ /** * @inheritDoc */ - public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult + public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST->value, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult { - if($version === Versions::LATEST) + if($version === Versions::LATEST->value) { $version = self::getLatestVersion($repository, $vendor, $project); } @@ -98,7 +98,7 @@ * @inheritDoc * @throws NotSupportedException */ - public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult + public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version = Versions::LATEST->value, ?AuthenticationType $authentication = null, array $options=[]): RepositoryResult { throw new NotSupportedException('Fetching ncc packages from Packagist is not supported'); } diff --git a/src/ncc/Classes/Runtime.php b/src/ncc/Classes/Runtime.php index 7800e67..ef2e9a5 100644 --- a/src/ncc/Classes/Runtime.php +++ b/src/ncc/Classes/Runtime.php @@ -121,7 +121,7 @@ * @return string * @throws ImportException */ - public static function import(string $package, string $version=Versions::LATEST): string + public static function import(string $package, string $version=Versions::LATEST->value): string { if(self::isImported($package)) { @@ -173,7 +173,7 @@ * @throws NotSupportedException * @throws PathNotFoundException */ - private static function importFromSystem(string $package, string $version=Versions::LATEST): string + private static function importFromSystem(string $package, string $version=Versions::LATEST->value): string { if(!self::getPackageManager()->getPackageLock()->entryExists($package)) { diff --git a/src/ncc/Enums/Versions.php b/src/ncc/Enums/Versions.php index ab36472..b7d1314 100644 --- a/src/ncc/Enums/Versions.php +++ b/src/ncc/Enums/Versions.php @@ -22,25 +22,20 @@ namespace ncc\Enums; - final class Versions + enum Versions : string { /** * The current version of the credentials store file format */ - public const CREDENTIALS_STORE_VERSION = '1.0.0'; - - /** - * The current version of the package structure file format - */ - public const PACKAGE_STRUCTURE_VERSION = '2.0'; + case CREDENTIALS_STORE_VERSION = '1.0.0'; /** * The current version of the package lock structure file format */ - public const PACKAGE_LOCK_VERSION = '2.0.0'; + case PACKAGE_LOCK_VERSION = '2.0.0'; /** * Generic version of the package structure file format (latest) */ - public const LATEST = 'latest'; + case LATEST = 'latest'; } \ No newline at end of file diff --git a/src/ncc/Interfaces/RepositoryInterface.php b/src/ncc/Interfaces/RepositoryInterface.php index d72845c..ee5f6f8 100644 --- a/src/ncc/Interfaces/RepositoryInterface.php +++ b/src/ncc/Interfaces/RepositoryInterface.php @@ -45,7 +45,7 @@ * @throws AuthenticationException If the authentication is invalid * @throws NetworkException If there was an error getting the source */ - public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult; + public static function fetchSourceArchive(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult; /** * Returns the archive URL for the ncc package of the specified group and project. @@ -61,5 +61,5 @@ * @throws AuthenticationException If the authentication is invalid * @throws NetworkException If there was an error getting the package */ - public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult; + public static function fetchPackage(RepositoryConfiguration $repository, string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult; } \ No newline at end of file diff --git a/src/ncc/Managers/PackageManager.php b/src/ncc/Managers/PackageManager.php index 25908df..375d6bd 100644 --- a/src/ncc/Managers/PackageManager.php +++ b/src/ncc/Managers/PackageManager.php @@ -206,7 +206,7 @@ { Console::outVerbose(sprintf( 'Removing symlink for %s=%s at %s', - $package_name, $this->package_lock->getEntry($package_name)->getVersion(Versions::LATEST)->getVersion(), + $package_name, $this->package_lock->getEntry($package_name)->getVersion(Versions::LATEST->value)->getVersion(), PathFinder::findBinPath() . DIRECTORY_SEPARATOR . strtolower($package_name) )); @@ -216,7 +216,7 @@ } catch(Exception $e) { - throw new IOException(sprintf('Failed to resolve symlink for %s=%s: %s', $package_name, $this->package_lock->getEntry($package_name)->getVersion(Versions::LATEST)->getVersion(), $e->getMessage()), $e); + throw new IOException(sprintf('Failed to resolve symlink for %s=%s: %s', $package_name, $this->package_lock->getEntry($package_name)->getVersion(Versions::LATEST->value)->getVersion(), $e->getMessage()), $e); } if(is_file($symlink_path)) diff --git a/src/ncc/Objects/PackageLock.php b/src/ncc/Objects/PackageLock.php index 9f6694a..a4d42b1 100644 --- a/src/ncc/Objects/PackageLock.php +++ b/src/ncc/Objects/PackageLock.php @@ -59,7 +59,7 @@ /** * Public Constructor */ - public function __construct(array $entries=[], string $package_lock_version=Versions::PACKAGE_LOCK_VERSION, ?int $last_updated_timestamp=null) + public function __construct(array $entries=[], string $package_lock_version=Versions::PACKAGE_LOCK_VERSION->value, ?int $last_updated_timestamp=null) { $this->entries = $entries; $this->package_lock_version = $package_lock_version; @@ -280,7 +280,7 @@ }, $entries_array); - $package_lock_version = Functions::array_bc($data, 'package_lock_version') ?? Versions::PACKAGE_LOCK_VERSION; + $package_lock_version = Functions::array_bc($data, 'package_lock_version') ?? Versions::PACKAGE_LOCK_VERSION->value; $last_updated_timestamp = Functions::array_bc($data, 'last_updated_timestamp') ?? time(); if($package_lock_version === null) diff --git a/src/ncc/Objects/PackageLock/PackageEntry.php b/src/ncc/Objects/PackageLock/PackageEntry.php index 5206743..4335824 100644 --- a/src/ncc/Objects/PackageLock/PackageEntry.php +++ b/src/ncc/Objects/PackageLock/PackageEntry.php @@ -183,7 +183,7 @@ */ public function versionExists(string $version): bool { - if($version === Versions::LATEST) + if($version === Versions::LATEST->value) { try { @@ -219,7 +219,7 @@ */ public function getSatisfyingVersion(string $version): string { - if($version === Versions::LATEST) + if($version === Versions::LATEST->value) { $version = $this->getLatestVersion(); } @@ -248,7 +248,7 @@ */ public function getVersion(string $version): VersionEntry { - if($version === Versions::LATEST) + if($version === Versions::LATEST->value) { $version = $this->getLatestVersion(); } @@ -354,7 +354,7 @@ * @throws IOException * @throws PathNotFoundException */ - public function getAssembly(string $version=Versions::LATEST): Assembly + public function getAssembly(string $version=Versions::LATEST->value): Assembly { $assembly_path = $this->getPath($version) . DIRECTORY_SEPARATOR . FileDescriptor::ASSEMBLY; if(!is_file($assembly_path)) @@ -375,7 +375,7 @@ * @throws PathNotFoundException * @throws NotSupportedException */ - public function getMetadata(string $version=Versions::LATEST): Metadata + public function getMetadata(string $version=Versions::LATEST->value): Metadata { $metadata_path = $this->getPath($version) . DIRECTORY_SEPARATOR . FileDescriptor::METADATA; if(!is_file($metadata_path)) @@ -394,7 +394,7 @@ * @throws IOException * @throws PathNotFoundException */ - public function getInstaller(string $version=Versions::LATEST): ?Installer + public function getInstaller(string $version=Versions::LATEST->value): ?Installer { $installer_path = $this->getPath($version) . DIRECTORY_SEPARATOR . FileDescriptor::INSTALLER; if(!is_file($installer_path)) @@ -413,7 +413,7 @@ * @throws IOException * @throws PathNotFoundException */ - public function getClassMap(string $version=Versions::LATEST): array + public function getClassMap(string $version=Versions::LATEST->value): array { $class_map_path = $this->getPath($version) . DIRECTORY_SEPARATOR . FileDescriptor::CLASS_MAP; if(!is_file($class_map_path)) @@ -434,7 +434,7 @@ * @throws IOException * @throws PathNotFoundException */ - public function getExecutionPolicy(string $policy_name, string $version=Versions::LATEST): ExecutionPolicy + public function getExecutionPolicy(string $policy_name, string $version=Versions::LATEST->value): ExecutionPolicy { $execution_policy_path = $this->getPath($version) . DIRECTORY_SEPARATOR . 'units' . DIRECTORY_SEPARATOR . $policy_name . '.policy'; if(!is_file($execution_policy_path)) @@ -453,7 +453,7 @@ * @return string * @throws IOException */ - public function getExecutionBinaryPath(string $policy_name, string $version=Versions::LATEST): string + public function getExecutionBinaryPath(string $policy_name, string $version=Versions::LATEST->value): string { $execution_binary_path = $this->getPath($version) . DIRECTORY_SEPARATOR . 'units' . DIRECTORY_SEPARATOR . $policy_name; if(!is_file($execution_binary_path)) diff --git a/src/ncc/Objects/ProjectConfiguration/Dependency.php b/src/ncc/Objects/ProjectConfiguration/Dependency.php index 5b17279..63b19af 100644 --- a/src/ncc/Objects/ProjectConfiguration/Dependency.php +++ b/src/ncc/Objects/ProjectConfiguration/Dependency.php @@ -63,7 +63,7 @@ { $this->name = $name; $this->source = $source; - $this->version = $version ?? Versions::LATEST; + $this->version = $version ?? Versions::LATEST->value; } /** @@ -115,7 +115,7 @@ */ public function getVersion(): string { - return $this->version ?? Versions::LATEST; + return $this->version ?? Versions::LATEST->value; } /** @@ -127,7 +127,7 @@ */ public function setVersion(?string $version): void { - $this->version = ($version ?? Versions::LATEST); + $this->version = ($version ?? Versions::LATEST->value); } /** @@ -140,7 +140,7 @@ throw new ConfigurationException(sprintf('Invalid dependency name "%s"', $this->name)); } - if($this->version !== Versions::LATEST && !Validate::version($this->version)) + if($this->version !== Versions::LATEST->value && !Validate::version($this->version)) { throw new ConfigurationException(sprintf('Invalid dependency version "%s"', $this->version)); } diff --git a/src/ncc/Objects/RemotePackageInput.php b/src/ncc/Objects/RemotePackageInput.php index b86b875..880ae86 100644 --- a/src/ncc/Objects/RemotePackageInput.php +++ b/src/ncc/Objects/RemotePackageInput.php @@ -66,7 +66,7 @@ { $this->package = $package; $this->vendor = $vendor; - $this->version = Versions::LATEST; + $this->version = Versions::LATEST->value; } /** @@ -126,7 +126,7 @@ */ public function setVersion(?string $version): void { - $this->version = $version ?? Versions::LATEST; + $this->version = $version ?? Versions::LATEST->value; } /** @@ -238,7 +238,7 @@ } $object = new RemotePackageInput($matches['package'], $matches['vendor']); - $object->version = empty($matches['version']) ? Versions::LATEST : $matches['version']; + $object->version = empty($matches['version']) ? Versions::LATEST->value : $matches['version']; $object->branch = empty($matches['branch']) ? null : $matches['branch']; $object->repository = empty($matches['source']) ? null : $matches['source']; diff --git a/src/ncc/Objects/RepositoryConfiguration.php b/src/ncc/Objects/RepositoryConfiguration.php index a39bc5f..245e2f0 100644 --- a/src/ncc/Objects/RepositoryConfiguration.php +++ b/src/ncc/Objects/RepositoryConfiguration.php @@ -178,7 +178,7 @@ * @throws NetworkException If there was an error getting the package * @throws NotSupportedException If the repository type does not support fetching packages */ - public function fetchPackage(string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult + public function fetchPackage(string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult { return match(strtolower($this->type)) { @@ -202,7 +202,7 @@ * @throws AuthenticationException If the authentication is invalid * @throws NetworkException If there was an error getting the source */ - public function fetchSourceArchive(string $vendor, string $project, string $version=Versions::LATEST, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult + public function fetchSourceArchive(string $vendor, string $project, string $version=Versions::LATEST->value, ?AuthenticationType $authentication=null, array $options=[]): RepositoryResult { return match(strtolower($this->type)) { diff --git a/src/ncc/Objects/Vault.php b/src/ncc/Objects/Vault.php index 8d8e74d..1c16fe9 100644 --- a/src/ncc/Objects/Vault.php +++ b/src/ncc/Objects/Vault.php @@ -53,7 +53,7 @@ */ public function __construct() { - $this->version = Versions::CREDENTIALS_STORE_VERSION; + $this->version = Versions::CREDENTIALS_STORE_VERSION->value; $this->entries = []; } diff --git a/src/ncc/Utilities/Functions.php b/src/ncc/Utilities/Functions.php index b6a1f9a..2f04a82 100644 --- a/src/ncc/Utilities/Functions.php +++ b/src/ncc/Utilities/Functions.php @@ -641,7 +641,7 @@ * @param string $version * @return string */ - public static function createExecutionPointer(string $package_name, string $version=Versions::LATEST): string + public static function createExecutionPointer(string $package_name, string $version=Versions::LATEST->value): string { $content = "#!/bin/sh\n"; $content .= sprintf('exec ncc exec --package "%s" --exec-version "%s" --exec-args "$@"', $package_name, $version); diff --git a/src/ncc/Utilities/extension b/src/ncc/Utilities/extension index fb81684..5240310 100644 --- a/src/ncc/Utilities/extension +++ b/src/ncc/Utilities/extension @@ -24,7 +24,7 @@ * @param array $options * @return string */ - function import(string $package, string $version=Versions::LATEST, array $options=[]): string + function import(string $package, string $version=Versions::LATEST->value, array $options=[]): string { try {