From 15fd06d2d0126f8380a4c9b4f3e19db262768b2d Mon Sep 17 00:00:00 2001 From: Netkas Date: Sat, 19 Aug 2023 11:06:11 -0400 Subject: [PATCH] - Implemented Bytecode compiling properly into `\ncc\Objects > ProjectConfiguration` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > Installer` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > ExecutionPolicy` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > Dependecy` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > Compiler` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > Build` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > UpdateSource` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > Project` --- CHANGELOG.md | 7 + src/ncc/CLI/Management/PackageManagerMenu.php | 20 +- src/ncc/CLI/Management/ProjectMenu.php | 34 +-- src/ncc/Classes/BashExtension/BashRunner.php | 2 +- .../ComposerSourceBuiltin.php | 28 +-- src/ncc/Classes/LuaExtension/LuaRunner.php | 2 +- .../Classes/NccExtension/PackageCompiler.php | 44 ++-- src/ncc/Classes/NccExtension/Runner.php | 2 +- src/ncc/Classes/PerlExtension/PerlRunner.php | 2 +- src/ncc/Classes/PhpExtension/PhpCompiler.php | 26 +- src/ncc/Classes/PhpExtension/PhpRunner.php | 2 +- .../Classes/PythonExtension/Python2Runner.php | 2 +- .../Classes/PythonExtension/Python3Runner.php | 2 +- .../Classes/PythonExtension/PythonRunner.php | 2 +- src/ncc/Managers/ExecutionPointerManager.php | 84 +++---- src/ncc/Managers/PackageManager.php | 74 +++--- src/ncc/Managers/ProjectManager.php | 26 +- src/ncc/Objects/ExecutionPointers.php | 8 +- src/ncc/Objects/Package.php | 8 +- src/ncc/Objects/Package/ExecutionUnit.php | 2 +- .../Objects/PackageLock/DependencyEntry.php | 4 +- src/ncc/Objects/ProjectConfiguration.php | 90 +++---- .../Objects/ProjectConfiguration/Build.php | 232 ++++++++++-------- .../Objects/ProjectConfiguration/Compiler.php | 134 +++++----- .../ProjectConfiguration/Dependency.php | 149 +++++------ .../ProjectConfiguration/ExecutionPolicy.php | 115 +++++---- .../ProjectConfiguration/Installer.php | 113 +++++---- .../Objects/ProjectConfiguration/Project.php | 81 +++--- .../ProjectConfiguration/UpdateSource.php | 66 ++--- src/ncc/Runtime.php | 6 +- src/ncc/Utilities/Functions.php | 4 +- 31 files changed, 726 insertions(+), 645 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1be9b2..245eab8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,6 +91,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Corrected code-smell and code style issues in `\ncc\Objects\Vault\Password > UsernamePassword` - Extended `PasswordInterface` with `BytecodeObjectInterface` - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\SymlinkDictionary > SymlinkEntry` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > UpdateSource` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > Project` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > Installer` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > ExecutionPolicy` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > Dependecy` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > Compiler` + - Implemented interface `BytecodeObjectInterface` into `\ncc\Objects\ProjectConfiguration > Build` ### Removed - Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions` diff --git a/src/ncc/CLI/Management/PackageManagerMenu.php b/src/ncc/CLI/Management/PackageManagerMenu.php index d81a114..6c2f57a 100644 --- a/src/ncc/CLI/Management/PackageManagerMenu.php +++ b/src/ncc/CLI/Management/PackageManagerMenu.php @@ -316,7 +316,7 @@ Console::out(sprintf('%s=%s (%s)', Console::formatColor($package, ConsoleColors::LIGHT_GREEN), Console::formatColor($version, ConsoleColors::LIGHT_MAGENTA), - $package_manager->getPackageVersion($package, $version)->Compiler->Extension + $package_manager->getPackageVersion($package, $version)->Compiler->extension )); } catch(Exception $e) @@ -505,7 +505,7 @@ { try { - $dependency_package = $package_manager->getPackage($dependency->Name); + $dependency_package = $package_manager->getPackage($dependency->name); } catch (PackageLockException $e) { @@ -517,7 +517,7 @@ { try { - $dependency_version = $dependency_package->getVersion($dependency->Version); + $dependency_version = $dependency_package->getVersion($dependency->version); } catch (VersionNotFoundException $e) { @@ -535,8 +535,8 @@ if($require_dependency) { $dependencies[] = sprintf(' %s %s', - Console::formatColor($dependency->Name, ConsoleColors::GREEN), - Console::formatColor($dependency->Version, ConsoleColors::LIGHT_MAGENTA) + Console::formatColor($dependency->name, ConsoleColors::GREEN), + Console::formatColor($dependency->version, ConsoleColors::LIGHT_MAGENTA) ); } } @@ -549,21 +549,21 @@ } Console::out(sprintf('Extension: %s', - Console::formatColor($package->header->CompilerExtension->Extension, ConsoleColors::GREEN) + Console::formatColor($package->header->CompilerExtension->extension, ConsoleColors::GREEN) )); - if($package->header->CompilerExtension->MaximumVersion !== null) + if($package->header->CompilerExtension->maximum_version !== null) { Console::out(sprintf('Maximum Version: %s', - Console::formatColor($package->header->CompilerExtension->MaximumVersion, ConsoleColors::LIGHT_MAGENTA) + Console::formatColor($package->header->CompilerExtension->maximum_version, ConsoleColors::LIGHT_MAGENTA) )); } - if($package->header->CompilerExtension->MinimumVersion !== null) + if($package->header->CompilerExtension->minimum_version !== null) { Console::out(sprintf('Minimum Version: %s', - Console::formatColor($package->header->CompilerExtension->MinimumVersion, ConsoleColors::LIGHT_MAGENTA) + Console::formatColor($package->header->CompilerExtension->minimum_version, ConsoleColors::LIGHT_MAGENTA) )); } diff --git a/src/ncc/CLI/Management/ProjectMenu.php b/src/ncc/CLI/Management/ProjectMenu.php index da1e21f..99289b2 100644 --- a/src/ncc/CLI/Management/ProjectMenu.php +++ b/src/ncc/CLI/Management/ProjectMenu.php @@ -122,7 +122,7 @@ if(in_array($compiler_extension, CompilerExtensions::ALL)) { - $Compiler->Extension = $compiler_extension; + $Compiler->extension = $compiler_extension; } else { @@ -133,7 +133,7 @@ else { // Default PHP Extension - $Compiler->Extension = CompilerExtensions::PHP; + $Compiler->extension = CompilerExtensions::PHP; } // If a minimum and maximum version is specified @@ -145,28 +145,28 @@ $max_version = strtolower($args['max-version'] ?? $args['max-ver']); $min_version = strtolower($args['min-version'] ?? $args['min-ver']); - switch($Compiler->Extension) + switch($Compiler->extension) { case CompilerExtensions::PHP: if(!in_array($max_version, CompilerExtensionSupportedVersions::PHP)) { - Console::outError('The extension \'' . $Compiler->Extension . '\' does not support version ' . $max_version, true, 1); + Console::outError('The extension \'' . $Compiler->extension . '\' does not support version ' . $max_version, true, 1); return; } if(!in_array($min_version, CompilerExtensionSupportedVersions::PHP)) { - Console::outError('The extension \'' . $Compiler->Extension . '\' does not support version ' . $min_version, true, 1); + Console::outError('The extension \'' . $Compiler->extension . '\' does not support version ' . $min_version, true, 1); return; } - $Compiler->MaximumVersion = $max_version; - $Compiler->MinimumVersion = $min_version; + $Compiler->maximum_version = $max_version; + $Compiler->minimum_version = $min_version; break; default: - Console::outError('Unsupported extension: ' . $Compiler->Extension, true, 1); + Console::outError('Unsupported extension: ' . $Compiler->extension, true, 1); return; } } @@ -174,37 +174,37 @@ elseif(isset($args['version']) || isset($args['ver'])) { $version = strtolower($args['version'] ?? $args['ver']); - switch($Compiler->Extension) + switch($Compiler->extension) { case CompilerExtensions::PHP: if(!in_array($version, CompilerExtensionSupportedVersions::PHP)) { - Console::outError('The extension \'' . $Compiler->Extension . '\' does not support version ' . $version, true, 1); + Console::outError('The extension \'' . $Compiler->extension . '\' does not support version ' . $version, true, 1); return; } - $Compiler->MaximumVersion = $version; - $Compiler->MinimumVersion = $version; + $Compiler->maximum_version = $version; + $Compiler->minimum_version = $version; break; default: - Console::outError('Unsupported extension: ' . $Compiler->Extension, true, 1); + Console::outError('Unsupported extension: ' . $Compiler->extension, true, 1); return; } } // If no version is specified, use the default version else { - switch($Compiler->Extension) + switch($Compiler->extension) { case CompilerExtensions::PHP: - $Compiler->MinimumVersion = CompilerExtensionDefaultVersions::PHP[0]; - $Compiler->MaximumVersion = CompilerExtensionDefaultVersions::PHP[1]; + $Compiler->minimum_version = CompilerExtensionDefaultVersions::PHP[0]; + $Compiler->maximum_version = CompilerExtensionDefaultVersions::PHP[1]; break; default: - Console::outError('Unsupported extension: ' . $Compiler->Extension, true, 1); + Console::outError('Unsupported extension: ' . $Compiler->extension, true, 1); return; } } diff --git a/src/ncc/Classes/BashExtension/BashRunner.php b/src/ncc/Classes/BashExtension/BashRunner.php index babef52..f744564 100644 --- a/src/ncc/Classes/BashExtension/BashRunner.php +++ b/src/ncc/Classes/BashExtension/BashRunner.php @@ -46,7 +46,7 @@ namespace ncc\Classes\BashExtension; $execution_unit->execution_policy = $policy; $execution_unit->Data = IO::fread($path); - $policy->Execute->Target = null; + $policy->execute->Target = null; return $execution_unit; } diff --git a/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php b/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php index 7a3c012..4aa24bd 100644 --- a/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php +++ b/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php @@ -363,9 +363,9 @@ namespace ncc\Classes\ComposerExtension; $project_configuration->assembly->Package = self::toPackageName($composer_package->Name); // Add the update source - $project_configuration->project->UpdateSource = new ProjectConfiguration\UpdateSource(); - $project_configuration->project->UpdateSource->Source = sprintf('%s@composer', str_ireplace('\\', '/', $composer_package->Name)); - $project_configuration->project->UpdateSource->Repository = null; + $project_configuration->project->update_source = new ProjectConfiguration\UpdateSource(); + $project_configuration->project->update_source->source = sprintf('%s@composer', str_ireplace('\\', '/', $composer_package->Name)); + $project_configuration->project->update_source->repository = null; // Process the dependencies if($composer_package->Require !== null && count($composer_package->Require) > 0) @@ -381,10 +381,10 @@ namespace ncc\Classes\ComposerExtension; } $dependency = new ProjectConfiguration\Dependency(); - $dependency->Name = $package_name; - $dependency->SourceType = DependencySourceType::LOCAL; - $dependency->Version = self::versionMap($item->PackageName, $version_map); - $dependency->Source = $package_name . '.ncc'; + $dependency->name = $package_name; + $dependency->source_type = DependencySourceType::LOCAL; + $dependency->version = self::versionMap($item->PackageName, $version_map); + $dependency->source = $package_name . '.ncc'; $project_configuration->build->addDependency($dependency); } } @@ -395,14 +395,14 @@ namespace ncc\Classes\ComposerExtension; $build_configuration->OutputPath = 'build'; // Apply the final properties - $project_configuration->build->Configurations[] = $build_configuration; - $project_configuration->build->DefaultConfiguration = 'default'; - $project_configuration->build->SourcePath = '.src'; + $project_configuration->build->build_configurations[] = $build_configuration; + $project_configuration->build->default_configuration = 'default'; + $project_configuration->build->source_path = '.src'; // Apply a compiler extension - $project_configuration->project->Compiler->Extension = CompilerExtensions::PHP; - $project_configuration->project->Compiler->MinimumVersion = CompilerExtensionSupportedVersions::PHP[0]; - $project_configuration->project->Compiler->MaximumVersion = CompilerExtensionSupportedVersions::PHP[(count(CompilerExtensionSupportedVersions::PHP) - 1)]; + $project_configuration->project->compiler->extension = CompilerExtensions::PHP; + $project_configuration->project->compiler->minimum_version = CompilerExtensionSupportedVersions::PHP[0]; + $project_configuration->project->compiler->maximum_version = CompilerExtensionSupportedVersions::PHP[(count(CompilerExtensionSupportedVersions::PHP) - 1)]; return $project_configuration; } @@ -793,7 +793,7 @@ namespace ncc\Classes\ComposerExtension; if (count($static_files) > 0) { - $project_configuration->project->Options['static_files'] = $static_files; + $project_configuration->project->options['static_files'] = $static_files; foreach ($static_files as $file) { diff --git a/src/ncc/Classes/LuaExtension/LuaRunner.php b/src/ncc/Classes/LuaExtension/LuaRunner.php index 0d9be05..1ae7d62 100644 --- a/src/ncc/Classes/LuaExtension/LuaRunner.php +++ b/src/ncc/Classes/LuaExtension/LuaRunner.php @@ -36,7 +36,7 @@ namespace ncc\Classes\LuaExtension; public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit { $execution_unit = new ExecutionUnit(); - $policy->Execute->Target = null; + $policy->execute->Target = null; $execution_unit->execution_policy = $policy; $execution_unit->Data = IO::fread($path); diff --git a/src/ncc/Classes/NccExtension/PackageCompiler.php b/src/ncc/Classes/NccExtension/PackageCompiler.php index e955c0f..b914fae 100644 --- a/src/ncc/Classes/NccExtension/PackageCompiler.php +++ b/src/ncc/Classes/NccExtension/PackageCompiler.php @@ -79,21 +79,21 @@ { Console::outDebug(sprintf('assembly.%s: %s', $prop, ($value ?? 'n/a'))); } - foreach($configuration->project->Compiler->toArray() as $prop => $value) + foreach($configuration->project->compiler->toArray() as $prop => $value) { Console::outDebug(sprintf('compiler.%s: %s', $prop, ($value ?? 'n/a'))); } } // Select the correct compiler for the specified extension - if (strtolower($configuration->project->Compiler->Extension) === CompilerExtensions::PHP) + if (strtolower($configuration->project->compiler->extension) === CompilerExtensions::PHP) { /** @var CompilerInterface $Compiler */ $Compiler = new PhpCompiler($configuration, $manager->getProjectPath()); } else { - throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $configuration->project->Compiler->Extension . '\' is not supported'); + throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $configuration->project->compiler->extension . '\' is not supported'); } $build_configuration = $configuration->build->getBuildConfiguration($build_configuration)->Name; @@ -178,7 +178,7 @@ /** @var ProjectConfiguration\ExecutionPolicy $policy */ foreach($configuration->execution_policies as $policy) { - Console::outVerbose(sprintf('Compiling Execution Policy %s', $policy->Name)); + Console::outVerbose(sprintf('Compiling Execution Policy %s', $policy->name)); /** @noinspection DisconnectedForeachInstructionInspection */ if($total_items > 5) @@ -186,7 +186,7 @@ Console::inlineProgressBar($processed_items, $total_items); } - $unit_path = Functions::correctDirectorySeparator($path . $policy->Execute->Target); + $unit_path = Functions::correctDirectorySeparator($path . $policy->execute->Target); $execution_units[] = Functions::compileRunner($unit_path, $policy); } @@ -272,7 +272,7 @@ $units = []; foreach($package->execution_units as $executionUnit) { - Console::outDebug(sprintf('compiling execution unit constant %s (%s)', $executionUnit->execution_policy->Name, implode(', ', array_keys($refs)))); + Console::outDebug(sprintf('compiling execution unit constant %s (%s)', $executionUnit->execution_policy->name, implode(', ', array_keys($refs)))); $units[] = self::compileExecutionUnitConstants($executionUnit, $refs); } $package->execution_units = $units; @@ -323,46 +323,46 @@ */ public static function compileExecutionUnitConstants(Package\ExecutionUnit $unit, array $refs): Package\ExecutionUnit { - $unit->execution_policy->Message = self::compileConstants($unit->execution_policy->Message, $refs); + $unit->execution_policy->message = self::compileConstants($unit->execution_policy->message, $refs); - if($unit->execution_policy->ExitHandlers !== null) + if($unit->execution_policy->exit_handlers !== null) { - if($unit->execution_policy->ExitHandlers->Success !== null) + if($unit->execution_policy->exit_handlers->Success !== null) { - $unit->execution_policy->ExitHandlers->Success->Message = self::compileConstants($unit->execution_policy->ExitHandlers->Success->Message, $refs); + $unit->execution_policy->exit_handlers->Success->Message = self::compileConstants($unit->execution_policy->exit_handlers->Success->Message, $refs); } - if($unit->execution_policy->ExitHandlers->Error !== null) + if($unit->execution_policy->exit_handlers->Error !== null) { - $unit->execution_policy->ExitHandlers->Error->Message = self::compileConstants($unit->execution_policy->ExitHandlers->Error->Message, $refs); + $unit->execution_policy->exit_handlers->Error->Message = self::compileConstants($unit->execution_policy->exit_handlers->Error->Message, $refs); } - if($unit->execution_policy->ExitHandlers->Warning !== null) + if($unit->execution_policy->exit_handlers->Warning !== null) { - $unit->execution_policy->ExitHandlers->Warning->Message = self::compileConstants($unit->execution_policy->ExitHandlers->Warning->Message, $refs); + $unit->execution_policy->exit_handlers->Warning->Message = self::compileConstants($unit->execution_policy->exit_handlers->Warning->Message, $refs); } } - if($unit->execution_policy->Execute !== null) + if($unit->execution_policy->execute !== null) { - if($unit->execution_policy->Execute->Target !== null) + if($unit->execution_policy->execute->Target !== null) { - $unit->execution_policy->Execute->Target = self::compileConstants($unit->execution_policy->Execute->Target, $refs); + $unit->execution_policy->execute->Target = self::compileConstants($unit->execution_policy->execute->Target, $refs); } - if($unit->execution_policy->Execute->WorkingDirectory !== null) + if($unit->execution_policy->execute->WorkingDirectory !== null) { - $unit->execution_policy->Execute->WorkingDirectory = self::compileConstants($unit->execution_policy->Execute->WorkingDirectory, $refs); + $unit->execution_policy->execute->WorkingDirectory = self::compileConstants($unit->execution_policy->execute->WorkingDirectory, $refs); } - if($unit->execution_policy->Execute->Options !== null && count($unit->execution_policy->Execute->Options) > 0) + if($unit->execution_policy->execute->Options !== null && count($unit->execution_policy->execute->Options) > 0) { $options = []; - foreach($unit->execution_policy->Execute->Options as $key=> $value) + foreach($unit->execution_policy->execute->Options as $key=> $value) { $options[self::compileConstants($key, $refs)] = self::compileConstants($value, $refs); } - $unit->execution_policy->Execute->Options = $options; + $unit->execution_policy->execute->Options = $options; } } diff --git a/src/ncc/Classes/NccExtension/Runner.php b/src/ncc/Classes/NccExtension/Runner.php index 06feaa0..a2b3739 100644 --- a/src/ncc/Classes/NccExtension/Runner.php +++ b/src/ncc/Classes/NccExtension/Runner.php @@ -56,7 +56,7 @@ $ExecutionPointerManager = new ExecutionPointerManager(); $ExecutionPointerManager->addUnit($package, $version, $unit, true); - $ExecutionPointerManager->executeUnit($package, $version, $unit->execution_policy->Name); + $ExecutionPointerManager->executeUnit($package, $version, $unit->execution_policy->name); $ExecutionPointerManager->cleanTemporaryUnits(); } } \ No newline at end of file diff --git a/src/ncc/Classes/PerlExtension/PerlRunner.php b/src/ncc/Classes/PerlExtension/PerlRunner.php index 8e513cd..dd722ca 100644 --- a/src/ncc/Classes/PerlExtension/PerlRunner.php +++ b/src/ncc/Classes/PerlExtension/PerlRunner.php @@ -45,7 +45,7 @@ public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit { $execution_unit = new ExecutionUnit(); - $policy->Execute->Target = null; + $policy->execute->Target = null; if(!file_exists($path) && !is_file($path)) { diff --git a/src/ncc/Classes/PhpExtension/PhpCompiler.php b/src/ncc/Classes/PhpExtension/PhpCompiler.php index 28ad02c..2b29881 100644 --- a/src/ncc/Classes/PhpExtension/PhpCompiler.php +++ b/src/ncc/Classes/PhpExtension/PhpCompiler.php @@ -108,11 +108,11 @@ // Create the package object $this->package = new Package(); $this->package->assembly = $this->project->assembly; - $this->package->dependencies = $this->project->build->Dependencies; - $this->package->main_execution_policy = $this->project->build->Main; + $this->package->dependencies = $this->project->build->dependencies; + $this->package->main_execution_policy = $this->project->build->main; // Add the option to create a symbolic link to the package - if(isset($this->project->project->Options['create_symlink']) && $this->project->project->Options['create_symlink'] === True) + if(isset($this->project->project->options['create_symlink']) && $this->project->project->options['create_symlink'] === True) { $this->package->header->Options['create_symlink'] = true; } @@ -122,17 +122,17 @@ $this->package->header->RuntimeConstants = []; $this->package->header->RuntimeConstants = array_merge( ($selected_build_configuration->DefineConstants ?? []), - ($this->project->build->DefineConstants ?? []), + ($this->project->build->define_constants ?? []), ($this->package->header->RuntimeConstants ?? []) ); - $this->package->header->CompilerExtension = $this->project->project->Compiler; + $this->package->header->CompilerExtension = $this->project->project->compiler; $this->package->header->CompilerVersion = NCC_VERSION_NUMBER; - $this->package->header->Options = $this->project->project->Options; + $this->package->header->Options = $this->project->project->options; - if($this->project->project->UpdateSource !== null) + if($this->project->project->update_source !== null) { - $this->package->header->UpdateSource = $this->project->project->UpdateSource; + $this->package->header->UpdateSource = $this->project->project->update_source; } Console::outDebug('scanning project files'); @@ -158,7 +158,7 @@ $DirectoryScanner->setExcludes($selected_build_configuration->ExcludeFiles); } - $source_path = $this->path . $this->project->build->SourcePath; + $source_path = $this->path . $this->project->build->source_path; // TODO: Re-implement the scanning process outside the compiler, as this is will be redundant // Scan for components first. @@ -238,9 +238,9 @@ $selected_dependencies = []; - if($this->project->build->Dependencies !== null && count($this->project->build->Dependencies) > 0) + if($this->project->build->dependencies !== null && count($this->project->build->dependencies) > 0) { - $selected_dependencies = array_merge($selected_dependencies, $this->project->build->Dependencies); + $selected_dependencies = array_merge($selected_dependencies, $this->project->build->dependencies); } if($selected_build_configuration->Dependencies !== null && count($selected_build_configuration->Dependencies) > 0) @@ -393,7 +393,7 @@ // Get the data and $resource->Data = IO::fread(Functions::correctDirectorySeparator($this->path . $resource->Name)); $resource->Data = Base64::encode($resource->Data); - $resource->Name = str_replace($this->project->build->SourcePath, (string)null, $resource->Name); + $resource->Name = str_replace($this->project->build->source_path, (string)null, $resource->Name); $resource->updateChecksum(); $resources[] = $resource; @@ -462,7 +462,7 @@ unset($parser); - $component->name = str_replace($this->project->build->SourcePath, (string)null, $component->name); + $component->name = str_replace($this->project->build->source_path, (string)null, $component->name); $component->updateChecksum(); $components[] = $component; ++$processed_items; diff --git a/src/ncc/Classes/PhpExtension/PhpRunner.php b/src/ncc/Classes/PhpExtension/PhpRunner.php index 9f792d2..a8217b5 100644 --- a/src/ncc/Classes/PhpExtension/PhpRunner.php +++ b/src/ncc/Classes/PhpExtension/PhpRunner.php @@ -48,7 +48,7 @@ throw new PathNotFoundException($path); } - $policy->Execute->Target = null; + $policy->execute->Target = null; $execution_unit->execution_policy = $policy; $execution_unit->Data = IO::fread($path); diff --git a/src/ncc/Classes/PythonExtension/Python2Runner.php b/src/ncc/Classes/PythonExtension/Python2Runner.php index b006165..4c88139 100644 --- a/src/ncc/Classes/PythonExtension/Python2Runner.php +++ b/src/ncc/Classes/PythonExtension/Python2Runner.php @@ -51,7 +51,7 @@ throw new PathNotFoundException($path); } - $policy->Execute->Target = null; + $policy->execute->Target = null; $execution_unit->execution_policy = $policy; $execution_unit->Data = IO::fread($path); diff --git a/src/ncc/Classes/PythonExtension/Python3Runner.php b/src/ncc/Classes/PythonExtension/Python3Runner.php index 188782f..c8f8fa4 100644 --- a/src/ncc/Classes/PythonExtension/Python3Runner.php +++ b/src/ncc/Classes/PythonExtension/Python3Runner.php @@ -51,7 +51,7 @@ throw new PathNotFoundException($path); } - $policy->Execute->Target = null; + $policy->execute->Target = null; $execution_unit->execution_policy = $policy; $execution_unit->Data = IO::fread($path); diff --git a/src/ncc/Classes/PythonExtension/PythonRunner.php b/src/ncc/Classes/PythonExtension/PythonRunner.php index aa7af0d..b6f381e 100644 --- a/src/ncc/Classes/PythonExtension/PythonRunner.php +++ b/src/ncc/Classes/PythonExtension/PythonRunner.php @@ -51,7 +51,7 @@ throw new PathNotFoundException($path); } - $policy->Execute->Target = null; + $policy->execute->Target = null; $execution_unit->execution_policy = $policy; $execution_unit->Data = IO::fread($path); diff --git a/src/ncc/Managers/ExecutionPointerManager.php b/src/ncc/Managers/ExecutionPointerManager.php index 77977f7..3ce7612 100644 --- a/src/ncc/Managers/ExecutionPointerManager.php +++ b/src/ncc/Managers/ExecutionPointerManager.php @@ -174,15 +174,15 @@ { if(Resolver::resolveScope() !== Scopes::SYSTEM) { - throw new AccessDeniedException('Cannot add new ExecutionUnit \'' . $unit->execution_policy->Name .'\' for ' . $package . ', insufficient permissions'); + throw new AccessDeniedException('Cannot add new ExecutionUnit \'' . $unit->execution_policy->name .'\' for ' . $package . ', insufficient permissions'); } - Console::outVerbose(sprintf('Adding new ExecutionUnit \'%s\' for %s', $unit->execution_policy->Name, $package)); + Console::outVerbose(sprintf('Adding new ExecutionUnit \'%s\' for %s', $unit->execution_policy->name, $package)); $package_id = $this->getPackageId($package, $version); $package_config_path = $this->runner_path . DIRECTORY_SEPARATOR . $package_id . '.inx'; $package_bin_path = $this->runner_path . DIRECTORY_SEPARATOR . $package_id; - $entry_point_path = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->execution_policy->Name) . '.entrypoint'; + $entry_point_path = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->execution_policy->name) . '.entrypoint'; Console::outDebug(sprintf('package_id=%s', $package_id)); Console::outDebug(sprintf('package_config_path=%s', $package_config_path)); @@ -201,8 +201,8 @@ $execution_pointers = ExecutionPointers::fromArray(ZiProto::decode(IO::fread($package_config_path))); } - $bin_file = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->execution_policy->Name); - $bin_file .= match ($unit->execution_policy->Runner) + $bin_file = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->execution_policy->name); + $bin_file .= match ($unit->execution_policy->runner) { Runners::BASH => BashRunner::getFileExtension(), Runners::PHP => PhpRunner::getFileExtension(), @@ -211,7 +211,7 @@ Runners::PYTHON_2 => Python2Runner::getFileExtension(), Runners::PYTHON_3 => Python3Runner::getFileExtension(), Runners::LUA => LuaRunner::getFileExtension(), - default => throw new RunnerExecutionException('The runner \'' . $unit->execution_policy->Runner . '\' is not supported'), + default => throw new RunnerExecutionException('The runner \'' . $unit->execution_policy->runner . '\' is not supported'), }; Console::outDebug(sprintf('bin_file=%s', $bin_file)); @@ -237,7 +237,7 @@ $entry_point = sprintf("#!%s\nncc exec --package=\"%s\" --exec-version=\"%s\" --exec-unit=\"%s\" --exec-args \"$@\"", '/bin/bash', - $package, $version, $unit->execution_policy->Name + $package, $version, $unit->execution_policy->name ); if(file_exists($entry_point_path)) @@ -250,11 +250,11 @@ if($temporary) { - Console::outVerbose(sprintf('Adding temporary ExecutionUnit \'%s\' for %s', $unit->execution_policy->Name, $package)); + Console::outVerbose(sprintf('Adding temporary ExecutionUnit \'%s\' for %s', $unit->execution_policy->name, $package)); $this->temporary_units[] = [ 'package' => $package, 'version' => $version, - 'unit' => $unit->execution_policy->Name + 'unit' => $unit->execution_policy->name ]; } } @@ -350,8 +350,8 @@ $results = []; foreach($execution_pointers->getPointers() as $pointer) { - Console::outDebug(sprintf('unit %s', $pointer->execution_policy->Name)); - $results[] = $pointer->execution_policy->Name; + Console::outDebug(sprintf('unit %s', $pointer->execution_policy->name)); + $results[] = $pointer->execution_policy->name; } return $results; @@ -390,34 +390,34 @@ throw new RunnerExecutionException('The execution unit \'' . $name . '\' was not found for \'' . $package . '=' .$version .'\''); } - Console::outDebug(sprintf('unit=%s', $unit->execution_policy->Name)); - Console::outDebug(sprintf('runner=%s', $unit->execution_policy->Runner)); + Console::outDebug(sprintf('unit=%s', $unit->execution_policy->name)); + Console::outDebug(sprintf('runner=%s', $unit->execution_policy->runner)); Console::outDebug(sprintf('file=%s', $unit->file_pointer)); Console::outDebug(sprintf('pass_thru_args=%s', implode(' ', $args))); // Handle the arguments - if($unit->execution_policy->Execute->Options !== null && count($unit->execution_policy->Execute->Options) > 0) + if($unit->execution_policy->execute->Options !== null && count($unit->execution_policy->execute->Options) > 0) { - $args = array_merge($args, $unit->execution_policy->Execute->Options); + $args = array_merge($args, $unit->execution_policy->execute->Options); - foreach($unit->execution_policy->Execute->Options as $option) + foreach($unit->execution_policy->execute->Options as $option) { $args[] = ConstantCompiler::compileRuntimeConstants($option); } } $process = new Process(array_merge( - [PathFinder::findRunner(strtolower($unit->execution_policy->Runner)), $unit->file_pointer], $args) + [PathFinder::findRunner(strtolower($unit->execution_policy->runner)), $unit->file_pointer], $args) ); - if($unit->execution_policy->Execute->WorkingDirectory !== null) + if($unit->execution_policy->execute->WorkingDirectory !== null) { - $process->setWorkingDirectory(ConstantCompiler::compileRuntimeConstants($unit->execution_policy->Execute->WorkingDirectory)); + $process->setWorkingDirectory(ConstantCompiler::compileRuntimeConstants($unit->execution_policy->execute->WorkingDirectory)); } - if($unit->execution_policy->Execute->Timeout !== null) + if($unit->execution_policy->execute->Timeout !== null) { - $process->setTimeout((float)$unit->execution_policy->Execute->Timeout); + $process->setTimeout((float)$unit->execution_policy->execute->Timeout); } else { @@ -427,12 +427,12 @@ try { - if($unit->execution_policy->Execute->Silent) + if($unit->execution_policy->execute->Silent) { $process->disableOutput(); $process->setTty(false); } - elseif($unit->execution_policy->Execute->Tty) + elseif($unit->execution_policy->execute->Tty) { $process->enableOutput(); $process->setTty(true); @@ -460,16 +460,16 @@ Console::outDebug(sprintf('working_directory=%s', $process->getWorkingDirectory())); Console::outDebug(sprintf('timeout=%s', (int)$process->getTimeout())); - Console::outDebug(sprintf('silent=%s', ($unit->execution_policy->Execute->Silent ? 'true' : 'false'))); - Console::outDebug(sprintf('tty=%s', ($unit->execution_policy->Execute->Tty ? 'true' : 'false'))); + Console::outDebug(sprintf('silent=%s', ($unit->execution_policy->execute->Silent ? 'true' : 'false'))); + Console::outDebug(sprintf('tty=%s', ($unit->execution_policy->execute->Tty ? 'true' : 'false'))); Console::outDebug(sprintf('options=%s', implode(' ', $args))); Console::outDebug(sprintf('cmd=%s', $process->getCommandLine())); try { - if($unit->execution_policy->Message !== null) + if($unit->execution_policy->message !== null) { - Console::out($unit->execution_policy->Message); + Console::out($unit->execution_policy->message); } $process->run(function ($type, $buffer) @@ -481,33 +481,33 @@ } catch(Exception $e) { - if($unit->execution_policy->ExitHandlers !== null && $unit->execution_policy->ExitHandlers->Error !== null) + if($unit->execution_policy->exit_handlers !== null && $unit->execution_policy->exit_handlers->Error !== null) { - $this->handleExit($package, $version, $unit->execution_policy->ExitHandlers->Error); + $this->handleExit($package, $version, $unit->execution_policy->exit_handlers->Error); } - Console::outException(sprintf('An error occurred while executing the unit \'%s\' for \'%s\' (exit code %s)', $unit->execution_policy->Name, $package, $process->getExitCode()), $e); + Console::outException(sprintf('An error occurred while executing the unit \'%s\' for \'%s\' (exit code %s)', $unit->execution_policy->name, $package, $process->getExitCode()), $e); } finally { Console::outDebug(sprintf('exit_code=%s', $process->getExitCode())); } - if($unit->execution_policy->ExitHandlers !== null) + if($unit->execution_policy->exit_handlers !== null) { - if($unit->execution_policy->ExitHandlers->Success !== null && $process->isSuccessful()) + if($unit->execution_policy->exit_handlers->Success !== null && $process->isSuccessful()) { - $this->handleExit($package, $version, $unit->execution_policy->ExitHandlers->Success); + $this->handleExit($package, $version, $unit->execution_policy->exit_handlers->Success); } - elseif($unit->execution_policy->ExitHandlers->Error !== null && $process->isSuccessful()) + elseif($unit->execution_policy->exit_handlers->Error !== null && $process->isSuccessful()) { - $this->handleExit($package, $version, $unit->execution_policy->ExitHandlers->Error); + $this->handleExit($package, $version, $unit->execution_policy->exit_handlers->Error); } else { - $this->handleExit($package, $version, $unit->execution_policy->ExitHandlers->Success, $process); - $this->handleExit($package, $version, $unit->execution_policy->ExitHandlers->Warning, $process); - $this->handleExit($package, $version, $unit->execution_policy->ExitHandlers->Error, $process); + $this->handleExit($package, $version, $unit->execution_policy->exit_handlers->Success, $process); + $this->handleExit($package, $version, $unit->execution_policy->exit_handlers->Warning, $process); + $this->handleExit($package, $version, $unit->execution_policy->exit_handlers->Error, $process); } } @@ -538,21 +538,21 @@ // Get the required units $required_units = []; - if($unit->execution_policy->ExitHandlers !== null) + if($unit->execution_policy->exit_handlers !== null) { - $required_unit = $unit->execution_policy?->ExitHandlers?->Success?->Run; + $required_unit = $unit->execution_policy?->exit_handlers?->Success?->Run; if($required_unit !== null) { $required_units[] = $required_unit; } - $required_unit = $unit->execution_policy?->ExitHandlers?->Warning?->Run; + $required_unit = $unit->execution_policy?->exit_handlers?->Warning?->Run; if($required_unit !== null) { $required_units[] = $required_unit; } - $required_unit = $unit->execution_policy?->ExitHandlers?->Error?->Run; + $required_unit = $unit->execution_policy?->exit_handlers?->Error?->Run; if($required_unit !== null) { $required_units = $required_unit; diff --git a/src/ncc/Managers/PackageManager.php b/src/ncc/Managers/PackageManager.php index 457290c..c40cdc3 100644 --- a/src/ncc/Managers/PackageManager.php +++ b/src/ncc/Managers/PackageManager.php @@ -143,7 +143,7 @@ return $package->assembly->Package; } - $extension = $package->header->CompilerExtension->Extension; + $extension = $package->header->CompilerExtension->extension; $installation_paths = new InstallationPaths($this->packages_path . DIRECTORY_SEPARATOR . $package->assembly->Package . '=' . $package->assembly->Version); $installer = match ($extension) @@ -180,15 +180,15 @@ foreach($package->dependencies as $dependency) { // Uninstall the dependency if the option Reinstall is passed on - if(in_array(InstallPackageOptions::REINSTALL, $options, true) && $this->getPackageLockManager()?->getPackageLock()?->packageExists($dependency->Name, $dependency->Version)) + if(in_array(InstallPackageOptions::REINSTALL, $options, true) && $this->getPackageLockManager()?->getPackageLock()?->packageExists($dependency->name, $dependency->version)) { - if($dependency->Version === null) + if($dependency->version === null) { - $this->uninstallPackage($dependency->Name); + $this->uninstallPackage($dependency->name); } else { - $this->uninstallPackageVersion($dependency->Name, $dependency->Version); + $this->uninstallPackageVersion($dependency->name, $dependency->version); } } @@ -366,7 +366,7 @@ /** @var Package\ExecutionUnit $executionUnit */ foreach($package->execution_units as $executionUnit) { - Console::outDebug(sprintf('processing execution unit %s', $executionUnit->execution_policy->Name)); + Console::outDebug(sprintf('processing execution unit %s', $executionUnit->execution_policy->name)); $execution_pointer_manager->addUnit($package->assembly->Package, $package->assembly->Version, $executionUnit); ++$current_steps; Console::inlineProgressBar($current_steps, $steps); @@ -434,17 +434,17 @@ Console::outDebug('no post-installation units to execute'); } - if($package->header->UpdateSource !== null && $package->header->UpdateSource->Repository !== null) + if($package->header->UpdateSource !== null && $package->header->UpdateSource->repository !== null) { $sources_manager = new RemoteSourcesManager(); - if($sources_manager->getRemoteSource($package->header->UpdateSource->Repository->Name) === null) + if($sources_manager->getRemoteSource($package->header->UpdateSource->repository->Name) === null) { - Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->Repository->Name); + Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->repository->Name); $defined_remote_source = new DefinedRemoteSource(); - $defined_remote_source->name = $package->header->UpdateSource->Repository->Name; - $defined_remote_source->host = $package->header->UpdateSource->Repository->Host; - $defined_remote_source->type = $package->header->UpdateSource->Repository->Type; - $defined_remote_source->ssl = $package->header->UpdateSource->Repository->SSL; + $defined_remote_source->name = $package->header->UpdateSource->repository->Name; + $defined_remote_source->host = $package->header->UpdateSource->repository->Host; + $defined_remote_source->type = $package->header->UpdateSource->repository->Type; + $defined_remote_source->ssl = $package->header->UpdateSource->repository->SSL; $sources_manager->addRemoteSource($defined_remote_source); } @@ -673,67 +673,67 @@ */ private function processDependency(Dependency $dependency, Package $package, string $package_path, ?Entry $entry=null, array $options=[]): void { - if(RuntimeCache::get(sprintf('dependency_installed.%s=%s', $dependency->Name, $dependency->Version ?? 'null'))) + if(RuntimeCache::get(sprintf('dependency_installed.%s=%s', $dependency->name, $dependency->version ?? 'null'))) { - Console::outDebug(sprintf('dependency %s=%s already processed, skipping', $dependency->Name, $dependency->Version ?? 'null')); + Console::outDebug(sprintf('dependency %s=%s already processed, skipping', $dependency->name, $dependency->version ?? 'null')); return; } - Console::outVerbose('processing dependency ' . $dependency->Name . ' (' . $dependency->Version . ')'); - $dependent_package = $this->getPackage($dependency->Name); + Console::outVerbose('processing dependency ' . $dependency->name . ' (' . $dependency->version . ')'); + $dependent_package = $this->getPackage($dependency->name); $dependency_met = false; - if ($dependent_package !== null && $dependency->Version !== null && Validate::version($dependency->Version)) + if ($dependent_package !== null && $dependency->version !== null && Validate::version($dependency->version)) { Console::outDebug('dependency has version constraint, checking if package is installed'); - $dependent_version = $this->getPackageVersion($dependency->Name, $dependency->Version); + $dependent_version = $this->getPackageVersion($dependency->name, $dependency->version); if ($dependent_version !== null) { $dependency_met = true; } } - elseif ($dependent_package !== null && $dependency->Version === null) + elseif ($dependent_package !== null && $dependency->version === null) { - Console::outDebug(sprintf('dependency %s has no version specified, assuming dependency is met', $dependency->Name)); + Console::outDebug(sprintf('dependency %s has no version specified, assuming dependency is met', $dependency->name)); $dependency_met = true; } Console::outDebug('dependency met: ' . ($dependency_met ? 'true' : 'false')); - if ($dependency->SourceType !== null && !$dependency_met) + if ($dependency->source_type !== null && !$dependency_met) { - Console::outVerbose(sprintf('Installing dependency %s=%s for %s=%s', $dependency->Name, $dependency->Version, $package->assembly->Package, $package->assembly->Version)); - switch ($dependency->SourceType) + Console::outVerbose(sprintf('Installing dependency %s=%s for %s=%s', $dependency->name, $dependency->version, $package->assembly->Package, $package->assembly->Version)); + switch ($dependency->source_type) { case DependencySourceType::LOCAL: - Console::outDebug('installing from local source ' . $dependency->Source); + Console::outDebug('installing from local source ' . $dependency->source); $basedir = dirname($package_path); - if (!file_exists($basedir . DIRECTORY_SEPARATOR . $dependency->Source)) + if (!file_exists($basedir . DIRECTORY_SEPARATOR . $dependency->source)) { - throw new PathNotFoundException($basedir . DIRECTORY_SEPARATOR . $dependency->Source); + throw new PathNotFoundException($basedir . DIRECTORY_SEPARATOR . $dependency->source); } - $this->install($basedir . DIRECTORY_SEPARATOR . $dependency->Source, null, $options); - RuntimeCache::set(sprintf('dependency_installed.%s=%s', $dependency->Name, $dependency->Version), true); + $this->install($basedir . DIRECTORY_SEPARATOR . $dependency->source, null, $options); + RuntimeCache::set(sprintf('dependency_installed.%s=%s', $dependency->name, $dependency->version), true); break; case DependencySourceType::STATIC: - throw new PackageNotFoundException('Static linking not possible, package ' . $dependency->Name . ' is not installed'); + throw new PackageNotFoundException('Static linking not possible, package ' . $dependency->name . ' is not installed'); case DependencySourceType::REMOTE: - Console::outDebug('installing from remote source ' . $dependency->Source); - $this->installFromSource($dependency->Source, $entry, $options); - RuntimeCache::set(sprintf('dependency_installed.%s=%s', $dependency->Name, $dependency->Version), true); + Console::outDebug('installing from remote source ' . $dependency->source); + $this->installFromSource($dependency->source, $entry, $options); + RuntimeCache::set(sprintf('dependency_installed.%s=%s', $dependency->name, $dependency->version), true); break; default: - throw new NotImplementedException('Dependency source type ' . $dependency->SourceType . ' is not implemented'); + throw new NotImplementedException('Dependency source type ' . $dependency->source_type . ' is not implemented'); } } elseif(!$dependency_met) { - throw new MissingDependencyException(sprintf('The dependency %s=%s for %s=%s is not met', $dependency->Name, $dependency->Version, $package->assembly->Package, $package->assembly->Version)); + throw new MissingDependencyException(sprintf('The dependency %s=%s for %s=%s is not met', $dependency->name, $dependency->version, $package->assembly->Package, $package->assembly->Version)); } } @@ -962,9 +962,9 @@ $execution_pointer_manager = new ExecutionPointerManager(); foreach($version_entry->ExecutionUnits as $executionUnit) { - if(!$execution_pointer_manager->removeUnit($package, $version, $executionUnit->execution_policy->Name)) + if(!$execution_pointer_manager->removeUnit($package, $version, $executionUnit->execution_policy->name)) { - Console::outDebug(sprintf('warning: removing execution unit %s failed', $executionUnit->execution_policy->Name)); + Console::outDebug(sprintf('warning: removing execution unit %s failed', $executionUnit->execution_policy->name)); } } } diff --git a/src/ncc/Managers/ProjectManager.php b/src/ncc/Managers/ProjectManager.php index 6803bd8..73d6e90 100644 --- a/src/ncc/Managers/ProjectManager.php +++ b/src/ncc/Managers/ProjectManager.php @@ -136,7 +136,7 @@ $this->project_configuration = new ProjectConfiguration(); // Set the compiler information - $this->project_configuration->project->Compiler = $compiler; + $this->project_configuration->project->compiler = $compiler; // Set the assembly information $this->project_configuration->assembly->Name = $name; @@ -145,32 +145,32 @@ $this->project_configuration->assembly->UUID = Uuid::v1()->toRfc4122(); // Set the build information - $this->project_configuration->build->SourcePath = $src; + $this->project_configuration->build->source_path = $src; - if($this->project_configuration->build->SourcePath === null) + if($this->project_configuration->build->source_path === null) { - $this->project_configuration->build->SourcePath = $this->project_path; + $this->project_configuration->build->source_path = $this->project_path; } - $this->project_configuration->build->DefaultConfiguration = 'debug'; + $this->project_configuration->build->default_configuration = 'debug'; // Assembly constants if the program wishes to check for this - $this->project_configuration->build->DefineConstants['ASSEMBLY_NAME'] = '%ASSEMBLY.NAME%'; - $this->project_configuration->build->DefineConstants['ASSEMBLY_PACKAGE'] = '%ASSEMBLY.PACKAGE%'; - $this->project_configuration->build->DefineConstants['ASSEMBLY_VERSION'] = '%ASSEMBLY.VERSION%'; - $this->project_configuration->build->DefineConstants['ASSEMBLY_UID'] = '%ASSEMBLY.UID%'; + $this->project_configuration->build->define_constants['ASSEMBLY_NAME'] = '%ASSEMBLY.NAME%'; + $this->project_configuration->build->define_constants['ASSEMBLY_PACKAGE'] = '%ASSEMBLY.PACKAGE%'; + $this->project_configuration->build->define_constants['ASSEMBLY_VERSION'] = '%ASSEMBLY.VERSION%'; + $this->project_configuration->build->define_constants['ASSEMBLY_UID'] = '%ASSEMBLY.UID%'; // Generate configurations $DebugConfiguration = new ProjectConfiguration\Build\BuildConfiguration(); $DebugConfiguration->Name = 'debug'; $DebugConfiguration->OutputPath = 'build/debug'; $DebugConfiguration->DefineConstants["DEBUG"] = '1'; // Debugging constant if the program wishes to check for this - $this->project_configuration->build->Configurations[] = $DebugConfiguration; + $this->project_configuration->build->build_configurations[] = $DebugConfiguration; $ReleaseConfiguration = new ProjectConfiguration\Build\BuildConfiguration(); $ReleaseConfiguration->Name = 'release'; $ReleaseConfiguration->OutputPath = 'build/release'; $ReleaseConfiguration->DefineConstants["DEBUG"] = '0'; // Debugging constant if the program wishes to check for this - $this->project_configuration->build->Configurations[] = $ReleaseConfiguration; + $this->project_configuration->build->build_configurations[] = $ReleaseConfiguration; // Finally, create project.json $this->project_configuration->toFile($this->project_path . DIRECTORY_SEPARATOR . 'project.json'); @@ -195,8 +195,8 @@ { if ( $option === InitializeProjectOptions::CREATE_SOURCE_DIRECTORY && - !file_exists($this->project_configuration->build->SourcePath) && - !mkdir($concurrentDirectory = $this->project_configuration->build->SourcePath) && + !file_exists($this->project_configuration->build->source_path) && + !mkdir($concurrentDirectory = $this->project_configuration->build->source_path) && !is_dir($concurrentDirectory) ) { diff --git a/src/ncc/Objects/ExecutionPointers.php b/src/ncc/Objects/ExecutionPointers.php index 3a83307..fb79da6 100644 --- a/src/ncc/Objects/ExecutionPointers.php +++ b/src/ncc/Objects/ExecutionPointers.php @@ -82,9 +82,9 @@ if($overwrite) { - $this->deleteUnit($unit->execution_policy->Name); + $this->deleteUnit($unit->execution_policy->name); } - elseif($this->getUnit($unit->execution_policy->Name) !== null) + elseif($this->getUnit($unit->execution_policy->name) !== null) { return false; } @@ -111,7 +111,7 @@ $new_pointers = []; foreach($this->pointers as $pointer) { - if($pointer->execution_policy->Name !== $name) + if($pointer->execution_policy->name !== $name) { $new_pointers[] = $pointer; } @@ -132,7 +132,7 @@ /** @var ExecutionPointer $pointer */ foreach($this->pointers as $pointer) { - if($pointer->execution_policy->Name === $name) + if($pointer->execution_policy->name === $name) { return $pointer; } diff --git a/src/ncc/Objects/Package.php b/src/ncc/Objects/Package.php index 9c5919a..e457d3a 100644 --- a/src/ncc/Objects/Package.php +++ b/src/ncc/Objects/Package.php @@ -134,9 +134,9 @@ { foreach($this->dependencies as $dep) { - if($dep->Name === $dependency->Name) + if($dep->name === $dependency->name) { - $this->removeDependency($dep->Name); + $this->removeDependency($dep->name); break; } } @@ -154,7 +154,7 @@ { foreach($this->dependencies as $key => $dep) { - if($dep->Name === $name) + if($dep->name === $name) { unset($this->dependencies[$key]); return; @@ -216,7 +216,7 @@ { foreach($this->execution_units as $unit) { - if($unit->execution_policy->Name === $name) + if($unit->execution_policy->name === $name) { return $unit; } diff --git a/src/ncc/Objects/Package/ExecutionUnit.php b/src/ncc/Objects/Package/ExecutionUnit.php index b11a3ae..bf3d038 100644 --- a/src/ncc/Objects/Package/ExecutionUnit.php +++ b/src/ncc/Objects/Package/ExecutionUnit.php @@ -87,7 +87,7 @@ public function getId(): string { if($this->id == null) - $this->id = hash('sha1', $this->execution_policy->Name); + $this->id = hash('sha1', $this->execution_policy->name); return $this->id; } diff --git a/src/ncc/Objects/PackageLock/DependencyEntry.php b/src/ncc/Objects/PackageLock/DependencyEntry.php index bbd1db2..7cc0614 100644 --- a/src/ncc/Objects/PackageLock/DependencyEntry.php +++ b/src/ncc/Objects/PackageLock/DependencyEntry.php @@ -47,8 +47,8 @@ { if($dependency !== null) { - $this->PackageName = $dependency->Name; - $this->Version = $dependency->Version; + $this->PackageName = $dependency->name; + $this->Version = $dependency->version; } } diff --git a/src/ncc/Objects/ProjectConfiguration.php b/src/ncc/Objects/ProjectConfiguration.php index 454e300..df5848b 100644 --- a/src/ncc/Objects/ProjectConfiguration.php +++ b/src/ncc/Objects/ProjectConfiguration.php @@ -149,13 +149,13 @@ return false; } - if($this->build->Main !== null) + if($this->build->main !== null) { if($this->execution_policies === null || count($this->execution_policies) === 0) { if($throw_exception) { - throw new UndefinedExecutionPolicyException(sprintf('Build configuration build.main uses an execution policy "%s" but no policies are defined', $this->build->Main)); + throw new UndefinedExecutionPolicyException(sprintf('Build configuration build.main uses an execution policy "%s" but no policies are defined', $this->build->main)); } return false; @@ -165,7 +165,7 @@ $found = false; foreach($this->execution_policies as $policy) { - if($policy->Name === $this->build->Main) + if($policy->name === $this->build->main) { $found = true; break; @@ -176,12 +176,12 @@ { if($throw_exception) { - throw new UndefinedExecutionPolicyException(sprintf('Build configuration build.main points to a undefined execution policy "%s"', $this->build->Main)); + throw new UndefinedExecutionPolicyException(sprintf('Build configuration build.main points to a undefined execution policy "%s"', $this->build->main)); } return false; } - if($this->build->Main === BuildConfigurationValues::ALL) + if($this->build->main === BuildConfigurationValues::ALL) { if($throw_exception) { @@ -203,7 +203,7 @@ { foreach($this->execution_policies as $executionPolicy) { - if($executionPolicy->Name === $name) + if($executionPolicy->name === $name) { return $executionPolicy; } @@ -233,7 +233,7 @@ /** @var ExecutionPolicy $execution_policy */ foreach($this->execution_policies as $execution_policy) { - $defined_polices[] = $execution_policy->Name; + $defined_polices[] = $execution_policy->name; //$execution_policy->validate(); } @@ -264,9 +264,9 @@ } } - if($this->build->PreBuild !== null && count($this->build->PostBuild) > 0) + if($this->build->pre_build !== null && count($this->build->post_build) > 0) { - foreach($this->build->PostBuild as $unit) + foreach($this->build->post_build as $unit) { if(!in_array($unit, $defined_polices, true)) { @@ -280,9 +280,9 @@ } } - if($this->build->PostBuild !== null && count($this->build->PostBuild) > 0) + if($this->build->post_build !== null && count($this->build->post_build) > 0) { - foreach($this->build->PostBuild as $unit) + foreach($this->build->post_build as $unit) { if(!in_array($unit, $defined_polices, true)) { @@ -301,7 +301,7 @@ { case BuildConfigurationValues::ALL: /** @var BuildConfiguration $configuration */ - foreach($this->build->Configurations as $configuration) + foreach($this->build->build_configurations as $configuration) { foreach($this->processBuildPolicies($configuration, $defined_polices) as $policy) { @@ -328,47 +328,47 @@ foreach($required_policies as $policy) { $execution_policy = $this->getExecutionPolicy($policy); - if($execution_policy?->ExitHandlers !== null) + if($execution_policy?->exit_handlers !== null) { if( - $execution_policy?->ExitHandlers->Success !== null && - $execution_policy?->ExitHandlers->Success->Run !== null + $execution_policy?->exit_handlers->Success !== null && + $execution_policy?->exit_handlers->Success->Run !== null ) { - if(!in_array($execution_policy?->ExitHandlers->Success->Run, $defined_polices, true)) + if(!in_array($execution_policy?->exit_handlers->Success->Run, $defined_polices, true)) { - throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy?->Name . '\' Success exit handler points to a undefined execution policy \'' . $execution_policy?->ExitHandlers->Success->Run . '\''); + throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy?->name . '\' Success exit handler points to a undefined execution policy \'' . $execution_policy?->exit_handlers->Success->Run . '\''); } - if(!in_array($execution_policy?->ExitHandlers->Success->Run, $required_policies, true)) + if(!in_array($execution_policy?->exit_handlers->Success->Run, $required_policies, true)) { - $required_policies[] = $execution_policy?->ExitHandlers->Success->Run; + $required_policies[] = $execution_policy?->exit_handlers->Success->Run; } } - if($execution_policy?->ExitHandlers->Warning !== null && $execution_policy?->ExitHandlers->Warning->Run !== null) + if($execution_policy?->exit_handlers->Warning !== null && $execution_policy?->exit_handlers->Warning->Run !== null) { - if(!in_array($execution_policy?->ExitHandlers->Warning->Run, $defined_polices, true)) + if(!in_array($execution_policy?->exit_handlers->Warning->Run, $defined_polices, true)) { - throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy?->Name . '\' Warning exit handler points to a undefined execution policy \'' . $execution_policy?->ExitHandlers->Warning->Run . '\''); + throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy?->name . '\' Warning exit handler points to a undefined execution policy \'' . $execution_policy?->exit_handlers->Warning->Run . '\''); } - if(!in_array($execution_policy?->ExitHandlers->Warning->Run, $required_policies, true)) + if(!in_array($execution_policy?->exit_handlers->Warning->Run, $required_policies, true)) { - $required_policies[] = $execution_policy?->ExitHandlers->Warning->Run; + $required_policies[] = $execution_policy?->exit_handlers->Warning->Run; } } - if($execution_policy?->ExitHandlers->Error !== null && $execution_policy?->ExitHandlers->Error->Run !== null) + if($execution_policy?->exit_handlers->Error !== null && $execution_policy?->exit_handlers->Error->Run !== null) { - if(!in_array($execution_policy?->ExitHandlers->Error->Run, $defined_polices, true)) + if(!in_array($execution_policy?->exit_handlers->Error->Run, $defined_polices, true)) { - throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy?->Name . '\' Error exit handler points to a undefined execution policy \'' . $execution_policy?->ExitHandlers->Error->Run . '\''); + throw new UndefinedExecutionPolicyException('The execution policy \'' . $execution_policy?->name . '\' Error exit handler points to a undefined execution policy \'' . $execution_policy?->exit_handlers->Error->Run . '\''); } - if(!in_array($execution_policy?->ExitHandlers->Error->Run, $required_policies, true)) + if(!in_array($execution_policy?->exit_handlers->Error->Run, $required_policies, true)) { - $required_policies[] = $execution_policy?->ExitHandlers->Error->Run; + $required_policies[] = $execution_policy?->exit_handlers->Error->Run; } } } @@ -463,7 +463,7 @@ $execution_policies = []; foreach($this->execution_policies as $executionPolicy) { - $execution_policies[$executionPolicy->Name] = $executionPolicy->toArray($bytecode); + $execution_policies[$executionPolicy->name] = $executionPolicy->toArray($bytecode); } } @@ -475,7 +475,7 @@ if($this->assembly !== null) { - $results['assembly'] = $this->assembly->toArray($bytecode); + $results[($bytecode ? Functions::cbc('assembly') : 'assembly')] = $this->assembly->toArray($bytecode); } if($this->build !== null) @@ -503,30 +503,16 @@ { $object = new self(); - if(isset($data['project'])) - { - $object->project = Project::fromArray($data['project']); - } + $object->project = Project::fromArray(Functions::array_bc($data, 'project')); + $object->assembly = Assembly::fromArray(Functions::array_bc($data, 'assembly')); + $object->build = Build::fromArray(Functions::array_bc($data, 'build')); + $object->installer = Installer::fromArray(Functions::array_bc($data, 'installer')); - if(isset($data['assembly'])) - { - $object->assembly = Assembly::fromArray($data['assembly']); - } - - if(isset($data['build'])) - { - $object->build = Build::fromArray($data['build']); - } - - if(isset($data['installer'])) - { - $object->installer = Installer::fromArray($data['installer']); - } - - if(isset($data['execution_policies'])) + $execution_policies = Functions::array_bc($data, 'execution_policies'); + if(!is_null($execution_policies)) { $object->execution_policies = []; - foreach($data['execution_policies'] as $execution_policy) + foreach(Functions::array_bc($data, 'execution_policies') as $execution_policy) { $object->execution_policies[] = ExecutionPolicy::fromArray($execution_policy); } diff --git a/src/ncc/Objects/ProjectConfiguration/Build.php b/src/ncc/Objects/ProjectConfiguration/Build.php index ab1e750..fd56669 100644 --- a/src/ncc/Objects/ProjectConfiguration/Build.php +++ b/src/ncc/Objects/ProjectConfiguration/Build.php @@ -1,24 +1,24 @@ ExcludeFiles = []; - $this->Options = []; - $this->DefineConstants = []; - $this->Dependencies = []; - $this->Configurations = []; + $this->exclude_files = []; + $this->options = []; + $this->define_constants = []; + $this->dependencies = []; + $this->build_configurations = []; } /** - * Adds a new dependency to the build, if it doesn't already exist + * Adds a new dependency to the build if it doesn't already exist * * @param Dependency $dependency * @return void */ public function addDependency(Dependency $dependency): void { - foreach($this->Dependencies as $dep) + foreach($this->dependencies as $dep) { - if($dep->Name == $dependency->Name) + if($dep->name === $dependency->name) { - $this->removeDependency($dep->Name); + $this->removeDependency($dep->name); break; } } - $this->Dependencies[] = $dependency; + $this->dependencies[] = $dependency; } /** @@ -156,11 +157,11 @@ */ private function removeDependency(string $name): void { - foreach($this->Dependencies as $key => $dep) + foreach($this->dependencies as $key => $dep) { - if($dep->Name == $name) + if($dep->name === $name) { - unset($this->Dependencies[$key]); + unset($this->dependencies[$key]); return; } } @@ -179,7 +180,7 @@ public function validate(bool $throw_exception=True): bool { // Check the defined constants - foreach($this->DefineConstants as $name => $value) + foreach($this->define_constants as $name => $value) { if(!Validate::constantName($name)) { @@ -189,23 +190,27 @@ // Check for duplicate configuration names $build_configurations = []; - foreach($this->Configurations as $configuration) + foreach($this->build_configurations as $configuration) { - if(in_array($configuration->Name, $build_configurations)) + if(in_array($configuration->Name, $build_configurations, true)) { if($throw_exception) + { throw new InvalidProjectBuildConfiguration('The build configuration \'' . $configuration->Name . '\' is already defined, build configuration names must be unique'); + } return false; } } - foreach($this->Configurations as $configuration) + foreach($this->build_configurations as $configuration) { try { if (!$configuration->validate($throw_exception)) + { return false; + } } catch (InvalidBuildConfigurationException $e) { @@ -213,23 +218,27 @@ } } - if($this->DefaultConfiguration == null) + if($this->default_configuration === null) { if($throw_exception) + { throw new InvalidProjectBuildConfiguration('The default build configuration is not set'); + } return false; } - if(!Validate::nameFriendly($this->DefaultConfiguration)) + if(!Validate::nameFriendly($this->default_configuration)) { if($throw_exception) - throw new InvalidProjectBuildConfiguration('The default build configuration name \'' . $this->DefaultConfiguration . '\' is not valid'); + { + throw new InvalidProjectBuildConfiguration('The default build configuration name \'' . $this->default_configuration . '\' is not valid'); + } return false; } - $this->getBuildConfiguration($this->DefaultConfiguration); + $this->getBuildConfiguration($this->default_configuration); return true; } @@ -244,7 +253,7 @@ { $build_configurations = []; - foreach($this->Configurations as $configuration) + foreach($this->build_configurations as $configuration) { $build_configurations[] = $configuration->Name; } @@ -262,12 +271,14 @@ */ public function getBuildConfiguration(string $name): BuildConfiguration { - if($name == BuildConfigurationValues::DEFAULT) - $name = $this->DefaultConfiguration; - - foreach($this->Configurations as $configuration) + if($name === BuildConfigurationValues::DEFAULT) { - if($configuration->Name == $name) + $name = $this->default_configuration; + } + + foreach($this->build_configurations as $configuration) + { + if($configuration->Name === $name) { return $configuration; } @@ -284,46 +295,71 @@ */ public function toArray(bool $bytecode=false): array { - $ReturnResults = []; + $results = []; - if($this->SourcePath !== null) - $ReturnResults[($bytecode ? Functions::cbc('source_path') : 'source_path')] = $this->SourcePath; - if($this->DefaultConfiguration !== null) - $ReturnResults[($bytecode ? Functions::cbc('default_configuration') : 'default_configuration')] = $this->DefaultConfiguration; - if($this->ExcludeFiles !== null && count($this->ExcludeFiles) > 0) - $ReturnResults[($bytecode ? Functions::cbc('exclude_files') : 'exclude_files')] = $this->ExcludeFiles; - if($this->Options !== null && count($this->Options) > 0) - $ReturnResults[($bytecode ? Functions::cbc('options') : 'options')] = $this->Options; - if($this->Scope !== null) - $ReturnResults[($bytecode ? Functions::cbc('scope') : 'scope')] = $this->Scope; - if($this->Main !== null) - $ReturnResults[($bytecode ? Functions::cbc('main') : 'main')] = $this->Main; - if($this->DefineConstants !== null && count($this->DefineConstants) > 0) - $ReturnResults[($bytecode ? Functions::cbc('define_constants') : 'define_constants')] = $this->DefineConstants; - if($this->PreBuild !== null && count($this->PreBuild) > 0) - $ReturnResults[($bytecode ? Functions::cbc('pre_build') : 'pre_build')] = $this->PreBuild; - if($this->PostBuild !== null && count($this->PostBuild) > 0) - $ReturnResults[($bytecode ? Functions::cbc('post_build') : 'post_build')] = $this->PostBuild; - if($this->Dependencies !== null && count($this->Dependencies) > 0) + if($this->source_path !== null) + { + $results[($bytecode ? Functions::cbc('source_path') : 'source_path')] = $this->source_path; + } + if($this->default_configuration !== null) + { + $results[($bytecode ? Functions::cbc('default_configuration') : 'default_configuration')] = $this->default_configuration; + } + if($this->exclude_files !== null && count($this->exclude_files) > 0) + { + $results[($bytecode ? Functions::cbc('exclude_files') : 'exclude_files')] = $this->exclude_files; + } + if($this->options !== null && count($this->options) > 0) + { + $results[($bytecode ? Functions::cbc('options') : 'options')] = $this->options; + } + + if($this->scope !== null) + { + $results[($bytecode ? Functions::cbc('scope') : 'scope')] = $this->scope; + } + + if($this->main !== null) + { + $results[($bytecode ? Functions::cbc('main') : 'main')] = $this->main; + } + + if($this->define_constants !== null && count($this->define_constants) > 0) + { + $results[($bytecode ? Functions::cbc('define_constants') : 'define_constants')] = $this->define_constants; + } + + if($this->pre_build !== null && count($this->pre_build) > 0) + { + $results[($bytecode ? Functions::cbc('pre_build') : 'pre_build')] = $this->pre_build; + } + + if($this->post_build !== null && count($this->post_build) > 0) + { + $results[($bytecode ? Functions::cbc('post_build') : 'post_build')] = $this->post_build; + } + + if($this->dependencies !== null && count($this->dependencies) > 0) { $dependencies = []; - foreach($this->Dependencies as $dependency) + foreach($this->dependencies as $dependency) { $dependencies[] = $dependency->toArray($bytecode); } - $ReturnResults[($bytecode ? Functions::cbc('dependencies') : 'dependencies')] = $dependencies; + $results[($bytecode ? Functions::cbc('dependencies') : 'dependencies')] = $dependencies; } - if($this->Configurations !== null && count($this->Configurations) > 0) + + if($this->build_configurations !== null && count($this->build_configurations) > 0) { $configurations = []; - foreach($this->Configurations as $configuration) + foreach($this->build_configurations as $configuration) { $configurations[] = $configuration->toArray($bytecode); } - $ReturnResults[($bytecode ? Functions::cbc('configurations') : 'configurations')] = $configurations; + $results[($bytecode ? Functions::cbc('configurations') : 'configurations')] = $configurations; } - return $ReturnResults; + return $results; } /** @@ -334,23 +370,23 @@ */ public static function fromArray(array $data): Build { - $BuildObject = new Build(); + $object = new self(); - $BuildObject->SourcePath = Functions::array_bc($data, 'source_path'); - $BuildObject->DefaultConfiguration = Functions::array_bc($data, 'default_configuration'); - $BuildObject->ExcludeFiles = (Functions::array_bc($data, 'exclude_files') ?? []); - $BuildObject->Options = (Functions::array_bc($data, 'options') ?? []); - $BuildObject->Scope = Functions::array_bc($data, 'scope'); - $BuildObject->Main = Functions::array_bc($data, 'main'); - $BuildObject->DefineConstants = (Functions::array_bc($data, 'define_constants') ?? []); - $BuildObject->PreBuild = (Functions::array_bc($data, 'pre_build') ?? []); - $BuildObject->PostBuild = (Functions::array_bc($data, 'post_build') ?? []); + $object->source_path = Functions::array_bc($data, 'source_path'); + $object->default_configuration = Functions::array_bc($data, 'default_configuration'); + $object->exclude_files = (Functions::array_bc($data, 'exclude_files') ?? []); + $object->options = (Functions::array_bc($data, 'options') ?? []); + $object->scope = Functions::array_bc($data, 'scope'); + $object->main = Functions::array_bc($data, 'main'); + $object->define_constants = (Functions::array_bc($data, 'define_constants') ?? []); + $object->pre_build = (Functions::array_bc($data, 'pre_build') ?? []); + $object->post_build = (Functions::array_bc($data, 'post_build') ?? []); if(Functions::array_bc($data, 'dependencies') !== null) { foreach(Functions::array_bc($data, 'dependencies') as $dependency) { - $BuildObject->Dependencies[] = Dependency::fromArray($dependency); + $object->dependencies[] = Dependency::fromArray($dependency); } } @@ -358,10 +394,10 @@ { foreach(Functions::array_bc($data, 'configurations') as $configuration) { - $BuildObject->Configurations[] = BuildConfiguration::fromArray($configuration); + $object->build_configurations[] = BuildConfiguration::fromArray($configuration); } } - return $BuildObject; + return $object; } } \ No newline at end of file diff --git a/src/ncc/Objects/ProjectConfiguration/Compiler.php b/src/ncc/Objects/ProjectConfiguration/Compiler.php index db68b55..9420929 100644 --- a/src/ncc/Objects/ProjectConfiguration/Compiler.php +++ b/src/ncc/Objects/ProjectConfiguration/Compiler.php @@ -1,24 +1,24 @@ Extension == null) + if($this->extension === null) { if($throw_exception) + { throw new InvalidPropertyValueException('The property \'extension\' must not be null.'); + } + return False; } - if($this->MinimumVersion == null) + if($this->minimum_version === null) { if($throw_exception) + { throw new InvalidPropertyValueException('The property \'minimum_version\' must not be null.'); + } return False; } - if($this->MaximumVersion == null) + if($this->maximum_version === null) { if($throw_exception) + { throw new InvalidPropertyValueException('The property \'maximum_version\' must not be null.'); + } + return False; } try { - if(VersionComparator::compareVersion($this->MinimumVersion, $this->MaximumVersion) == 1) + if(VersionComparator::compareVersion($this->minimum_version, $this->maximum_version) === 1) { if($throw_exception) + { throw new InvalidVersionConfigurationException('The minimum version cannot be greater version number than the maximum version'); + } + return False; } } @@ -110,72 +122,80 @@ throw new RuntimeException('Version comparison failed: ' . $e->getMessage()); } - if(!in_array($this->Extension, CompilerExtensions::ALL)) + if(!in_array($this->extension, CompilerExtensions::ALL)) { if($throw_exception) - throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $this->Extension . '\' is not supported'); + { + throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $this->extension . '\' is not supported'); + } + return False; } - switch($this->Extension) + switch($this->extension) { case CompilerExtensions::PHP: - if(!in_array($this->MaximumVersion, CompilerExtensionSupportedVersions::PHP)) + if(!in_array($this->maximum_version, CompilerExtensionSupportedVersions::PHP)) { if($throw_exception) - throw new UnsupportedExtensionVersionException('The MaximumVersion does not support version ' . $this->MaximumVersion . ' for the extension ' . $this->Extension); + { + throw new UnsupportedExtensionVersionException('The MaximumVersion does not support version ' . $this->maximum_version . ' for the extension ' . $this->extension); + } return False; } - if(!in_array($this->MinimumVersion, CompilerExtensionSupportedVersions::PHP)) + if(!in_array($this->minimum_version, CompilerExtensionSupportedVersions::PHP)) { if($throw_exception) - throw new UnsupportedExtensionVersionException('The MinimumVersion does not support version ' . $this->MinimumVersion . ' for the extension ' . $this->Extension); + { + throw new UnsupportedExtensionVersionException('The MinimumVersion does not support version ' . $this->minimum_version . ' for the extension ' . $this->extension); + } return False; } break; default: - throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $this->Extension . '\' is not supported'); + throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $this->extension . '\' is not supported'); } return True; } /** - * Returns an array representation of the object - * - * @return array + * @inheritDoc */ - public function toArray(): array + public function toArray(bool $bytecode = false): array { - $return_results = []; - if($this->Extension !== null && strlen($this->Extension) > 0) - $return_results['extension'] = $this->Extension; + $results = []; + if($this->extension !== null && $this->extension !== '') + { + $results[($bytecode ? Functions::cbc('extension') : 'extension')] = $this->extension; + } - if($this->MinimumVersion !== null && strlen($this->MinimumVersion) > 0) - $return_results['minimum_version'] = $this->MinimumVersion; + if($this->minimum_version !== null && $this->minimum_version !== '') + { + $results[($bytecode ? Functions::cbc('minimum_version') : 'minimum_version')] = $this->minimum_version; + } - if($this->MaximumVersion !== null && strlen($this->MaximumVersion) > 0) - $return_results['maximum_version'] = $this->MaximumVersion; + if($this->maximum_version !== null && $this->maximum_version !== '') + { + $results[($bytecode ? Functions::cbc('maximum_version') : 'maximum_version')] = $this->maximum_version; + } - return $return_results; + return $results; } /** - * Constructs object from an array representation - * - * @param array $data - * @return Compiler + * @inheritDoc */ public static function fromArray(array $data): Compiler { - $CompilerObject = new Compiler(); + $object = new self(); - $CompilerObject->MaximumVersion = Functions::array_bc($data, 'maximum_version'); - $CompilerObject->Extension = Functions::array_bc($data, 'extension'); - $CompilerObject->MinimumVersion = Functions::array_bc($data, 'minimum_version'); + $object->maximum_version = Functions::array_bc($data, 'maximum_version'); + $object->extension = Functions::array_bc($data, 'extension'); + $object->minimum_version = Functions::array_bc($data, 'minimum_version'); - return $CompilerObject; + return $object; } } \ No newline at end of file diff --git a/src/ncc/Objects/ProjectConfiguration/Dependency.php b/src/ncc/Objects/ProjectConfiguration/Dependency.php index 46b6f8c..9d23183 100644 --- a/src/ncc/Objects/ProjectConfiguration/Dependency.php +++ b/src/ncc/Objects/ProjectConfiguration/Dependency.php @@ -1,30 +1,31 @@ Name; - - if($this->SourceType !== null && strlen($this->SourceType) > 0) - $ReturnResults[($bytecode ? Functions::cbc('source_type') : 'source_type')] = $this->SourceType; - - if($this->Source !== null && strlen($this->Source) > 0) - $ReturnResults[($bytecode ? Functions::cbc('source') : 'source')] = $this->Source; - - if($this->Version !== null && strlen($this->Version) > 0) - $ReturnResults[($bytecode ? Functions::cbc('version') : 'version')] = $this->Version; - - return $ReturnResults; - } - - /** - * Constructs the object from an array representation - * - * @param array $data - * @return Dependency - */ - public static function fromArray(array $data): Dependency - { - $DependencyObject = new Dependency(); - - $DependencyObject->Name = Functions::array_bc($data, 'name'); - $DependencyObject->SourceType = Functions::array_bc($data, 'source_type'); - $DependencyObject->Source = Functions::array_bc($data, 'source'); - $DependencyObject->Version = Functions::array_bc($data, 'version'); - - return $DependencyObject; - } + public $version; /** * Validates the dependency configuration @@ -115,22 +72,68 @@ */ public function validate(bool $throw_exception): bool { - if(!Validate::packageName($this->Name)) + if(!Validate::packageName($this->name)) { if($throw_exception) - throw new InvalidDependencyConfiguration(sprintf('Invalid dependency name "%s"', $this->Name)); + { + throw new InvalidDependencyConfiguration(sprintf('Invalid dependency name "%s"', $this->name)); + } return false; } - if($this->Version !== null && !Validate::version($this->Version)) + if($this->version !== null && !Validate::version($this->version)) { if($throw_exception) - throw new InvalidDependencyConfiguration(sprintf('Invalid dependency version "%s"', $this->Version)); + { + throw new InvalidDependencyConfiguration(sprintf('Invalid dependency version "%s"', $this->version)); + } return false; } return true; } + + /** + * @inheritDoc + */ + public function toArray(bool $bytecode=false): array + { + $results = []; + + $results[($bytecode ? Functions::cbc('name') : 'name')] = $this->name; + + if($this->source_type !== null && $this->source_type !== '') + { + $results[($bytecode ? Functions::cbc('source_type') : 'source_type')] = $this->source_type; + } + + if($this->source !== null && $this->source !== '') + { + $results[($bytecode ? Functions::cbc('source') : 'source')] = $this->source; + } + + if($this->version !== null && $this->version !== '') + { + $results[($bytecode ? Functions::cbc('version') : 'version')] = $this->version; + } + + return $results; + } + + /** + * @inheritDoc + */ + public static function fromArray(array $data): Dependency + { + $object = new self(); + + $object->name = Functions::array_bc($data, 'name'); + $object->source_type = Functions::array_bc($data, 'source_type'); + $object->source = Functions::array_bc($data, 'source'); + $object->version = Functions::array_bc($data, 'version'); + + return $object; + } } \ No newline at end of file diff --git a/src/ncc/Objects/ProjectConfiguration/ExecutionPolicy.php b/src/ncc/Objects/ProjectConfiguration/ExecutionPolicy.php index efc175c..851ab99 100644 --- a/src/ncc/Objects/ProjectConfiguration/ExecutionPolicy.php +++ b/src/ncc/Objects/ProjectConfiguration/ExecutionPolicy.php @@ -1,69 +1,70 @@ Name !== null && strlen($this->Name) > 0) - $results[($bytecode ? Functions::cbc('name') : 'name')] = $this->Name; + if ($this->name !== null && $this->name !== '') + { + $results[($bytecode ? Functions::cbc('name') : 'name')] = $this->name; + } - if ($this->Runner !== null && strlen($this->Runner) > 0) - $results[($bytecode ? Functions::cbc('runner') : 'runner')] = $this->Runner; + if ($this->runner !== null && $this->runner !== '') + { + $results[($bytecode ? Functions::cbc('runner') : 'runner')] = $this->runner; + } - if ($this->Message !== null && strlen($this->Message) > 0) - $results[($bytecode ? Functions::cbc('message') : 'message')] = $this->Message; + if ($this->message !== null && $this->message !== '') + { + $results[($bytecode ? Functions::cbc('message') : 'message')] = $this->message; + } - if ($this->Execute !== null) - $results[($bytecode ? Functions::cbc('execute') : 'execute')] = $this->Execute->toArray($bytecode); + if ($this->execute !== null) + { + $results[($bytecode ? Functions::cbc('execute') : 'execute')] = $this->execute->toArray($bytecode); + } - if ($this->ExitHandlers !== null) - $results[($bytecode ? Functions::cbc('exit_handlers') : 'exit_handlers')] = $this->ExitHandlers->toArray($bytecode); + if ($this->exit_handlers !== null) + { + $results[($bytecode ? Functions::cbc('exit_handlers') : 'exit_handlers')] = $this->exit_handlers->toArray($bytecode); + } return $results; } /** - * @param array $data - * @return ExecutionPolicy + * @inheritDoc */ - public static function fromArray(array $data): self + public static function fromArray(array $data): ExecutionPolicy { $object = new self(); - $object->Name = Functions::array_bc($data, 'name'); - $object->Runner = Functions::array_bc($data, 'runner'); - $object->Message = Functions::array_bc($data, 'message'); - $object->Execute = Functions::array_bc($data, 'execute'); - $object->ExitHandlers = Functions::array_bc($data, 'exit_handlers'); + $object->name = Functions::array_bc($data, 'name'); + $object->runner = Functions::array_bc($data, 'runner'); + $object->message = Functions::array_bc($data, 'message'); + $object->execute = Functions::array_bc($data, 'execute'); + $object->exit_handlers = Functions::array_bc($data, 'exit_handlers'); - if($object->Execute !== null) - $object->Execute = Execute::fromArray($object->Execute); + if($object->execute !== null) + { + $object->execute = Execute::fromArray($object->execute); + } - if($object->ExitHandlers !== null) - $object->ExitHandlers = ExitHandlers::fromArray($object->ExitHandlers); + if($object->exit_handlers !== null) + { + $object->exit_handlers = ExitHandlers::fromArray($object->exit_handlers); + } return $object; } diff --git a/src/ncc/Objects/ProjectConfiguration/Installer.php b/src/ncc/Objects/ProjectConfiguration/Installer.php index b229ffd..88e97cb 100644 --- a/src/ncc/Objects/ProjectConfiguration/Installer.php +++ b/src/ncc/Objects/ProjectConfiguration/Installer.php @@ -1,120 +1,129 @@ PreInstall !== null && count($this->PreInstall) > 0) - $results[($bytecode ? Functions::cbc('pre_install') : 'pre_install')] = $this->PreInstall; + if($this->pre_install !== null && count($this->pre_install) > 0) + { + $results[($bytecode ? Functions::cbc('pre_install') : 'pre_install')] = $this->pre_install; + } - if($this->PostInstall !== null && count($this->PostInstall) > 0) - $results[($bytecode ? Functions::cbc('post_install') : 'post_install')] = $this->PostInstall; + if($this->post_install !== null && count($this->post_install) > 0) + { + $results[($bytecode ? Functions::cbc('post_install') : 'post_install')] = $this->post_install; + } - if($this->PreUninstall !== null && count($this->PreUninstall) > 0) - $results[($bytecode ? Functions::cbc('pre_uninstall') : 'pre_uninstall')] = $this->PreUninstall; + if($this->pre_uninstall !== null && count($this->pre_uninstall) > 0) + { + $results[($bytecode ? Functions::cbc('pre_uninstall') : 'pre_uninstall')] = $this->pre_uninstall; + } - if($this->PostUninstall !== null && count($this->PostUninstall) > 0) - $results[($bytecode ? Functions::cbc('post_uninstall') : 'post_uninstall')] = $this->PostUninstall; + if($this->post_uninstall !== null && count($this->post_uninstall) > 0) + { + $results[($bytecode ? Functions::cbc('post_uninstall') : 'post_uninstall')] = $this->post_uninstall; + } - if($this->PreUpdate !== null && count($this->PreUpdate) > 0) - $results[($bytecode ? Functions::cbc('pre_update') : 'pre_update')] = $this->PreUpdate; + if($this->pre_update !== null && count($this->pre_update) > 0) + { + $results[($bytecode ? Functions::cbc('pre_update') : 'pre_update')] = $this->pre_update; + } - if($this->PostUpdate !== null && count($this->PostUpdate) > 0) - $results[($bytecode ? Functions::cbc('post_update') : 'post_update')] = $this->PostUpdate; + if($this->post_update !== null && count($this->post_update) > 0) + { + $results[($bytecode ? Functions::cbc('post_update') : 'post_update')] = $this->post_update; + } return $results; } /** - * @param array $data - * @return Installer + * @inheritDoc */ - public static function fromArray(array $data): self + public static function fromArray(array $data): Installer { $object = new self(); - $object->PreInstall = Functions::array_bc($data, 'pre_install'); - $object->PostInstall = Functions::array_bc($data, 'post_install'); - $object->PreUninstall = Functions::array_bc($data, 'pre_uninstall'); - $object->PostUninstall = Functions::array_bc($data, 'post_uninstall'); - $object->PreUpdate = Functions::array_bc($data, 'pre_update'); - $object->PostUpdate = Functions::array_bc($data, 'post_update'); + $object->pre_install = Functions::array_bc($data, 'pre_install'); + $object->post_install = Functions::array_bc($data, 'post_install'); + $object->pre_uninstall = Functions::array_bc($data, 'pre_uninstall'); + $object->post_uninstall = Functions::array_bc($data, 'post_uninstall'); + $object->pre_update = Functions::array_bc($data, 'pre_update'); + $object->post_update = Functions::array_bc($data, 'post_update'); return $object; } diff --git a/src/ncc/Objects/ProjectConfiguration/Project.php b/src/ncc/Objects/ProjectConfiguration/Project.php index 77e15db..c2f2427 100644 --- a/src/ncc/Objects/ProjectConfiguration/Project.php +++ b/src/ncc/Objects/ProjectConfiguration/Project.php @@ -1,24 +1,24 @@ Compiler = new Compiler(); - $this->Options = []; + $this->compiler = new Compiler(); + $this->options = []; } /** @@ -72,8 +73,10 @@ */ public function validate(bool $throw_exception=True): bool { - if(!$this->Compiler->validate($throw_exception)) + if(!$this->compiler->validate($throw_exception)) + { return False; + } return True; } @@ -86,15 +89,17 @@ */ public function toArray(bool $bytecode=false): array { - $ReturnResults = []; + $results = []; - $ReturnResults[($bytecode ? Functions::cbc('compiler') : 'compiler')] = $this->Compiler->toArray(); - $ReturnResults[($bytecode ? Functions::cbc('options') : 'options')] = $this->Options; + $results[($bytecode ? Functions::cbc('compiler') : 'compiler')] = $this->compiler->toArray(); + $results[($bytecode ? Functions::cbc('options') : 'options')] = $this->options; - if($this->UpdateSource !== null) - $ReturnResults[($bytecode ? Functions::cbc('update_source') : 'update_source')] = $this->UpdateSource->toArray($bytecode); + if($this->update_source !== null) + { + $results[($bytecode ? Functions::cbc('update_source') : 'update_source')] = $this->update_source->toArray($bytecode); + } - return $ReturnResults; + return $results; } /** @@ -105,23 +110,23 @@ */ public static function fromArray(array $data): Project { - $ProjectObject = new Project(); + $object = new self(); if(Functions::array_bc($data, 'compiler') !== null) { - $ProjectObject->Compiler = Compiler::fromArray(Functions::array_bc($data, 'compiler')); + $object->compiler = Compiler::fromArray(Functions::array_bc($data, 'compiler')); } if(Functions::array_bc($data, 'options') !== null) { - $ProjectObject->Options = Functions::array_bc($data, 'options'); + $object->options = Functions::array_bc($data, 'options'); } if(Functions::array_bc($data, 'update_source') !== null) { - $ProjectObject->UpdateSource = UpdateSource::fromArray(Functions::array_bc($data, 'update_source')); + $object->update_source = UpdateSource::fromArray(Functions::array_bc($data, 'update_source')); } - return $ProjectObject; + return $object; } } \ No newline at end of file diff --git a/src/ncc/Objects/ProjectConfiguration/UpdateSource.php b/src/ncc/Objects/ProjectConfiguration/UpdateSource.php index 1cb0c97..a16c6d3 100644 --- a/src/ncc/Objects/ProjectConfiguration/UpdateSource.php +++ b/src/ncc/Objects/ProjectConfiguration/UpdateSource.php @@ -1,47 +1,48 @@ $this->Source, - ($bytecode ? Functions::cbc('repository') : 'repository') => ($this->Repository?->toArray($bytecode)) + ($bytecode ? Functions::cbc('source') : 'source') => $this->source, + ($bytecode ? Functions::cbc('repository') : 'repository') => ($this->repository?->toArray($bytecode)) ]; } @@ -66,13 +67,16 @@ */ public static function fromArray(array $data): UpdateSource { - $obj = new UpdateSource(); - $obj->Source = Functions::array_bc($data, 'source'); - $obj->Repository = Functions::array_bc($data, 'repository'); + $object = new self(); - if($obj->Repository !== null) - $obj->Repository = Repository::fromArray($obj->Repository); + $object->source = Functions::array_bc($data, 'source'); + $object->repository = Functions::array_bc($data, 'repository'); - return $obj; + if($object->repository !== null) + { + $object->repository = Repository::fromArray($object->repository); + } + + return $object; } } \ No newline at end of file diff --git a/src/ncc/Runtime.php b/src/ncc/Runtime.php index 6a6d07b..d1a233d 100644 --- a/src/ncc/Runtime.php +++ b/src/ncc/Runtime.php @@ -136,19 +136,19 @@ // Import all dependencies first /** @var Dependency $dependency */ foreach($version_entry->Dependencies as $dependency) - self::import($dependency->PackageName, $dependency->Version, $options); + self::import($dependency->PackageName, $dependency->version, $options); } try { - switch($version_entry->Compiler->Extension) + switch($version_entry->Compiler->extension) { case CompilerExtensions::PHP: PhpRuntime::import($version_entry, $options); break; default: - throw new ImportException(sprintf('Compiler extension %s is not supported in this runtime', $version_entry->Compiler->Extension)); + throw new ImportException(sprintf('Compiler extension %s is not supported in this runtime', $version_entry->Compiler->extension)); } } catch(Exception $e) diff --git a/src/ncc/Utilities/Functions.php b/src/ncc/Utilities/Functions.php index e137abe..31d7c04 100644 --- a/src/ncc/Utilities/Functions.php +++ b/src/ncc/Utilities/Functions.php @@ -301,7 +301,7 @@ */ public static function compileRunner(string $path, ExecutionPolicy $policy): ExecutionUnit { - return match (strtolower($policy->Runner)) + return match (strtolower($policy->runner)) { Runners::BASH => BashRunner::processUnit($path, $policy), Runners::PHP => PhpRunner::processUnit($path, $policy), @@ -310,7 +310,7 @@ Runners::PYTHON_2 => Python2Runner::processUnit($path, $policy), Runners::PYTHON_3 => Python3Runner::processUnit($path, $policy), Runners::LUA => LuaRunner::processUnit($path, $policy), - default => throw new RunnerExecutionException('The runner \'' . $policy->Runner . '\' is not supported'), + default => throw new RunnerExecutionException('The runner \'' . $policy->runner . '\' is not supported'), }; }