Update Scopes to enum and adjust scope checks
This commit is contained in:
parent
1ba50cc7ee
commit
7c9f63955a
15 changed files with 33 additions and 33 deletions
|
@ -101,7 +101,7 @@
|
|||
|
||||
if(isset($args['v']))
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
Console::outError('Insufficient permissions, cannot modify configuration values', true, 1);
|
||||
return 1;
|
||||
|
|
|
@ -187,7 +187,7 @@
|
|||
{
|
||||
$ResolvedScope = Resolver::resolveScope();
|
||||
|
||||
if($ResolvedScope !== Scopes::SYSTEM)
|
||||
if($ResolvedScope !== Scopes::SYSTEM->value)
|
||||
{
|
||||
Console::outError('Insufficient permissions to add entries');
|
||||
}
|
||||
|
@ -313,7 +313,7 @@
|
|||
{
|
||||
$ResolvedScope = Resolver::resolveScope();
|
||||
|
||||
if($ResolvedScope !== Scopes::SYSTEM)
|
||||
if($ResolvedScope !== Scopes::SYSTEM->value)
|
||||
{
|
||||
Console::outError('Insufficient permissions to remove entries');
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@
|
|||
*/
|
||||
private static function installPackage(array $args): int
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
Console::outError('You cannot install packages in a user scope, please run this command as root', true, 1);
|
||||
return 1;
|
||||
|
@ -388,7 +388,7 @@
|
|||
*/
|
||||
private static function uninstallPackage($args): int
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
Console::outError('You cannot uninstall packages in a user scope, please run this command as root', true, 1);
|
||||
return 1;
|
||||
|
@ -419,7 +419,7 @@
|
|||
*/
|
||||
private static function uninstallAllPackages(array $args): int
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
Console::outError('You cannot uninstall all packages in a user scope, please run this command as root', true, 1);
|
||||
return 1;
|
||||
|
@ -455,7 +455,7 @@
|
|||
*/
|
||||
private static function fixBrokenPackages(array $args): int
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
Console::outError('You cannot fix broken packages in a user scope, please run this command as root', true, 1);
|
||||
return 1;
|
||||
|
|
|
@ -134,7 +134,7 @@
|
|||
*/
|
||||
private static function installProject(array $args): int
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
Console::outError('You cannot install packages in a user scope, please run this command as root', true, 1);
|
||||
return 1;
|
||||
|
|
|
@ -141,7 +141,7 @@
|
|||
*/
|
||||
private static function addEntry(array $args): int
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
Console::outError('You must be running as root to add a new repository', true, 1);
|
||||
return 1;
|
||||
|
@ -230,7 +230,7 @@
|
|||
*/
|
||||
private static function removeEntry(array $args): int
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
Console::outError('You must be running as root to remove a repository', true, 1);
|
||||
return 1;
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
|
||||
namespace ncc\Enums;
|
||||
|
||||
final class Scopes
|
||||
enum Scopes : string
|
||||
{
|
||||
public const USER = 'USER';
|
||||
case USER = 'USER';
|
||||
|
||||
public const SYSTEM = 'SYSTEM';
|
||||
case SYSTEM = 'SYSTEM';
|
||||
}
|
|
@ -89,7 +89,7 @@
|
|||
{
|
||||
Console::outDebug(sprintf('saving configuration file to %s', PathFinder::getConfigurationFile()));
|
||||
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new AuthenticationException('Cannot save configuration file, insufficient permissions');
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must have root privileges to access the credentials storage file');
|
||||
}
|
||||
|
@ -86,7 +86,7 @@
|
|||
{
|
||||
Console::outVerbose(sprintf('Saving credentials store to %s', PathFinder::getCredentialStorage()));
|
||||
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must have root privileges to modify the credentials storage file');
|
||||
}
|
||||
|
@ -103,7 +103,7 @@
|
|||
*/
|
||||
public static function initializeCredentialStorage(): void
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must have root privileges to initialize the credentials storage file');
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
*/
|
||||
public function save(): void
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must be running as root to update the system package lock');
|
||||
}
|
||||
|
@ -98,7 +98,7 @@
|
|||
*/
|
||||
public static function initializePackageLock(): void
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must be running as root to update the system package lock');
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@
|
|||
*/
|
||||
public function install(string|PackageReader $input, ?AuthenticationInterface $authentication=null, array $options=[]): array
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must have root privileges to install packages');
|
||||
}
|
||||
|
@ -188,7 +188,7 @@
|
|||
*/
|
||||
public function uninstall(string $package_name, ?string $version=null): array
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must have root privileges to uninstall packages');
|
||||
}
|
||||
|
@ -285,7 +285,7 @@
|
|||
*/
|
||||
public function uninstallAll(): array
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must have root privileges to uninstall packages');
|
||||
}
|
||||
|
|
|
@ -211,7 +211,7 @@
|
|||
*/
|
||||
public function installDependencies(?AuthenticationInterface $authentication=null): array
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('Unable to install dependencies, you must be running as root');
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@
|
|||
*/
|
||||
public function addRepository(RepositoryConfiguration $source, bool $update=true): void
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must be running as root to add a new repository');
|
||||
}
|
||||
|
@ -160,7 +160,7 @@
|
|||
*/
|
||||
public function removeRepository(string $name, bool $update=true): void
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must be running as root to delete a repository');
|
||||
}
|
||||
|
@ -195,7 +195,7 @@
|
|||
*/
|
||||
public function updateDatabase(): void
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must be running as root to update the repository database');
|
||||
}
|
||||
|
@ -221,7 +221,7 @@
|
|||
*/
|
||||
public static function initializeDatabase(array $default_repositories=[]): void
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must be running as root to initialize the repository database');
|
||||
}
|
||||
|
|
|
@ -293,7 +293,7 @@
|
|||
*/
|
||||
public static function initializeFiles(?string $install_path=null, array $default_repositories=[]): void
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
throw new OperationException('You must be running as root to initialize ncc files');
|
||||
}
|
||||
|
@ -523,7 +523,7 @@
|
|||
*/
|
||||
public static function finalizePermissions(): void
|
||||
{
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM)
|
||||
if(Resolver::resolveScope() !== Scopes::SYSTEM->value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -56,10 +56,10 @@
|
|||
|
||||
if(self::$user_id_cache === 0)
|
||||
{
|
||||
return Scopes::SYSTEM;
|
||||
return Scopes::SYSTEM->value;
|
||||
}
|
||||
|
||||
return Scopes::USER;
|
||||
return Scopes::USER->value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -111,8 +111,8 @@ namespace ncc\Utilities;
|
|||
|
||||
switch($input)
|
||||
{
|
||||
case Scopes::SYSTEM:
|
||||
case Scopes::USER:
|
||||
case Scopes::SYSTEM->value:
|
||||
case Scopes::USER->value:
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Add table
Reference in a new issue