Convert ComponentFlags constants to enum cases

This commit is contained in:
netkas 2024-09-14 08:58:26 -04:00
parent 863dffafe7
commit 039147c8a8
3 changed files with 9 additions and 17 deletions

View file

@ -58,7 +58,7 @@
);
$component = new Component($component_name, ZiProto::encode($stmts), ComponentDataType::AST->value);
$component->addFlag(ComponentFlags::PHP_AST);
$component->addFlag(ComponentFlags::PHP_AST->value);
$pointer = $package_writer->addComponent($component);
foreach(AstWalker::extractClasses($stmts) as $class)
@ -74,7 +74,7 @@
}
$component = new Component($component_name, Base64::encode(IO::fread($file_path)), ComponentDataType::BASE64_ENCODED->value);
$component->addFlag(ComponentFlags::PHP_B64);
$component->addFlag(ComponentFlags::PHP_B64->value);
$package_writer->addComponent($component);
}
}

View file

@ -22,23 +22,15 @@
namespace ncc\Enums\Flags;
final class ComponentFlags
enum ComponentFlags : string
{
/**
* Indicates that the component is the AST of a PHP file encoded with msgpack.
*/
public const PHP_AST = 'php_ast';
case PHP_AST = 'php_ast';
/**
* Indicates that the component is a PHP file encoded with base64.
*/
public const PHP_B64 = 'php_b64';
/**
* All the possible flags of a component
*/
public const ALL = [
self::PHP_AST,
self::PHP_B64
];
case PHP_B64 = 'php_b64';
}

View file

@ -173,7 +173,7 @@
return $this->data;
case ComponentDataType::BASE64_ENCODED->value:
if(in_array(ComponentFlags::PHP_B64, $this->flags, true))
if(in_array(ComponentFlags::PHP_B64->value, $this->flags, true))
{
try
{
@ -186,14 +186,14 @@
}
catch(Exception $e)
{
throw new OperationException(sprintf('Failed to decode component %s with data type %s because the component is corrupted: %s', $this->name, ComponentFlags::PHP_B64, $e->getMessage()), $e->getCode(), $e);
throw new OperationException(sprintf('Failed to decode component %s with data type %s because the component is corrupted: %s', $this->name, ComponentFlags::PHP_B64->value, $e->getMessage()), $e->getCode(), $e);
}
}
return base64_decode($this->data);
case ComponentDataType::AST->value:
if(in_array(ComponentFlags::PHP_AST, $this->flags, true))
if(in_array(ComponentFlags::PHP_AST->value, $this->flags, true))
{
try
{
@ -206,7 +206,7 @@
}
catch(Exception $e)
{
throw new OperationException(sprintf('Failed to decode component %s with data type %s because the component is corrupted: %s', $this->name, ComponentFlags::PHP_AST, $e->getMessage()), $e->getCode(), $e);
throw new OperationException(sprintf('Failed to decode component %s with data type %s because the component is corrupted: %s', $this->name, ComponentFlags::PHP_AST->value, $e->getMessage()), $e->getCode(), $e);
}
}