Convert PackageDirectory constants to enum cases
This commit is contained in:
parent
42473390e8
commit
d612c67cb0
5 changed files with 45 additions and 44 deletions
|
@ -320,7 +320,7 @@
|
|||
*/
|
||||
public function getAssembly(): Assembly
|
||||
{
|
||||
$directory = sprintf('@%s', PackageDirectory::ASSEMBLY);
|
||||
$directory = sprintf('@%s', PackageDirectory::ASSEMBLY->value);
|
||||
|
||||
if(isset($this->cache[$directory]))
|
||||
{
|
||||
|
@ -346,7 +346,7 @@
|
|||
*/
|
||||
public function getMetadata(): Metadata
|
||||
{
|
||||
$directory = sprintf('@%s', PackageDirectory::METADATA);
|
||||
$directory = sprintf('@%s', PackageDirectory::METADATA->value);
|
||||
|
||||
if(isset($this->cache[$directory]))
|
||||
{
|
||||
|
@ -375,7 +375,7 @@
|
|||
*/
|
||||
public function getInstaller(): ?Installer
|
||||
{
|
||||
$directory = sprintf('@%s', PackageDirectory::INSTALLER);
|
||||
$directory = sprintf('@%s', PackageDirectory::INSTALLER->value);
|
||||
|
||||
if(isset($this->cache[$directory]))
|
||||
{
|
||||
|
@ -400,7 +400,7 @@
|
|||
public function getDependencies(): array
|
||||
{
|
||||
$dependencies = [];
|
||||
$directory = sprintf('@%s:', PackageDirectory::DEPENDENCIES);
|
||||
$directory = sprintf('@%s:', PackageDirectory::DEPENDENCIES->value);
|
||||
|
||||
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||
{
|
||||
|
@ -422,7 +422,7 @@
|
|||
*/
|
||||
public function getDependency(string $name): Dependency
|
||||
{
|
||||
$dependency_name = sprintf('@%s:%s', PackageDirectory::DEPENDENCIES, $name);
|
||||
$dependency_name = sprintf('@%s:%s', PackageDirectory::DEPENDENCIES->value, $name);
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value[$dependency_name]]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Dependency \'%s\' not found in package', $name));
|
||||
|
@ -452,7 +452,7 @@
|
|||
public function getExecutionUnits(): array
|
||||
{
|
||||
$execution_units = [];
|
||||
$directory = sprintf('@%s:', PackageDirectory::EXECUTION_UNITS);
|
||||
$directory = sprintf('@%s:', PackageDirectory::EXECUTION_UNITS->value);
|
||||
|
||||
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||
{
|
||||
|
@ -474,7 +474,7 @@
|
|||
*/
|
||||
public function getExecutionUnit(string $name): ExecutionUnit
|
||||
{
|
||||
$execution_unit_name = sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS, $name);
|
||||
$execution_unit_name = sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS->value, $name);
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value[$execution_unit_name]]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Execution unit \'%s\' not found in package', $name));
|
||||
|
@ -504,7 +504,7 @@
|
|||
public function getComponents(): array
|
||||
{
|
||||
$components = [];
|
||||
$directory = sprintf('@%s:', PackageDirectory::COMPONENTS);
|
||||
$directory = sprintf('@%s:', PackageDirectory::COMPONENTS->value);
|
||||
|
||||
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||
{
|
||||
|
@ -525,7 +525,7 @@
|
|||
public function getClassMap(): array
|
||||
{
|
||||
$class_map = [];
|
||||
$directory = sprintf('@%s:', PackageDirectory::CLASS_POINTER);
|
||||
$directory = sprintf('@%s:', PackageDirectory::CLASS_POINTER->value);
|
||||
|
||||
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||
{
|
||||
|
@ -547,7 +547,7 @@
|
|||
*/
|
||||
public function getComponent(string $name): Component
|
||||
{
|
||||
$component_name = sprintf('@%s:%s', PackageDirectory::COMPONENTS, $name);
|
||||
$component_name = sprintf('@%s:%s', PackageDirectory::COMPONENTS->value, $name);
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value][$component_name]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Component \'%s\' not found in package', $name));
|
||||
|
@ -578,7 +578,7 @@
|
|||
*/
|
||||
public function getComponentByClass(string $class): Component
|
||||
{
|
||||
$class_name = sprintf('@%s:%s', PackageDirectory::CLASS_POINTER, $class);
|
||||
$class_name = sprintf('@%s:%s', PackageDirectory::CLASS_POINTER->value, $class);
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value[$class_name]]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Class map \'%s\' not found in package', $class));
|
||||
|
@ -595,7 +595,7 @@
|
|||
public function getResources(): array
|
||||
{
|
||||
$resources = [];
|
||||
$directory = sprintf('@%s:', PackageDirectory::RESOURCES);
|
||||
$directory = sprintf('@%s:', PackageDirectory::RESOURCES->value);
|
||||
|
||||
foreach($this->headers[PackageStructure::DIRECTORY->value] as $name => $location)
|
||||
{
|
||||
|
@ -617,7 +617,7 @@
|
|||
*/
|
||||
public function getResource(string $name): Resource
|
||||
{
|
||||
$resource_name = sprintf('@%s:%s', PackageDirectory::RESOURCES, $name);
|
||||
$resource_name = sprintf('@%s:%s', PackageDirectory::RESOURCES->value, $name);
|
||||
if(!isset($this->headers[PackageStructure::DIRECTORY->value[$resource_name]]))
|
||||
{
|
||||
throw new ConfigurationException(sprintf('Resource \'%s\' not found in package', $name));
|
||||
|
|
|
@ -272,7 +272,7 @@
|
|||
*/
|
||||
public function setAssembly(Assembly $assembly): array
|
||||
{
|
||||
return $this->add(sprintf('@%s', PackageDirectory::ASSEMBLY), ZiProto::encode($assembly->toArray(true)));
|
||||
return $this->add(sprintf('@%s', PackageDirectory::ASSEMBLY->value), ZiProto::encode($assembly->toArray(true)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -283,7 +283,7 @@
|
|||
*/
|
||||
public function setMetadata(Metadata $metadata): array
|
||||
{
|
||||
return $this->add(sprintf('@%s', PackageDirectory::METADATA), ZiProto::encode($metadata->toArray(true)));
|
||||
return $this->add(sprintf('@%s', PackageDirectory::METADATA->value), ZiProto::encode($metadata->toArray(true)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -294,7 +294,7 @@
|
|||
*/
|
||||
public function setInstaller(Installer $installer): array
|
||||
{
|
||||
return $this->add(sprintf('@%s', PackageDirectory::INSTALLER), ZiProto::encode($installer->toArray(true)));
|
||||
return $this->add(sprintf('@%s', PackageDirectory::INSTALLER->value), ZiProto::encode($installer->toArray(true)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,7 +305,7 @@
|
|||
*/
|
||||
public function addDependencyConfiguration(Dependency $dependency): array
|
||||
{
|
||||
return $this->add(sprintf('@%s:%s', PackageDirectory::DEPENDENCIES, $dependency->getName()), ZiProto::encode($dependency->toArray(true)));
|
||||
return $this->add(sprintf('@%s:%s', PackageDirectory::DEPENDENCIES->value, $dependency->getName()), ZiProto::encode($dependency->toArray(true)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -316,7 +316,7 @@
|
|||
*/
|
||||
public function addExecutionUnit(ExecutionUnit $unit): array
|
||||
{
|
||||
return $this->add(sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS, $unit->getExecutionPolicy()->getName()), ZiProto::encode($unit->toArray(true)));
|
||||
return $this->add(sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS->value, $unit->getExecutionPolicy()->getName()), ZiProto::encode($unit->toArray(true)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -327,7 +327,7 @@
|
|||
*/
|
||||
public function addComponent(Component $component): array
|
||||
{
|
||||
return $this->add(sprintf('@%s:%s', PackageDirectory::COMPONENTS, $component->getName()), ZiProto::encode($component->toArray(true)));
|
||||
return $this->add(sprintf('@%s:%s', PackageDirectory::COMPONENTS->value, $component->getName()), ZiProto::encode($component->toArray(true)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -338,7 +338,7 @@
|
|||
*/
|
||||
public function addResource(Resource $resource): array
|
||||
{
|
||||
return $this->add(sprintf('@%s:%s', PackageDirectory::RESOURCES, $resource->getName()), ZiProto::encode($resource->toArray(true)));
|
||||
return $this->add(sprintf('@%s:%s', PackageDirectory::RESOURCES->value, $resource->getName()), ZiProto::encode($resource->toArray(true)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -351,7 +351,7 @@
|
|||
*/
|
||||
public function mapClass(string $class, int $offset, int $length): void
|
||||
{
|
||||
$this->addPointer(sprintf('@%s:%s', PackageDirectory::CLASS_POINTER, $class), $offset, $length);
|
||||
$this->addPointer(sprintf('@%s:%s', PackageDirectory::CLASS_POINTER->value, $class), $offset, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -372,10 +372,10 @@
|
|||
|
||||
switch((int)substr(explode(':', $name, 2)[0], 1))
|
||||
{
|
||||
case PackageDirectory::METADATA:
|
||||
case PackageDirectory::ASSEMBLY:
|
||||
case PackageDirectory::INSTALLER:
|
||||
case PackageDirectory::EXECUTION_UNITS:
|
||||
case PackageDirectory::METADATA->value:
|
||||
case PackageDirectory::ASSEMBLY->value:
|
||||
case PackageDirectory::INSTALLER->value:
|
||||
case PackageDirectory::EXECUTION_UNITS->value:
|
||||
Console::outDebug(sprintf('Skipping %s', $name));
|
||||
break;
|
||||
|
||||
|
|
|
@ -480,8 +480,8 @@
|
|||
|
||||
return match (Resolver::componentType($acquired_file))
|
||||
{
|
||||
PackageDirectory::RESOURCES => self::$imported_packages[$package]->getResource(Resolver::componentName($acquired_file))->getData(),
|
||||
PackageDirectory::COMPONENTS => self::$imported_packages[$package]->getComponent(Resolver::componentName($acquired_file))->getData([ComponentDecodeOptions::AS_FILE]),
|
||||
PackageDirectory::RESOURCES->value => self::$imported_packages[$package]->getResource(Resolver::componentName($acquired_file))->getData(),
|
||||
PackageDirectory::COMPONENTS->value => self::$imported_packages[$package]->getComponent(Resolver::componentName($acquired_file))->getData([ComponentDecodeOptions::AS_FILE]),
|
||||
default => throw new IOException(sprintf('Unable to acquire file "%s" from package "%s" because it is not a resource or component', $path, $package)),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -22,21 +22,21 @@
|
|||
|
||||
namespace ncc\Enums;
|
||||
|
||||
final class PackageDirectory
|
||||
enum PackageDirectory : int
|
||||
{
|
||||
public const ASSEMBLY = 0x61737365;
|
||||
case ASSEMBLY = 0x61737365;
|
||||
|
||||
public const METADATA = 0x6D657461;
|
||||
case METADATA = 0x6D657461;
|
||||
|
||||
public const INSTALLER = 0x696E7374;
|
||||
case INSTALLER = 0x696E7374;
|
||||
|
||||
public const DEPENDENCIES = 0x64657065;
|
||||
case DEPENDENCIES = 0x64657065;
|
||||
|
||||
public const EXECUTION_UNITS = 0x65786563;
|
||||
case EXECUTION_UNITS = 0x65786563;
|
||||
|
||||
public const COMPONENTS = 0x636F6D70;
|
||||
case COMPONENTS = 0x636F6D70;
|
||||
|
||||
public const RESOURCES = 0x7265736F;
|
||||
case RESOURCES = 0x7265736F;
|
||||
|
||||
public const CLASS_POINTER = 0x636C6173;
|
||||
case CLASS_POINTER = 0x636C6173;
|
||||
}
|
|
@ -284,16 +284,17 @@
|
|||
throw new InvalidArgumentException(sprintf('Invalid component prefix "%s"', $file_stub_code));
|
||||
}
|
||||
|
||||
// TODO: What the hell is this?
|
||||
return match ((int)$file_stub_code)
|
||||
{
|
||||
PackageDirectory::METADATA => PackageDirectory::METADATA,
|
||||
PackageDirectory::ASSEMBLY => PackageDirectory::ASSEMBLY,
|
||||
PackageDirectory::EXECUTION_UNITS => PackageDirectory::EXECUTION_UNITS,
|
||||
PackageDirectory::INSTALLER => PackageDirectory::INSTALLER,
|
||||
PackageDirectory::DEPENDENCIES => PackageDirectory::DEPENDENCIES,
|
||||
PackageDirectory::CLASS_POINTER => PackageDirectory::CLASS_POINTER,
|
||||
PackageDirectory::RESOURCES => PackageDirectory::RESOURCES,
|
||||
PackageDirectory::COMPONENTS => PackageDirectory::COMPONENTS,
|
||||
PackageDirectory::METADATA->value => PackageDirectory::METADATA->value,
|
||||
PackageDirectory::ASSEMBLY->value => PackageDirectory::ASSEMBLY->value,
|
||||
PackageDirectory::EXECUTION_UNITS->value => PackageDirectory::EXECUTION_UNITS->value,
|
||||
PackageDirectory::INSTALLER->value => PackageDirectory::INSTALLER->value,
|
||||
PackageDirectory::DEPENDENCIES->value => PackageDirectory::DEPENDENCIES->value,
|
||||
PackageDirectory::CLASS_POINTER->value => PackageDirectory::CLASS_POINTER->value,
|
||||
PackageDirectory::RESOURCES->value => PackageDirectory::RESOURCES->value,
|
||||
PackageDirectory::COMPONENTS->value => PackageDirectory::COMPONENTS->value,
|
||||
default => throw new InvalidArgumentException(sprintf('Invalid component type "%s"', $component_path)),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue