diff --git a/src/ncc/Classes/PhpExtension/NccCompiler.php b/src/ncc/Classes/PhpExtension/NccCompiler.php index e68254a..5fe93e5 100644 --- a/src/ncc/Classes/PhpExtension/NccCompiler.php +++ b/src/ncc/Classes/PhpExtension/NccCompiler.php @@ -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); } } \ No newline at end of file diff --git a/src/ncc/Enums/Flags/ComponentFlags.php b/src/ncc/Enums/Flags/ComponentFlags.php index ab70ad8..dc0770d 100644 --- a/src/ncc/Enums/Flags/ComponentFlags.php +++ b/src/ncc/Enums/Flags/ComponentFlags.php @@ -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'; } \ No newline at end of file diff --git a/src/ncc/Objects/Package/Component.php b/src/ncc/Objects/Package/Component.php index 3a41d7a..2c96067 100644 --- a/src/ncc/Objects/Package/Component.php +++ b/src/ncc/Objects/Package/Component.php @@ -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); } }