- Added a new interface class SerializableObjectInterface to implement serializable objects, BytecodeObjectInterface

extends this interface to allow for serialization of compiled assets
 - Updated class `\ncc\Objects\ComposerJson > Author` to use method calls rather than direct property access and
   implemented `SerializableObjectInterface`
 - Updated class `\ncc\Objects\ComposerJson > Autoloader` to use method calls rather than direct property access and
   implemented `SerializableObjectInterface`
 - Updated class `\ncc\Objects\ComposerJson > Funding` to use method calls rather than direct property access and
   implemented `SerializableObjectInterface`
 - Updated class `\ncc\Objects\ComposerJson > NamespacePointer` to use method calls rather than direct property access
   and implemented `SerializableObjectInterface`
 - Updated class `\ncc\Objects\ComposerJson > PackageLink` to use method calls rather than direct property access and
   implemented `SerializableObjectInterface`
 - Updated class `\ncc\Objects\ComposerJson > Suggestion` to use method calls rather than direct property access and
   implemented `SerializableObjectInterface`
 - Updated class `\ncc\Objects\ComposerJson > Support` to use method calls rather than direct property access and
   implemented `SerializableObjectInterface`
 - Updated class `\ncc\Objects\ExecutionPointers > ExecutionPointer` to use method calls rather than direct property
   access and implemented `BytecodeObjectInterface`
 - Updated class `\ncc\Objects\NccVersionInformation > Component` to use method calls rather than direct property access
   and implemented `SerializableObjectInterface`
 - Updated class `\ncc\Objects\Package > Component` to use method calls rather than direct property access and
   implemented `BytecodeObjectInterface`
 - Updated class `\ncc\Objects\Package > ExecutionUnit` to use method calls rather than direct property access and
   implemented `BytecodeObjectInterface`
 - Updated class `\ncc\Objects\Package > Header` to use method calls rather than direct property access and implemented
   `BytecodeObjectInterface`
 - Updated class `\ncc\Objects\Package > Installer` to use method calls rather than direct property access and implemented
   `BytecodeObjectInterface`
 - Updated class `\ncc\Objects\Package > MagicBytes` to use method calls rather than direct property access and implemented
   `SerializableObjectInterface`
 - Updated class `\ncc\Objects\Package > Resource` to use method calls rather than direct property access and implemented
   `BytecodeObjectInterface`
 -  Updated class `\ncc\Objects\PackageLock > DependencyEntry` to use method calls rather than direct property access
    and implemented `BytecodeObjectInterface`
 - Updated class `\ncc\Objects\PackageLock > PackageEntry` to use method calls rather than direct property access
   and implemented `BytecodeObjectInterface`
 - Updated class `\ncc\Objects\PackageLock > VersionEntry` to use method calls rather than direct property access
   and implemented `BytecodeObjectInterface`
This commit is contained in:
Netkas 2023-08-28 18:27:09 -04:00
parent 2ea1dfc27a
commit 729c9cb217
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
44 changed files with 1845 additions and 884 deletions

View file

@ -1,6 +1,7 @@
<component name="InspectionProjectProfileManager"> <component name="InspectionProjectProfileManager">
<profile version="1.0"> <profile version="1.0">
<option name="myName" value="Project Default" /> <option name="myName" value="Project Default" />
<inspection_tool class="ContractViolationInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true"> <inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages> <Languages>
<language minSize="133" name="PHP" /> <language minSize="133" name="PHP" />

View file

@ -19,6 +19,8 @@ features and reduced the number of exceptions down to 15 exceptions.
- Added new exception `GitException` in `\ncc\Exceptions` to replace all git related exceptions - Added new exception `GitException` in `\ncc\Exceptions` to replace all git related exceptions
- Added new exception `PackageException` in `\ncc\Exceptions` to replace all package related exceptions - Added new exception `PackageException` in `\ncc\Exceptions` to replace all package related exceptions
- Added new exception `OperationException` in `\ncc\Exceptions` to replace all generic related exceptions - Added new exception `OperationException` in `\ncc\Exceptions` to replace all generic related exceptions
- Added a new interface class `SerializableObjectInterface` to implement serializable objects, `BytecodeObjectInterface`
extends this interface to allow for serialization of compiled assets
### Fixed ### Fixed
- Fixed MITM attack vector in `\ncc\Classes > HttpClient > prepareCurl()` - Fixed MITM attack vector in `\ncc\Classes > HttpClient > prepareCurl()`
@ -137,6 +139,42 @@ features and reduced the number of exceptions down to 15 exceptions.
- Updated class `\ncc\Objects\ProjectConfiguration > Installer` to use method calls rather than direct property access - Updated class `\ncc\Objects\ProjectConfiguration > Installer` to use method calls rather than direct property access
- Updated class `\ncc\Objects\ProjectConfiguration > Project` to use method calls rather than direct property access - Updated class `\ncc\Objects\ProjectConfiguration > Project` to use method calls rather than direct property access
- Updated class `\ncc\Objects\ProjectConfiguration > UpdateSource` to use method calls rather than direct property access - Updated class `\ncc\Objects\ProjectConfiguration > UpdateSource` to use method calls rather than direct property access
- Updated class `\ncc\Objects\ComposerJson > Author` to use method calls rather than direct property access and
implemented `SerializableObjectInterface`
- Updated class `\ncc\Objects\ComposerJson > Autoloader` to use method calls rather than direct property access and
implemented `SerializableObjectInterface`
- Updated class `\ncc\Objects\ComposerJson > Funding` to use method calls rather than direct property access and
implemented `SerializableObjectInterface`
- Updated class `\ncc\Objects\ComposerJson > NamespacePointer` to use method calls rather than direct property access
and implemented `SerializableObjectInterface`
- Updated class `\ncc\Objects\ComposerJson > PackageLink` to use method calls rather than direct property access and
implemented `SerializableObjectInterface`
- Updated class `\ncc\Objects\ComposerJson > Suggestion` to use method calls rather than direct property access and
implemented `SerializableObjectInterface`
- Updated class `\ncc\Objects\ComposerJson > Support` to use method calls rather than direct property access and
implemented `SerializableObjectInterface`
- Updated class `\ncc\Objects\ExecutionPointers > ExecutionPointer` to use method calls rather than direct property
access and implemented `BytecodeObjectInterface`
- Updated class `\ncc\Objects\NccVersionInformation > Component` to use method calls rather than direct property access
and implemented `SerializableObjectInterface`
- Updated class `\ncc\Objects\Package > Component` to use method calls rather than direct property access and
implemented `BytecodeObjectInterface`
- Updated class `\ncc\Objects\Package > ExecutionUnit` to use method calls rather than direct property access and
implemented `BytecodeObjectInterface`
- Updated class `\ncc\Objects\Package > Header` to use method calls rather than direct property access and implemented
`BytecodeObjectInterface`
- Updated class `\ncc\Objects\Package > Installer` to use method calls rather than direct property access and implemented
`BytecodeObjectInterface`
- Updated class `\ncc\Objects\Package > MagicBytes` to use method calls rather than direct property access and implemented
`SerializableObjectInterface`
- Updated class `\ncc\Objects\Package > Resource` to use method calls rather than direct property access and implemented
`BytecodeObjectInterface`
- Updated class `\ncc\Objects\PackageLock > DependencyEntry` to use method calls rather than direct property access
and implemented `BytecodeObjectInterface`
- Updated class `\ncc\Objects\PackageLock > PackageEntry` to use method calls rather than direct property access
and implemented `BytecodeObjectInterface`
- Updated class `\ncc\Objects\PackageLock > VersionEntry` to use method calls rather than direct property access
and implemented `BytecodeObjectInterface`
### Removed ### Removed
- Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions` - Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions`

View file

@ -291,7 +291,7 @@
foreach($VersionInformation->Components as $component) foreach($VersionInformation->Components as $component)
{ {
$full_name = $component->vendor . '/' . $component->package_name; $full_name = $component->getVendor() . '/' . $component->getPackageName();
try try
{ {

View file

@ -81,7 +81,7 @@ namespace ncc\CLI\Commands;
try try
{ {
$units = $execution_pointer_manager->getUnits($package_entry->Name, $version_entry->Version); $units = $execution_pointer_manager->getUnits($package_entry->getName(), $version_entry->getVersion());
} }
catch(Exception $e) catch(Exception $e)
{ {
@ -106,7 +106,7 @@ namespace ncc\CLI\Commands;
try try
{ {
exit($execution_pointer_manager->executeUnit($package_entry->Name, $version_entry->Version, $unit_name, $options)); exit($execution_pointer_manager->executeUnit($package_entry->getName(), $version_entry->getVersion(), $unit_name, $options));
} }
catch(Exception $e) catch(Exception $e)
{ {

View file

@ -237,7 +237,7 @@
Console::out('resources:'); Console::out('resources:');
foreach($package->resources as $resource) foreach($package->resources as $resource)
{ {
Console::out(' - ' . sprintf('%s - (%s)', $resource->Name, Functions::b2u(strlen($resource->Data)))); Console::out(' - ' . sprintf('%s - (%s)', $resource->getName(), Functions::b2u(strlen($resource->getData()))));
} }
} }
else else
@ -252,7 +252,7 @@
{ {
try try
{ {
Console::out(' - ' . sprintf('#%s %s - %s', $component->data_types, $component->name, json_encode(($component->flags ?? []), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES))); Console::out(' - ' . sprintf('#%s %s - %s', $component->getDataType(), $component->getName(), json_encode(($component->getFlags() ?? []), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES)));
} }
catch(JsonException $e) catch(JsonException $e)
{ {
@ -315,7 +315,7 @@
Console::out(sprintf('%s=%s (%s)', Console::out(sprintf('%s=%s (%s)',
Console::formatColor($package, ConsoleColors::LIGHT_GREEN), Console::formatColor($package, ConsoleColors::LIGHT_GREEN),
Console::formatColor($version, ConsoleColors::LIGHT_MAGENTA), Console::formatColor($version, ConsoleColors::LIGHT_MAGENTA),
$package_manager->getPackageVersion($package, $version)->Compiler->getExtension() $package_manager->getPackageVersion($package, $version)->getCompiler()->getExtension()
)); ));
} }
catch(Exception $e) catch(Exception $e)
@ -559,21 +559,21 @@
} }
Console::out(sprintf('Extension: %s', Console::out(sprintf('Extension: %s',
Console::formatColor($package->header->CompilerExtension->getExtension(), ConsoleColors::GREEN) Console::formatColor($package->header->getCompilerExtension()->getExtension(), ConsoleColors::GREEN)
)); ));
if($package->header->CompilerExtension->getMinimumVersion() !== null) if($package->header->getCompilerExtension()->getMinimumVersion() !== null)
{ {
Console::out(sprintf('Maximum Version: %s', Console::out(sprintf('Maximum Version: %s',
Console::formatColor($package->header->CompilerExtension->getMinimumVersion(), ConsoleColors::LIGHT_MAGENTA) Console::formatColor($package->header->getCompilerExtension()->getMinimumVersion(), ConsoleColors::LIGHT_MAGENTA)
)); ));
} }
if($package->header->CompilerExtension->getMinimumVersion() !== null) if($package->header->getCompilerExtension()->getMinimumVersion() !== null)
{ {
Console::out(sprintf('Minimum Version: %s', Console::out(sprintf('Minimum Version: %s',
Console::formatColor($package->header->CompilerExtension->getMinimumVersion(), ConsoleColors::LIGHT_MAGENTA) Console::formatColor($package->header->getCompilerExtension()->getMinimumVersion(), ConsoleColors::LIGHT_MAGENTA)
)); ));
} }

View file

@ -43,8 +43,8 @@ namespace ncc\Classes\BashExtension;
} }
$execution_unit = new ExecutionUnit(); $execution_unit = new ExecutionUnit();
$execution_unit->execution_policy = $policy; $execution_unit->setExecutionPolicy($policy);
$execution_unit->Data = IO::fread($path); $execution_unit->setData(IO::fread($path));
return $execution_unit; return $execution_unit;
} }

View file

@ -346,7 +346,7 @@
foreach ($composer_package->require as $item) foreach ($composer_package->require as $item)
{ {
// Check if the dependency is already in the project configuration // Check if the dependency is already in the project configuration
$package_name = self::toPackageName($item->package_name); $package_name = self::toPackageName($item->getPackageName());
if($package_name === null) if($package_name === null)
{ {
@ -356,7 +356,7 @@
$dependency = new ProjectConfiguration\Dependency(); $dependency = new ProjectConfiguration\Dependency();
$dependency->setName($package_name); $dependency->setName($package_name);
$dependency->setSourceType(DependencySourceType::LOCAL); $dependency->setSourceType(DependencySourceType::LOCAL);
$dependency->setVersion(self::versionMap($item->package_name, $version_map)); $dependency->setVersion(self::versionMap($item->getPackageName(), $version_map));
$dependency->setSource($package_name . '.ncc'); $dependency->setSource($package_name . '.ncc');
$project_configuration->build->addDependency($dependency); $project_configuration->build->addDependency($dependency);
} }
@ -688,34 +688,34 @@
$static_files = []; $static_files = [];
// Extract all the source directories // Extract all the source directories
if ($composer_package->autoload->psr_4 !== null && count($composer_package->autoload->psr_4) > 0) if ($composer_package->autoload->getPsr4() !== null && count($composer_package->autoload->getPsr4()) > 0)
{ {
Console::outVerbose('Extracting PSR-4 source directories'); Console::outVerbose('Extracting PSR-4 source directories');
foreach ($composer_package->autoload->psr_4 as $namespace_pointer) foreach ($composer_package->autoload->getPsr4() as $namespace_pointer)
{ {
if ($namespace_pointer->Path !== null && !in_array($namespace_pointer->Path, $source_directories, true)) if ($namespace_pointer->getPath() !== null && !in_array($namespace_pointer->getPath(), $source_directories, true))
{ {
$source_directories[] = $package_path . DIRECTORY_SEPARATOR . $namespace_pointer->Path; $source_directories[] = $package_path . DIRECTORY_SEPARATOR . $namespace_pointer->getPath();
} }
} }
} }
if ($composer_package->autoload->psr_0 !== null && count($composer_package->autoload->psr_0) > 0) if ($composer_package->autoload->getPsr0() !== null && count($composer_package->autoload->getPsr0()) > 0)
{ {
Console::outVerbose('Extracting PSR-0 source directories'); Console::outVerbose('Extracting PSR-0 source directories');
foreach ($composer_package->autoload->psr_0 as $namespace_pointer) foreach ($composer_package->autoload->getPsr0() as $namespace_pointer)
{ {
if ($namespace_pointer->Path !== null && !in_array($namespace_pointer->Path, $source_directories, true)) if ($namespace_pointer->getPath() !== null && !in_array($namespace_pointer->getPath(), $source_directories, true))
{ {
$source_directories[] = $package_path . DIRECTORY_SEPARATOR . $namespace_pointer->Path; $source_directories[] = $package_path . DIRECTORY_SEPARATOR . $namespace_pointer->getPath();
} }
} }
} }
if ($composer_package->autoload->files !== null && count($composer_package->autoload->files) > 0) if ($composer_package->autoload->getFiles() !== null && count($composer_package->autoload->getFiles()) > 0)
{ {
Console::outVerbose('Extracting static files'); Console::outVerbose('Extracting static files');
foreach ($composer_package->autoload->files as $file) foreach ($composer_package->autoload->getFiles() as $file)
{ {
$static_files[] = $package_path . DIRECTORY_SEPARATOR . $file; $static_files[] = $package_path . DIRECTORY_SEPARATOR . $file;
} }
@ -800,21 +800,21 @@
Console::out(sprintf('Authors for package %s:', $composer_package->name)); Console::out(sprintf('Authors for package %s:', $composer_package->name));
foreach($composer_package->authors as $author) foreach($composer_package->authors as $author)
{ {
Console::out(sprintf(' - %s', $author->Name)); Console::out(sprintf(' - %s', $author->getName()));
if($author->Email !== null) if($author->getEmail() !== null)
{ {
Console::out(sprintf(' %s', $author->Email)); Console::out(sprintf(' %s', $author->getEmail()));
} }
if($author->Homepage !== null) if($author->getHomepage() !== null)
{ {
Console::out(sprintf(' %s', $author->Homepage)); Console::out(sprintf(' %s', $author->getHomepage()));
} }
if($author->Role !== null) if($author->getRole() !== null)
{ {
Console::out(sprintf(' %s', $author->Role)); Console::out(sprintf(' %s', $author->getRole()));
} }
} }

View file

@ -38,8 +38,8 @@ namespace ncc\Classes\LuaExtension;
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
{ {
$execution_unit = new ExecutionUnit(); $execution_unit = new ExecutionUnit();
$execution_unit->execution_policy = $policy; $execution_unit->setExecutionPolicy($policy);
$execution_unit->Data = IO::fread($path); $execution_unit->setData(IO::fread($path));
return $execution_unit; return $execution_unit;
} }

View file

@ -263,7 +263,7 @@
$units = []; $units = [];
foreach($package->execution_units as $executionUnit) foreach($package->execution_units as $executionUnit)
{ {
Console::outDebug(sprintf('compiling execution unit constant %s (%s)', $executionUnit->execution_policy->getName(), implode(', ', array_keys($refs)))); Console::outDebug(sprintf('compiling execution unit constant %s (%s)', $executionUnit->getExecutionPolicy()->getName(), implode(', ', array_keys($refs))));
$units[] = self::compileExecutionUnitConstants($executionUnit, $refs); $units[] = self::compileExecutionUnitConstants($executionUnit, $refs);
} }
$package->execution_units = $units; $package->execution_units = $units;
@ -271,14 +271,14 @@
} }
$compiled_constants = []; $compiled_constants = [];
foreach($package->header->RuntimeConstants as $name => $value) foreach($package->header->getRuntimeConstants() as $name => $value)
{ {
Console::outDebug(sprintf('compiling runtime constant %s (%s)', $name, implode(', ', array_keys($refs)))); Console::outDebug(sprintf('compiling runtime constant %s (%s)', $name, implode(', ', array_keys($refs))));
$compiled_constants[$name] = self::compileConstants($value, $refs); $compiled_constants[$name] = self::compileConstants($value, $refs);
} }
$options = []; $options = [];
foreach($package->header->Options as $name => $value) foreach($package->header->getOptions() as $name => $value)
{ {
if(is_array($value)) if(is_array($value))
{ {
@ -301,8 +301,8 @@
} }
} }
$package->header->Options = $options; $package->header->setOptions($options);
$package->header->RuntimeConstants = $compiled_constants; $package->header->setRuntimeConstants($compiled_constants);
} }
/** /**
@ -314,47 +314,47 @@
*/ */
public static function compileExecutionUnitConstants(Package\ExecutionUnit $unit, array $refs): Package\ExecutionUnit public static function compileExecutionUnitConstants(Package\ExecutionUnit $unit, array $refs): Package\ExecutionUnit
{ {
$unit->execution_policy->setMessage(self::compileConstants($unit->execution_policy->getMessage(), $refs)); $unit->getExecutionPolicy()->setMessage(self::compileConstants($unit->getExecutionPolicy()->getMessage(), $refs));
if($unit->execution_policy->getExitHandlers() !== null) if($unit->getExecutionPolicy()->getExitHandlers() !== null)
{ {
if($unit->execution_policy->getExitHandlers()->getSuccess()?->getMessage() !== null) if($unit->getExecutionPolicy()->getExitHandlers()->getSuccess()?->getMessage() !== null)
{ {
$unit->execution_policy->getExitHandlers()->getSuccess()?->setMessage( $unit->getExecutionPolicy()->getExitHandlers()->getSuccess()?->setMessage(
self::compileConstants($unit->execution_policy->getExitHandlers()->getSuccess()->getMessage(), $refs) self::compileConstants($unit->getExecutionPolicy()->getExitHandlers()->getSuccess()->getMessage(), $refs)
); );
} }
if($unit->execution_policy->getExitHandlers()->getError()?->getMessage() !== null) if($unit->getExecutionPolicy()->getExitHandlers()->getError()?->getMessage() !== null)
{ {
$unit->execution_policy->getExitHandlers()->getError()?->setMessage( $unit->getExecutionPolicy()->getExitHandlers()->getError()?->setMessage(
self::compileConstants($unit->execution_policy->getExitHandlers()->getError()->getMessage(), $refs) self::compileConstants($unit->getExecutionPolicy()->getExitHandlers()->getError()->getMessage(), $refs)
); );
} }
if($unit->execution_policy->getExitHandlers()->getWarning()?->getMessage() !== null) if($unit->getExecutionPolicy()->getExitHandlers()->getWarning()?->getMessage() !== null)
{ {
$unit->execution_policy->getExitHandlers()->getWarning()?->setMessage( $unit->getExecutionPolicy()->getExitHandlers()->getWarning()?->setMessage(
self::compileConstants($unit->execution_policy->getExitHandlers()->getWarning()->getMessage(), $refs) self::compileConstants($unit->getExecutionPolicy()->getExitHandlers()->getWarning()->getMessage(), $refs)
); );
} }
} }
if($unit->execution_policy->getExecute() !== null) if($unit->getExecutionPolicy()->getExecute() !== null)
{ {
$unit->execution_policy->getExecute()->setTarget(self::compileConstants($unit->execution_policy->getExecute()->getTarget(), $refs)); $unit->getExecutionPolicy()->getExecute()->setTarget(self::compileConstants($unit->getExecutionPolicy()->getExecute()->getTarget(), $refs));
$unit->execution_policy->getExecute()->setWorkingDirectory(self::compileConstants($unit->execution_policy->getExecute()->getWorkingDirectory(), $refs)); $unit->getExecutionPolicy()->getExecute()->setWorkingDirectory(self::compileConstants($unit->getExecutionPolicy()->getExecute()->getWorkingDirectory(), $refs));
if(count($unit->execution_policy->getExecute()->getOptions()) > 0) if(count($unit->getExecutionPolicy()->getExecute()->getOptions()) > 0)
{ {
$options = []; $options = [];
foreach($unit->execution_policy->getExecute()->getOptions() as $key=> $value) foreach($unit->getExecutionPolicy()->getExecute()->getOptions() as $key=> $value)
{ {
$options[self::compileConstants($key, $refs)] = self::compileConstants($value, $refs); $options[self::compileConstants($key, $refs)] = self::compileConstants($value, $refs);
} }
$unit->execution_policy->getExecute()->setOptions($options); $unit->getExecutionPolicy()->getExecute()->setOptions($options);
} }
} }

View file

@ -56,7 +56,7 @@
$ExecutionPointerManager = new ExecutionPointerManager(); $ExecutionPointerManager = new ExecutionPointerManager();
$ExecutionPointerManager->addUnit($package, $version, $unit, true); $ExecutionPointerManager->addUnit($package, $version, $unit, true);
$ExecutionPointerManager->executeUnit($package, $version, $unit->execution_policy->getName()); $ExecutionPointerManager->executeUnit($package, $version, $unit->getExecutionPolicy()->getName());
$ExecutionPointerManager->cleanTemporaryUnits(); $ExecutionPointerManager->cleanTemporaryUnits();
} }
} }

View file

@ -49,8 +49,8 @@
throw new PathNotFoundException($path); throw new PathNotFoundException($path);
} }
$execution_unit->execution_policy = $policy; $execution_unit->setExecutionPolicy($policy);
$execution_unit->Data = IO::fread($path); $execution_unit->setData(IO::fread($path));
return $execution_unit; return $execution_unit;
} }

View file

@ -58,7 +58,7 @@
/** /**
* @var ProjectConfiguration * @var ProjectConfiguration
*/ */
private $project; private $project_configuration;
/** /**
* @var Package|null * @var Package|null
@ -76,7 +76,7 @@
*/ */
public function __construct(ProjectConfiguration $project, string $path) public function __construct(ProjectConfiguration $project, string $path)
{ {
$this->project = $project; $this->project_configuration = $project;
$this->path = $path; $this->path = $path;
} }
@ -95,7 +95,7 @@
try try
{ {
/** @noinspection PhpRedundantOptionalArgumentInspection */ /** @noinspection PhpRedundantOptionalArgumentInspection */
$this->project->validate(True); $this->project_configuration->validate(True);
} }
catch (Exception $e) catch (Exception $e)
{ {
@ -103,36 +103,35 @@
} }
// Select the build configuration // Select the build configuration
$selected_build_configuration = $this->project->build->getBuildConfiguration($build_configuration); $selected_build_configuration = $this->project_configuration->build->getBuildConfiguration($build_configuration);
// Create the package object // Create the package object
$this->package = new Package(); $this->package = new Package();
$this->package->assembly = $this->project->assembly; $this->package->assembly = $this->project_configuration->assembly;
$this->package->dependencies = $this->project->build->getDependencies(); $this->package->dependencies = $this->project_configuration->build->getDependencies();
$this->package->main_execution_policy = $this->project->build->getMain(); $this->package->main_execution_policy = $this->project_configuration->build->getMain();
// Add the option to create a symbolic link to the package // Add the option to create a symbolic link to the package
if(isset($this->project->project->getOptions()['create_symlink']) && $this->project->project->getOptions()['create_symlink'] === True) if(isset($this->project_configuration->project->getOptions()['create_symlink']) && $this->project_configuration->project->getOptions()['create_symlink'] === True)
{ {
$this->package->header->Options['create_symlink'] = true; $this->package->header->setOption('create_symlink', true);
} }
// Add both the defined constants from the build configuration and the global constants. // Add both the defined constants from the build configuration and the global constants.
// Global constants are overridden // Global constants are overridden
$this->package->header->RuntimeConstants = []; $this->package->header->setRuntimeConstants(array_merge(
$this->package->header->RuntimeConstants = array_merge(
$selected_build_configuration->getDefineConstants(), $selected_build_configuration->getDefineConstants(),
($this->project->build->getDefineConstants()), ($this->project_configuration->build->getDefineConstants()),
($this->package->header->RuntimeConstants ?? []) ($this->package->header->getRuntimeConstants() ?? [])
); ));
$this->package->header->CompilerExtension = $this->project->project->getCompiler(); $this->package->header->setCompilerExtension($this->project_configuration->project->getCompiler());
$this->package->header->CompilerVersion = NCC_VERSION_NUMBER; $this->package->header->setCompilerVersion(NCC_VERSION_NUMBER);
$this->package->header->Options = $this->project->project->getOptions(); $this->package->header->setOptions($this->project_configuration->project->getOptions());
if($this->project->project->getUpdateSource() !== null) if($this->project_configuration->project->getUpdateSource() !== null)
{ {
$this->package->header->UpdateSource = $this->project->project->getUpdateSource(); $this->package->header->setUpdateSource($this->project_configuration->project->getUpdateSource());
} }
Console::outDebug('scanning project files'); Console::outDebug('scanning project files');
@ -158,7 +157,7 @@
$directory_scanner->setExcludes($selected_build_configuration->getExcludeFiles()); $directory_scanner->setExcludes($selected_build_configuration->getExcludeFiles());
} }
$source_path = $this->path . $this->project->build->getSourcePath(); $source_path = $this->path . $this->project_configuration->build->getSourcePath();
// TODO: Re-implement the scanning process outside the compiler, as this is will be redundant // TODO: Re-implement the scanning process outside the compiler, as this is will be redundant
// Scan for components first. // Scan for components first.
@ -176,10 +175,10 @@
} }
$component = new Package\Component(); $component = new Package\Component();
$component->name = Functions::removeBasename($item->getPathname(), $this->path); $component->setName(Functions::removeBasename($item->getPathname(), $this->path));
$this->package->components[] = $component; $this->package->components[] = $component;
Console::outVerbose(sprintf('Found component %s', $component->name)); Console::outVerbose(sprintf('Found component %s', $component->getName()));
} }
if(count($this->package->components) > 0) if(count($this->package->components) > 0)
@ -216,10 +215,10 @@
} }
$resource = new Package\Resource(); $resource = new Package\Resource();
$resource->Name = Functions::removeBasename($item->getPathname(), $this->path); $resource->setName(Functions::removeBasename($item->getPathname(), $this->path));
$this->package->resources[] = $resource; $this->package->resources[] = $resource;
Console::outVerbose(sprintf('found resource %s', $resource->Name)); Console::outVerbose(sprintf('found resource %s', $resource->getName()));
} }
if(count($this->package->resources) > 0) if(count($this->package->resources) > 0)
@ -238,9 +237,9 @@
$selected_dependencies = []; $selected_dependencies = [];
if(count($this->project->build->getDependencies()) > 0) if(count($this->project_configuration->build->getDependencies()) > 0)
{ {
$selected_dependencies = array_merge($selected_dependencies, $this->project->build->getDependencies()); $selected_dependencies = array_merge($selected_dependencies, $this->project_configuration->build->getDependencies());
} }
if(count($selected_build_configuration->getDependencies()) > 0) if(count($selected_build_configuration->getDependencies()) > 0)
@ -292,7 +291,7 @@
$filesystem->mkdir($lib_path); $filesystem->mkdir($lib_path);
} }
$filesystem->copy($version->Location, $out_path); $filesystem->copy($version->location, $out_path);
$dependency->Source = 'libs' . DIRECTORY_SEPARATOR . sprintf('%s=%s.lib', $dependency->getName(), $dependency->getVersion()); $dependency->Source = 'libs' . DIRECTORY_SEPARATOR . sprintf('%s=%s.lib', $dependency->getName(), $dependency->getVersion());
} }
@ -339,7 +338,7 @@
$this->compileResources(); $this->compileResources();
PackageCompiler::compilePackageConstants($this->package, [ PackageCompiler::compilePackageConstants($this->package, [
ConstantReferences::ASSEMBLY => $this->project->assembly, ConstantReferences::ASSEMBLY => $this->project_configuration->assembly,
ConstantReferences::BUILD => null, ConstantReferences::BUILD => null,
ConstantReferences::DATE_TIME => time() ConstantReferences::DATE_TIME => time()
]); ]);
@ -386,13 +385,12 @@
} }
// Get the data and // Get the data and
$resource->Data = IO::fread(Functions::correctDirectorySeparator($this->path . $resource->Name)); $resource->setData(Base64::encode(IO::fread(Functions::correctDirectorySeparator($this->path . $resource->getName()))));
$resource->Data = Base64::encode($resource->Data); $resource->setName(str_replace($this->project_configuration->build->getSourcePath(), (string)null, $resource->getName()));
$resource->Name = str_replace($this->project->build->getSourcePath(), (string)null, $resource->Name);
$resource->updateChecksum(); $resource->updateChecksum();
$resources[] = $resource; $resources[] = $resource;
Console::outDebug(sprintf('processed resource %s', $resource->Name)); Console::outDebug(sprintf('processed resource %s', $resource->getName()));
} }
// Update the resources // Update the resources
@ -436,7 +434,7 @@
Console::inlineProgressBar($processed_items, $total_items); Console::inlineProgressBar($processed_items, $total_items);
} }
$content = IO::fread(Functions::correctDirectorySeparator($this->path . $component->name)); $content = IO::fread(Functions::correctDirectorySeparator($this->path . $component->getName()));
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
try try
@ -444,24 +442,24 @@
$stmts = $parser->parse($content); $stmts = $parser->parse($content);
$encoded = json_encode($stmts, JSON_THROW_ON_ERROR); $encoded = json_encode($stmts, JSON_THROW_ON_ERROR);
unset($stmts); unset($stmts);
$component->data_types = ComponentDataType::AST; $component->setDataType(ComponentDataType::AST);
$component->data = json_decode($encoded, true, 512, JSON_THROW_ON_ERROR); $component->setData(json_decode($encoded, true, 512, JSON_THROW_ON_ERROR));
} }
catch(Exception $e) catch(Exception $e)
{ {
$component->data_types = ComponentDataType::BASE64_ENCODED; $component->setDataType(ComponentDataType::BASE64_ENCODED);
$component->data = Base64::encode($content); $component->setData(Base64::encode($content));
unset($e); unset($e);
} }
unset($parser); unset($parser);
$component->name = str_replace($this->project->build->getSourcePath(), (string)null, $component->name); $component->setName(str_replace($this->project_configuration->build->getSourcePath(), (string)null, $component->getName()));
$component->updateChecksum(); $component->updateChecksum();
$components[] = $component; $components[] = $component;
++$processed_items; ++$processed_items;
Console::outDebug(sprintf('processed component %s (%s)', $component->name, $component->data_types)); Console::outDebug(sprintf('processed component %s (%s)', $component->getName(), $component->getDataType()));
} }
// Update the components // Update the components
@ -476,7 +474,7 @@
*/ */
public function compileExecutionPolicies(): void public function compileExecutionPolicies(): void
{ {
$this->package->execution_units = PackageCompiler::compileExecutionPolicies($this->path, $this->project); $this->package->execution_units = PackageCompiler::compileExecutionPolicies($this->path, $this->project_configuration);
} }
/** /**

View file

@ -79,38 +79,38 @@
*/ */
public function processComponent(Package\Component $component): ?string public function processComponent(Package\Component $component): ?string
{ {
if($component->data === null) if($component->getData() === null)
{ {
return null; return null;
} }
if(!$component->validate_checksum()) if(!$component->validate_checksum())
{ {
throw new IntegrityException(sprintf('Checksum validation failed for component: %s', $component->name)); throw new IntegrityException(sprintf('Checksum validation failed for component: %s', $component->getName()));
} }
switch($component->data_types) switch($component->getDataType())
{ {
case ComponentDataType::AST: case ComponentDataType::AST:
try try
{ {
$stmts = $this->decodeRecursive($component->data); $stmts = $this->decodeRecursive($component->getData());
} }
catch (Exception $e) catch (Exception $e)
{ {
throw new IntegrityException(sprintf('Cannot decode component: %s, %s', $component->name, $e->getMessage())); throw new IntegrityException(sprintf('Cannot decode component: %s, %s', $component->getName(), $e->getMessage()));
} }
return (new Standard())->prettyPrintFile($stmts); return (new Standard())->prettyPrintFile($stmts);
case ComponentDataType::BASE64_ENCODED: case ComponentDataType::BASE64_ENCODED:
return Base64::decode($component->data); return Base64::decode($component->getData());
case ComponentDataType::PLAIN: case ComponentDataType::PLAIN:
return $component->data; return $component->getData();
default: default:
throw new NotSupportedException(sprintf('Component data type %s is not supported.', $component->data_types)); throw new NotSupportedException(sprintf('Component data type %s is not supported.', $component->getDataType()));
} }
} }
@ -143,10 +143,10 @@
{ {
if(!$resource->validateChecksum()) if(!$resource->validateChecksum())
{ {
throw new IntegrityException('Checksum validation failed for resource ' . $resource->Name . ', the package may be corrupted.'); throw new IntegrityException('Checksum validation failed for resource ' . $resource->getName() . ', the package may be corrupted.');
} }
return Base64::decode($resource->Data); return Base64::decode($resource->getData());
} }
/** /**

View file

@ -46,8 +46,8 @@
throw new PathNotFoundException($path); throw new PathNotFoundException($path);
} }
$execution_unit->execution_policy = $policy; $execution_unit->setExecutionPolicy($policy);
$execution_unit->Data = IO::fread($path); $execution_unit->setData(IO::fread($path));
return $execution_unit; return $execution_unit;
} }

View file

@ -49,8 +49,8 @@
throw new PathNotFoundException($path); throw new PathNotFoundException($path);
} }
$execution_unit->execution_policy = $policy; $execution_unit->setExecutionPolicy($policy);
$execution_unit->Data = IO::fread($path); $execution_unit->setData(IO::fread($path));
return $execution_unit; return $execution_unit;
} }

View file

@ -49,8 +49,8 @@
throw new PathNotFoundException($path); throw new PathNotFoundException($path);
} }
$execution_unit->execution_policy = $policy; $execution_unit->setExecutionPolicy($policy);
$execution_unit->Data = IO::fread($path); $execution_unit->setData(IO::fread($path));
return $execution_unit; return $execution_unit;
} }

View file

@ -49,8 +49,8 @@
throw new PathNotFoundException($path); throw new PathNotFoundException($path);
} }
$execution_unit->execution_policy = $policy; $execution_unit->setExecutionPolicy($policy);
$execution_unit->Data = IO::fread($path); $execution_unit->setData(IO::fread($path));
return $execution_unit; return $execution_unit;
} }

View file

@ -22,7 +22,7 @@
namespace ncc\Interfaces; namespace ncc\Interfaces;
interface BytecodeObjectInterface interface BytecodeObjectInterface extends SerializableObjectInterface
{ {
/** /**
* Returns an array representation of the object * Returns an array representation of the object

View file

@ -0,0 +1,41 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Interfaces;
interface SerializableObjectInterface
{
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array;
/**
* Constructs the object from a SerializableObjectInterface array representation
*
* @param array $data
* @return SerializableObjectInterface
*/
public static function fromArray(array $data): SerializableObjectInterface;
}

View file

@ -174,15 +174,15 @@
{ {
if(Resolver::resolveScope() !== Scopes::SYSTEM) if(Resolver::resolveScope() !== Scopes::SYSTEM)
{ {
throw new AuthenticationException('Cannot add new ExecutionUnit \'' . $unit->execution_policy->getName() .'\' for ' . $package . ', insufficient permissions'); throw new AuthenticationException('Cannot add new ExecutionUnit \'' . $unit->getExecutionPolicy()->getName() .'\' for ' . $package . ', insufficient permissions');
} }
Console::outVerbose(sprintf('Adding new ExecutionUnit \'%s\' for %s', $unit->execution_policy->getName(), $package)); Console::outVerbose(sprintf('Adding new ExecutionUnit \'%s\' for %s', $unit->getExecutionPolicy()->getName(), $package));
$package_id = $this->getPackageId($package, $version); $package_id = $this->getPackageId($package, $version);
$package_config_path = $this->runner_path . DIRECTORY_SEPARATOR . $package_id . '.inx'; $package_config_path = $this->runner_path . DIRECTORY_SEPARATOR . $package_id . '.inx';
$package_bin_path = $this->runner_path . DIRECTORY_SEPARATOR . $package_id; $package_bin_path = $this->runner_path . DIRECTORY_SEPARATOR . $package_id;
$entry_point_path = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->execution_policy->getName()) . '.entrypoint'; $entry_point_path = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->getExecutionPolicy()->getName()) . '.entrypoint';
Console::outDebug(sprintf('package_id=%s', $package_id)); Console::outDebug(sprintf('package_id=%s', $package_id));
Console::outDebug(sprintf('package_config_path=%s', $package_config_path)); 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))); $execution_pointers = ExecutionPointers::fromArray(ZiProto::decode(IO::fread($package_config_path)));
} }
$bin_file = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->execution_policy->getName()); $bin_file = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->getExecutionPolicy()->getName());
$bin_file .= match ($unit->execution_policy->getRunner()) $bin_file .= match ($unit->getExecutionPolicy()->getRunner())
{ {
Runners::BASH => BashRunner::getFileExtension(), Runners::BASH => BashRunner::getFileExtension(),
Runners::PHP => PhpRunner::getFileExtension(), Runners::PHP => PhpRunner::getFileExtension(),
@ -211,7 +211,7 @@
Runners::PYTHON_2 => Python2Runner::getFileExtension(), Runners::PYTHON_2 => Python2Runner::getFileExtension(),
Runners::PYTHON_3 => Python3Runner::getFileExtension(), Runners::PYTHON_3 => Python3Runner::getFileExtension(),
Runners::LUA => LuaRunner::getFileExtension(), Runners::LUA => LuaRunner::getFileExtension(),
default => throw new NotSupportedException('The runner \'' . $unit->execution_policy->getRunner() . '\' is not supported'), default => throw new NotSupportedException('The runner \'' . $unit->getExecutionPolicy()->getRunner() . '\' is not supported'),
}; };
Console::outDebug(sprintf('bin_file=%s', $bin_file)); Console::outDebug(sprintf('bin_file=%s', $bin_file));
@ -231,13 +231,13 @@
$filesystem->remove($bin_file); $filesystem->remove($bin_file);
} }
IO::fwrite($bin_file, $unit->Data); IO::fwrite($bin_file, $unit->getData());
$execution_pointers->addUnit($unit, $bin_file); $execution_pointers->addUnit($unit, $bin_file);
IO::fwrite($package_config_path, ZiProto::encode($execution_pointers->toArray(true))); IO::fwrite($package_config_path, ZiProto::encode($execution_pointers->toArray(true)));
$entry_point = sprintf("#!%s\nncc exec --package=\"%s\" --exec-version=\"%s\" --exec-unit=\"%s\" --exec-args \"$@\"", $entry_point = sprintf("#!%s\nncc exec --package=\"%s\" --exec-version=\"%s\" --exec-unit=\"%s\" --exec-args \"$@\"",
'/bin/bash', '/bin/bash',
$package, $version, $unit->execution_policy->getName() $package, $version, $unit->getExecutionPolicy()->getName()
); );
if(file_exists($entry_point_path)) if(file_exists($entry_point_path))
@ -250,11 +250,11 @@
if($temporary) if($temporary)
{ {
Console::outVerbose(sprintf('Adding temporary ExecutionUnit \'%s\' for %s', $unit->execution_policy->getName(), $package)); Console::outVerbose(sprintf('Adding temporary ExecutionUnit \'%s\' for %s', $unit->getExecutionPolicy()->getName(), $package));
$this->temporary_units[] = [ $this->temporary_units[] = [
'package' => $package, 'package' => $package,
'version' => $version, 'version' => $version,
'unit' => $unit->execution_policy->getName() 'unit' => $unit->getExecutionPolicy()->getName()
]; ];
} }
} }
@ -314,9 +314,9 @@
} }
// Delete the single execution pointer file // Delete the single execution pointer file
if($filesystem->exists($unit->file_pointer)) if($filesystem->exists($unit->getFilePointer()))
{ {
$filesystem->remove($unit->file_pointer); $filesystem->remove($unit->getFilePointer());
} }
return $results; return $results;
@ -351,8 +351,8 @@
$results = []; $results = [];
foreach($execution_pointers->getPointers() as $pointer) foreach($execution_pointers->getPointers() as $pointer)
{ {
Console::outDebug(sprintf('unit %s', $pointer->execution_policy->getName())); Console::outDebug(sprintf('unit %s', $pointer->getExecutionPolicy()->getName()));
$results[] = $pointer->execution_policy->getName(); $results[] = $pointer->getExecutionPolicy()->getName();
} }
return $results; return $results;
@ -390,32 +390,32 @@
throw new OperationException('The execution unit \'' . $name . '\' was not found for \'' . $package . '=' .$version .'\''); throw new OperationException('The execution unit \'' . $name . '\' was not found for \'' . $package . '=' .$version .'\'');
} }
Console::outDebug(sprintf('unit=%s', $unit->execution_policy->getName())); Console::outDebug(sprintf('unit=%s', $unit->getExecutionPolicy()->getName()));
Console::outDebug(sprintf('runner=%s', $unit->execution_policy->getRunner())); Console::outDebug(sprintf('runner=%s', $unit->getExecutionPolicy()->getRunner()));
Console::outDebug(sprintf('file=%s', $unit->file_pointer)); Console::outDebug(sprintf('file=%s', $unit->getFilePointer()));
Console::outDebug(sprintf('pass_thru_args=%s', implode(' ', $args))); Console::outDebug(sprintf('pass_thru_args=%s', implode(' ', $args)));
// Handle the arguments // Handle the arguments
if(count($unit->execution_policy->getExecute()->getOptions()) > 0) if(count($unit->getExecutionPolicy()->getExecute()->getOptions()) > 0)
{ {
$args = array_merge($args, $unit->execution_policy->getExecute()->getOptions()); $args = array_merge($args, $unit->getExecutionPolicy()->getExecute()->getOptions());
foreach($unit->execution_policy->getExecute()->getOptions() as $option) foreach($unit->getExecutionPolicy()->getExecute()->getOptions() as $option)
{ {
$args[] = ConstantCompiler::compileRuntimeConstants($option); $args[] = ConstantCompiler::compileRuntimeConstants($option);
} }
} }
$process = new Process(array_merge( $process = new Process(array_merge(
[PathFinder::findRunner(strtolower($unit->execution_policy->getRunner())), $unit->file_pointer], $args) [PathFinder::findRunner(strtolower($unit->getExecutionPolicy()->getRunner())), $unit->getFilePointer()], $args)
); );
$process->setWorkingDirectory(ConstantCompiler::compileRuntimeConstants($unit->execution_policy->getExecute()->getWorkingDirectory())); $process->setWorkingDirectory(ConstantCompiler::compileRuntimeConstants($unit->getExecutionPolicy()->getExecute()->getWorkingDirectory()));
if(is_null($unit->execution_policy->getExecute()->getTimeout())) if(is_null($unit->getExecutionPolicy()->getExecute()->getTimeout()))
{ {
$process->setTimeout((float)$unit->execution_policy->getExecute()->getTimeout()); $process->setTimeout((float)$unit->getExecutionPolicy()->getExecute()->getTimeout());
} }
else else
{ {
@ -425,12 +425,12 @@
try try
{ {
if($unit->execution_policy->getExecute()->isSilent()) if($unit->getExecutionPolicy()->getExecute()->isSilent())
{ {
$process->disableOutput(); $process->disableOutput();
$process->setTty(false); $process->setTty(false);
} }
elseif($unit->execution_policy->getExecute()->isTty()) elseif($unit->getExecutionPolicy()->getExecute()->isTty())
{ {
$process->enableOutput(); $process->enableOutput();
$process->setTty(true); $process->setTty(true);
@ -457,16 +457,16 @@
Console::outDebug(sprintf('working_directory=%s', $process->getWorkingDirectory())); Console::outDebug(sprintf('working_directory=%s', $process->getWorkingDirectory()));
Console::outDebug(sprintf('timeout=%s', (int)$process->getTimeout())); Console::outDebug(sprintf('timeout=%s', (int)$process->getTimeout()));
Console::outDebug(sprintf('silent=%s', ($unit->execution_policy->getExecute()->isSilent() ? 'true' : 'false'))); Console::outDebug(sprintf('silent=%s', ($unit->getExecutionPolicy()->getExecute()->isSilent() ? 'true' : 'false')));
Console::outDebug(sprintf('tty=%s', ($unit->execution_policy->getExecute()->isTty() ? 'true' : 'false'))); Console::outDebug(sprintf('tty=%s', ($unit->getExecutionPolicy()->getExecute()->isTty() ? 'true' : 'false')));
Console::outDebug(sprintf('options=%s', implode(' ', $args))); Console::outDebug(sprintf('options=%s', implode(' ', $args)));
Console::outDebug(sprintf('cmd=%s', $process->getCommandLine())); Console::outDebug(sprintf('cmd=%s', $process->getCommandLine()));
try try
{ {
if($unit->execution_policy->getMessage() !== null) if($unit->getExecutionPolicy()->getMessage() !== null)
{ {
Console::out($unit->execution_policy->getMessage()); Console::out($unit->getExecutionPolicy()->getMessage());
} }
$process->run(function ($type, $buffer) $process->run(function ($type, $buffer)
@ -478,33 +478,33 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
if($unit->execution_policy->getExitHandlers() !== null && $unit->execution_policy->getExitHandlers()->getError() !== null) if($unit->getExecutionPolicy()->getExitHandlers()?->getError() !== null)
{ {
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getError()); $this->handleExit($package, $version, $unit->getExecutionPolicy()?->getExitHandlers()?->getError());
} }
Console::outException(sprintf('An error occurred while executing the unit \'%s\' for \'%s\' (exit code %s)', $unit->execution_policy->getName(), $package, $process->getExitCode()), $e); Console::outException(sprintf('An error occurred while executing the unit \'%s\' for \'%s\' (exit code %s)', $unit->getExecutionPolicy()->getName(), $package, $process->getExitCode()), $e);
} }
finally finally
{ {
Console::outDebug(sprintf('exit_code=%s', $process->getExitCode())); Console::outDebug(sprintf('exit_code=%s', $process->getExitCode()));
} }
if($unit->execution_policy->getExitHandlers() !== null) if($unit->getExecutionPolicy()->getExitHandlers() !== null)
{ {
if($unit->execution_policy->getExitHandlers()->getSuccess() !== null && $process->isSuccessful()) if($unit->getExecutionPolicy()->getExitHandlers()->getSuccess() !== null && $process->isSuccessful())
{ {
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getSuccess()); $this->handleExit($package, $version, $unit->getExecutionPolicy()->getExitHandlers()->getSuccess());
} }
elseif($unit->execution_policy->getExitHandlers()->getError() !== null && $process->isSuccessful()) elseif($unit->getExecutionPolicy()->getExitHandlers()->getError() !== null && $process->isSuccessful())
{ {
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getError()); $this->handleExit($package, $version, $unit->getExecutionPolicy()->getExitHandlers()->getError());
} }
else else
{ {
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getSuccess(), $process); $this->handleExit($package, $version, $unit->getExecutionPolicy()->getExitHandlers()->getSuccess(), $process);
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getWarning(), $process); $this->handleExit($package, $version, $unit->getExecutionPolicy()->getExitHandlers()->getWarning(), $process);
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getError(), $process); $this->handleExit($package, $version, $unit->executigetExecutionPolicy()on_policy->getExitHandlers()->getError(), $process);
} }
} }
@ -535,21 +535,21 @@
// Get the required units // Get the required units
$required_units = []; $required_units = [];
if($unit->execution_policy->getExitHandlers() !== null) if($unit->getExecutionPolicy()->getExitHandlers() !== null)
{ {
$required_unit = $unit->execution_policy?->getExitHandlers()?->getSuccess()?->getRun(); $required_unit = $unit->getExecutionPolicy()?->getExitHandlers()?->getSuccess()?->getRun();
if($required_unit !== null) if($required_unit !== null)
{ {
$required_units[] = $required_unit; $required_units[] = $required_unit;
} }
$required_unit = $unit->execution_policy?->getExitHandlers()?->getWarning()?->getRun(); $required_unit = $unit->getExecutionPolicy()?->getExitHandlers()?->getWarning()?->getRun();
if($required_unit !== null) if($required_unit !== null)
{ {
$required_units[] = $required_unit; $required_units[] = $required_unit;
} }
$required_unit = $unit->execution_policy?->getExitHandlers()?->getError()?->getRun(); $required_unit = $unit->getExecutionPolicy()?->getExitHandlers()?->getError()?->getRun();
if($required_unit !== null) if($required_unit !== null)
{ {
$required_units = $required_unit; $required_units = $required_unit;

View file

@ -124,7 +124,7 @@
return $package->assembly->getPackage(); return $package->assembly->getPackage();
} }
$extension = $package->header->CompilerExtension->getExtension(); $extension = $package->header->getCompilerExtension()->getExtension();
$installation_paths = new InstallationPaths($this->packages_path . DIRECTORY_SEPARATOR . $package->assembly->getPackage() . '=' . $package->assembly->getVersion()); $installation_paths = new InstallationPaths($this->packages_path . DIRECTORY_SEPARATOR . $package->assembly->getPackage() . '=' . $package->assembly->getVersion());
$installer = match ($extension) $installer = match ($extension)
@ -191,7 +191,7 @@
Console::outDebug(sprintf('assembly.%s: %s', $prop, ($value ?? 'n/a'))); Console::outDebug(sprintf('assembly.%s: %s', $prop, ($value ?? 'n/a')));
} }
foreach($package->header->CompilerExtension->toArray() as $prop => $value) foreach($package->header->getCompilerExtension()->toArray() as $prop => $value)
{ {
Console::outDebug(sprintf('header.compiler.%s: %s', $prop, ($value ?? 'n/a'))); Console::outDebug(sprintf('header.compiler.%s: %s', $prop, ($value ?? 'n/a')));
} }
@ -203,14 +203,14 @@
$steps = (4 + count($package->components) + count ($package->resources) + count ($package->execution_units)); $steps = (4 + count($package->components) + count ($package->resources) + count ($package->execution_units));
// Include the Execution units // Include the Execution units
if($package->installer?->PreInstall !== null) if($package->installer?->getPreInstall() !== null)
{ {
$steps += count($package->installer->PreInstall); $steps += count($package->installer->getPreInstall());
} }
if($package->installer?->PostInstall!== null) if($package->installer?->getPostInstall()!== null)
{ {
$steps += count($package->installer->PostInstall); $steps += count($package->installer->getPostInstall());
} }
$current_steps = 0; $current_steps = 0;
@ -258,9 +258,9 @@
throw new OperationException('Pre installation stage failed, ' . $e->getMessage(), $e); throw new OperationException('Pre installation stage failed, ' . $e->getMessage(), $e);
} }
if($package->installer?->PreInstall !== null && count($package->installer->PreInstall) > 0) if($package->installer?->getPreInstall() !== null && count($package->installer->getPreInstall()) > 0)
{ {
foreach($package->installer->PreInstall as $unit_name) foreach($package->installer->getPreInstall() as $unit_name)
{ {
try try
{ {
@ -279,14 +279,14 @@
// Process & Install the components // Process & Install the components
foreach($package->components as $component) foreach($package->components as $component)
{ {
Console::outDebug(sprintf('processing component %s (%s)', $component->name, $component->data_types)); Console::outDebug(sprintf('processing component %s (%s)', $component->getName(), $component->getDataType()));
try try
{ {
$data = $installer->processComponent($component); $data = $installer->processComponent($component);
if($data !== null) if($data !== null)
{ {
$component_path = $installation_paths->getSourcePath() . DIRECTORY_SEPARATOR . $component->name; $component_path = $installation_paths->getSourcePath() . DIRECTORY_SEPARATOR . $component->getName();
$component_dir = dirname($component_path); $component_dir = dirname($component_path);
if(!$filesystem->exists($component_dir)) if(!$filesystem->exists($component_dir))
@ -309,14 +309,14 @@
// Process & Install the resources // Process & Install the resources
foreach($package->resources as $resource) foreach($package->resources as $resource)
{ {
Console::outDebug(sprintf('processing resource %s', $resource->Name)); Console::outDebug(sprintf('processing resource %s', $resource->getName()));
try try
{ {
$data = $installer->processResource($resource); $data = $installer->processResource($resource);
if($data !== null) if($data !== null)
{ {
$resource_path = $installation_paths->getSourcePath() . DIRECTORY_SEPARATOR . $resource->Name; $resource_path = $installation_paths->getSourcePath() . DIRECTORY_SEPARATOR . $resource->getName();
$resource_dir = dirname($resource_path); $resource_dir = dirname($resource_path);
if(!$filesystem->exists($resource_dir)) if(!$filesystem->exists($resource_dir))
@ -347,7 +347,7 @@
/** @var Package\ExecutionUnit $executionUnit */ /** @var Package\ExecutionUnit $executionUnit */
foreach($package->execution_units as $executionUnit) foreach($package->execution_units as $executionUnit)
{ {
Console::outDebug(sprintf('processing execution unit %s', $executionUnit->execution_policy->getName())); Console::outDebug(sprintf('processing execution unit %s', $executionUnit->getExecutionPolicy()->getName()));
$execution_pointer_manager->addUnit($package->assembly->getPackage(), $package->assembly->getVersion(), $executionUnit); $execution_pointer_manager->addUnit($package->assembly->getPackage(), $package->assembly->getVersion(), $executionUnit);
++$current_steps; ++$current_steps;
Console::inlineProgressBar($current_steps, $steps); Console::inlineProgressBar($current_steps, $steps);
@ -361,7 +361,7 @@
} }
// After execution units are installed, create a symlink if needed // After execution units are installed, create a symlink if needed
if(isset($package->header->Options['create_symlink']) && $package->header->Options['create_symlink']) if(!is_null($package->header->getOption('create_symlink')) && $package->header->getOption('create_symlink'))
{ {
if($package->main_execution_policy === null) if($package->main_execution_policy === null)
{ {
@ -389,11 +389,11 @@
throw new OperationException('Post installation stage failed, ' . $e->getMessage(), $e); throw new OperationException('Post installation stage failed, ' . $e->getMessage(), $e);
} }
if($package->installer?->PostInstall !== null && count($package->installer->PostInstall) > 0) if($package->installer?->getPostInstall() !== null && count($package->installer->getPostInstall()) > 0)
{ {
Console::outDebug('executing post-installation units'); Console::outDebug('executing post-installation units');
foreach($package->installer->PostInstall as $unit_name) foreach($package->installer->getPostInstall() as $unit_name)
{ {
try try
{ {
@ -415,18 +415,18 @@
Console::outDebug('no post-installation units to execute'); Console::outDebug('no post-installation units to execute');
} }
if($package->header->UpdateSource !== null && $package->header->UpdateSource->getRepository() !== null) if($package->header->getUpdateSource()?->getRepository() !== null)
{ {
$sources_manager = new RemoteSourcesManager(); $sources_manager = new RemoteSourcesManager();
if($sources_manager->getRemoteSource($package->header->UpdateSource->getRepository()->getName()) === null) if($sources_manager->getRemoteSource($package->header->getUpdateSource()->getRepository()->getName()) === null)
{ {
Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->getRepository()->getName()); Console::outVerbose('Adding remote source ' . $package->header->getUpdateSource()->getRepository()->getName());
$defined_remote_source = new DefinedRemoteSource(); $defined_remote_source = new DefinedRemoteSource();
$defined_remote_source->name = $package->header->UpdateSource->getRepository()->getName(); $defined_remote_source->name = $package->header->getUpdateSource()?->getRepository()->getName();
$defined_remote_source->host = $package->header->UpdateSource->getRepository()->getHost(); $defined_remote_source->host = $package->header->getUpdateSource()?->getRepository()->getHost();
$defined_remote_source->type = $package->header->UpdateSource->getRepository()->getType(); $defined_remote_source->type = $package->header->getUpdateSource()?->getRepository()->getType();
$defined_remote_source->ssl = $package->header->UpdateSource->getRepository()->isSsl(); $defined_remote_source->ssl = $package->header->getUpdateSource()?->getRepository()->isSsl();
$sources_manager->addRemoteSource($defined_remote_source); $sources_manager->addRemoteSource($defined_remote_source);
} }
@ -790,11 +790,11 @@
throw new OperationException('Version ' . $exploded[1] . ' not found for package ' . $exploded[0]); throw new OperationException('Version ' . $exploded[1] . ' not found for package ' . $exploded[0]);
} }
foreach ($version->Dependencies as $dependency) foreach ($version->getDependencies() as $dependency)
{ {
if(!in_array($dependency->PackageName . '=' . $dependency->Version, $tree, true)) if(!in_array($dependency->getPackageName() . '=' . $dependency->getVersion(), $tree, true))
{ {
$packages[] = $dependency->PackageName . '=' . $dependency->Version; $packages[] = $dependency->getPackageName() . '=' . $dependency->getVersion();
} }
} }
} }
@ -840,12 +840,12 @@
else else
{ {
$tree[$package_iter] = null; $tree[$package_iter] = null;
if($version_entry->Dependencies !== null && count($version_entry->Dependencies) > 0) if(count($version_entry->getDependencies()) > 0)
{ {
$tree[$package_iter] = []; $tree[$package_iter] = [];
foreach($version_entry->Dependencies as $dependency) foreach($version_entry->getDependencies() as $dependency)
{ {
$dependency_name = sprintf('%s=%s', $dependency->PackageName, $dependency->Version); $dependency_name = sprintf('%s=%s', $dependency->getPackageName(), $dependency->getVersion());
$tree[$package_iter] = $this->getPackageTree($tree[$package_iter], $dependency_name); $tree[$package_iter] = $this->getPackageTree($tree[$package_iter], $dependency_name);
} }
} }
@ -898,13 +898,13 @@
$scanner = new DirectoryScanner(); $scanner = new DirectoryScanner();
$filesystem = new Filesystem(); $filesystem = new Filesystem();
if($filesystem->exists($version_entry->Location)) if($filesystem->exists($version_entry->location))
{ {
Console::outVerbose(sprintf('Removing package files from %s', $version_entry->Location)); Console::outVerbose(sprintf('Removing package files from %s', $version_entry->location));
/** @var SplFileInfo $item */ /** @var SplFileInfo $item */
/** @noinspection PhpRedundantOptionalArgumentInspection */ /** @noinspection PhpRedundantOptionalArgumentInspection */
foreach($scanner($version_entry->Location, true) as $item) foreach($scanner($version_entry->location, true) as $item)
{ {
if(is_file($item->getPath())) if(is_file($item->getPath()))
{ {
@ -916,21 +916,21 @@
} }
else else
{ {
Console::outWarning(sprintf('warning: package location %s does not exist', $version_entry->Location)); Console::outWarning(sprintf('warning: package location %s does not exist', $version_entry->location));
} }
$filesystem->remove($version_entry->Location); $filesystem->remove($version_entry->location);
if($version_entry->ExecutionUnits !== null && count($version_entry->ExecutionUnits) > 0) if(count($version_entry->getExecutionUnits()) > 0)
{ {
Console::outVerbose('Uninstalling execution units'); Console::outVerbose('Uninstalling execution units');
$execution_pointer_manager = new ExecutionPointerManager(); $execution_pointer_manager = new ExecutionPointerManager();
foreach($version_entry->ExecutionUnits as $executionUnit) foreach($version_entry->getExecutionUnits() as $executionUnit)
{ {
if(!$execution_pointer_manager->removeUnit($package, $version, $executionUnit->execution_policy->getName())) if(!$execution_pointer_manager->removeUnit($package, $version, $executionUnit->getExecutionPolicy()->getName()))
{ {
Console::outDebug(sprintf('warning: removing execution unit %s failed', $executionUnit->execution_policy->getName())); Console::outDebug(sprintf('warning: removing execution unit %s failed', $executionUnit->getExecutionPolicy()->getName()));
} }
} }
} }
@ -973,11 +973,11 @@
try try
{ {
$this->uninstallPackageVersion($package, $version_entry->Version); $this->uninstallPackageVersion($package, $version_entry->getVersion());
} }
catch(Exception $e) catch(Exception $e)
{ {
Console::outDebug(sprintf('warning: unable to uninstall package %s=%s, %s (%s)', $package, $version_entry->Version, $e->getMessage(), $e->getCode())); Console::outDebug(sprintf('warning: unable to uninstall package %s=%s, %s (%s)', $package, $version_entry->getVersion(), $e->getMessage(), $e->getCode()));
} }
} }
} }
@ -999,14 +999,10 @@
} }
$data_files = [ $data_files = [
$paths->getDataPath() . DIRECTORY_SEPARATOR . 'assembly' => $paths->getDataPath() . DIRECTORY_SEPARATOR . 'assembly' => ZiProto::encode($package->assembly->toArray(true)),
ZiProto::encode($package->assembly->toArray(true)), $paths->getDataPath() . DIRECTORY_SEPARATOR . 'ext' => ZiProto::encode($package->header->getCompilerExtension()->toArray()),
$paths->getDataPath() . DIRECTORY_SEPARATOR . 'ext' => $paths->getDataPath() . DIRECTORY_SEPARATOR . 'const' => ZiProto::encode($package->header->getRuntimeConstants()),
ZiProto::encode($package->header->CompilerExtension->toArray()), $paths->getDataPath() . DIRECTORY_SEPARATOR . 'dependencies' => ZiProto::encode($dependencies),
$paths->getDataPath() . DIRECTORY_SEPARATOR . 'const' =>
ZiProto::encode($package->header->RuntimeConstants),
$paths->getDataPath() . DIRECTORY_SEPARATOR . 'dependencies' =>
ZiProto::encode($dependencies),
]; ];
foreach($data_files as $file => $data) foreach($data_files as $file => $data)

View file

@ -315,7 +315,7 @@
$_require = []; $_require = [];
foreach($this->require as $require) foreach($this->require as $require)
{ {
$_require[$require->package_name] = $require->version; $_require[$require->getPackageName()] = $require->getVersion();
} }
} }
@ -325,7 +325,7 @@
$_require_dev = []; $_require_dev = [];
foreach($this->require_dev as $require) foreach($this->require_dev as $require)
{ {
$_require_dev[$require->package_name] = $require->version; $_require_dev[$require->getPackageName()] = $require->getVersion();
} }
} }
@ -335,7 +335,7 @@
$_conflict = []; $_conflict = [];
foreach($this->conflict as $require) foreach($this->conflict as $require)
{ {
$_conflict[$require->package_name] = $require->version; $_conflict[$require->getPackageName()] = $require->getVersion();
} }
} }
@ -345,7 +345,7 @@
$_replace = []; $_replace = [];
foreach($this->replace as $require) foreach($this->replace as $require)
{ {
$_replace[$require->package_name] = $require->version; $_replace[$require->getPackageName()] = $require->getVersion();
} }
} }
@ -355,7 +355,7 @@
$_provide = []; $_provide = [];
foreach($this->provide as $require) foreach($this->provide as $require)
{ {
$_provide[$require->package_name] = $require->version; $_provide[$require->getPackageName()] = $require->getVersion();
} }
} }
@ -365,7 +365,7 @@
$_suggest = []; $_suggest = [];
foreach($this->suggest as $suggestion) foreach($this->suggest as $suggestion)
{ {
$_suggest[$suggestion->package_name] = $suggestion->comment; $_suggest[$suggestion->getPackageName()] = $suggestion->getComment();
} }
} }

View file

@ -1,95 +1,132 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * Copyright (c) Nosial 2022-2023, all rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without * associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\ComposerJson; namespace ncc\Objects\ComposerJson;
class Author use ncc\Interfaces\SerializableObjectInterface;
class Author implements SerializableObjectInterface
{ {
/** /**
* The author's name. Usually their real name * The author's name. Usually their real name
* *
* @var string|null * @var string|null
*/ */
public $Name; private $name;
/** /**
* The author's email address * The author's email address
* *
* @var string|null * @var string|null
*/ */
public $Email; private $email;
/** /**
* URL to the author's website * URL to the author's website
* *
* @var string|null * @var string|null
*/ */
public $Homepage; private $homepage;
/** /**
* The author's role in the project (eg. developer or translator) * The author's role in the project (eg. developer or translator)
* *
* @var string|null * @var string|null
*/ */
public $Role; private $role;
/** /**
* Returns an array representation of the object * @return string|null
* */
* @return array public function getName(): ?string
{
return $this->name;
}
/**
* @return string|null
*/
public function getEmail(): ?string
{
return $this->email;
}
/**
* @return string|null
*/
public function getHomepage(): ?string
{
return $this->homepage;
}
/**
* @return string|null
*/
public function getRole(): ?string
{
return $this->role;
}
/**
* @inheritDoc
*/ */
public function toArray(): array public function toArray(): array
{ {
return [ return [
'name' => $this->Name, 'name' => $this->name,
'email' => $this->Email, 'email' => $this->email,
'homepage' => $this->Homepage, 'homepage' => $this->homepage,
'role' => $this->Role 'role' => $this->role
]; ];
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return Author
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): Author
{ {
$object = new self(); $object = new self();
if(isset($data['name'])) if(isset($data['name']))
$object->Name = $data['name']; {
$object->name = $data['name'];
}
if(isset($data['email'])) if(isset($data['email']))
$object->Email = $data['email']; {
$object->email = $data['email'];
}
if(isset($data['homepage'])) if(isset($data['homepage']))
$object->Homepage = $data['homepage']; {
$object->homepage = $data['homepage'];
}
if(isset($data['role'])) if(isset($data['role']))
$object->Role = $data['role']; {
$object->role = $data['role'];
}
return $object; return $object;
} }

View file

@ -1,56 +1,98 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * Copyright (c) Nosial 2022-2023, all rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without * associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\ComposerJson; namespace ncc\Objects\ComposerJson;
class Autoloader use ncc\Interfaces\SerializableObjectInterface;
class Autoloader implements SerializableObjectInterface
{ {
/** /**
* @var NamespacePointer[]|null * @var NamespacePointer[]|null
*/ */
public $psr_4; private $psr_4;
/** /**
* @var NamespacePointer[]|null * @var NamespacePointer[]|null
*/ */
public $psr_0; private $psr_0;
/** /**
* @var string[]|null * @var string[]|null
*/ */
public $class_map; private $class_map;
/** /**
* @var string[]|null * @var string[]|null
*/ */
public $files; private $files;
/** /**
* @var string[]|null * @var string[]|null
*/ */
public $exclude_from_class_map; private $exclude_from_class_map;
/**
* @return NamespacePointer[]|null
*/
public function getPsr4(): ?array
{
return $this->psr_4;
}
/**
* @return NamespacePointer[]|null
*/
public function getPsr0(): ?array
{
return $this->psr_0;
}
/**
* @return string[]|null
*/
public function getClassMap(): ?array
{
return $this->class_map;
}
/**
* @return string[]|null
*/
public function getFiles(): ?array
{
return $this->files;
}
/**
* @return string[]|null
*/
public function getExcludeFromClassMap(): ?array
{
return $this->exclude_from_class_map;
}
/** /**
* @param array $psr * @param array $psr
@ -60,33 +102,31 @@
*/ */
private static function psrRestructure(array $psr, NamespacePointer $pointer): array private static function psrRestructure(array $psr, NamespacePointer $pointer): array
{ {
if (isset($psr[(string)$pointer->Namespace])) if (isset($psr[(string)$pointer->getNamespace()]))
{ {
if (!is_array($psr[(string)$pointer->Namespace])) if (!is_array($psr[(string)$pointer->getNamespace()]))
{ {
$r = [ $r = [
$psr[(string)$pointer->Namespace], $psr[(string)$pointer->getNamespace()],
$pointer->Path $pointer->getPath()
]; ];
$psr[(string)$pointer->Namespace] = $r; $psr[(string)$pointer->getNamespace()] = $r;
} }
elseif (!in_array($pointer->Path, $psr[(string)$pointer->Namespace], true)) elseif (!in_array($pointer->getPath(), $psr[(string)$pointer->getNamespace()], true))
{ {
$psr[(string)$pointer->Namespace][] = $pointer->Path; $psr[(string)$pointer->getNamespace()][] = $pointer->getPath();
} }
} }
else else
{ {
$psr[(string)$pointer->Namespace] = $pointer->Path; $psr[(string)$pointer->getNamespace()] = $pointer->getPath();
} }
return $psr; return $psr;
} }
/** /**
* Returns an array representation of the object * @inheritDoc
*
* @return array
*/ */
public function toArray(): array public function toArray(): array
{ {
@ -116,10 +156,9 @@
} }
/** /**
* @param array $data * @inheritDoc
* @return static
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): Autoloader
{ {
$object = new self(); $object = new self();

View file

@ -1,28 +1,33 @@
<?php <?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects\ComposerJson; /** @noinspection PhpMissingFieldTypeInspection */
class Funding /*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects\ComposerJson;
use ncc\Interfaces\SerializableObjectInterface;
class Funding implements SerializableObjectInterface
{ {
/** /**
* The type of funding, or the platform through which * The type of funding, or the platform through which
@ -31,7 +36,7 @@ namespace ncc\Objects\ComposerJson;
* *
* @var string|null * @var string|null
*/ */
public $Type; private $type;
/** /**
* URL to a website with details, and a way to fund * URL to a website with details, and a way to fund
@ -39,36 +44,51 @@ namespace ncc\Objects\ComposerJson;
* *
* @var string|null * @var string|null
*/ */
public $URL; private $url;
/** /**
* Returns an array representation of the object * @return string|null
* */
* @return array public function getType(): ?string
{
return $this->type;
}
/**
* @return string|null
*/
public function getUrl(): ?string
{
return $this->url;
}
/**
* @inheritDoc
*/ */
public function toArray(): array public function toArray(): array
{ {
return [ return [
'type' => $this->Type, 'type' => $this->type,
'url' => $this->URL 'url' => $this->url
]; ];
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return static
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): Funding
{ {
$object = new self(); $object = new self();
if(isset($data['type'])) if(isset($data['type']))
$object->Type = $data['type']; {
$object->type = $data['type'];
}
if(isset($data['url'])) if(isset($data['url']))
$object->URL = $data['url']; {
$object->url = $data['url'];
}
return $object; return $object;
} }

View file

@ -1,42 +1,63 @@
<?php <?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects\ComposerJson; /** @noinspection PhpMissingFieldTypeInspection */
class NamespacePointer /*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects\ComposerJson;
use ncc\Interfaces\SerializableObjectInterface;
class NamespacePointer implements SerializableObjectInterface
{ {
/** /**
* Namespace name that maps to the path route * Namespace name that maps to the path route
* *
* @var string|null * @var string|null
*/ */
public $Namespace; private $namespace;
/** /**
* The relative path to the source code to index * The relative path to the source code to index
* *
* @var string * @var string
*/ */
public $Path; private $path;
/**
* @return string|null
*/
public function getNamespace(): ?string
{
return $this->namespace;
}
/**
* @return string|null
*/
public function getPath(): ?string
{
return $this->path;
}
/** /**
* Public constructor * Public constructor
@ -46,38 +67,37 @@ namespace ncc\Objects\ComposerJson;
*/ */
public function __construct(?string $name=null, ?string $path=null) public function __construct(?string $name=null, ?string $path=null)
{ {
$this->Namespace = $name; $this->namespace = $name;
$this->Path = $path; $this->path = $path;
} }
/** /**
* Returns an array representation of the object * @inheritDoc
*
* @return array
*/ */
public function toArray(): array public function toArray(): array
{ {
return [ return [
'namespace' => $this->Namespace, 'namespace' => $this->namespace,
'path' => $this->Path 'path' => $this->path
]; ];
} }
/** /**
* Constructs the object from an array representation * @inheritDoc
*
* @param array $array
* @return static
*/ */
public static function fromArray(array $array): self public static function fromArray(array $array): NamespacePointer
{ {
$object = new self(); $object = new self();
if(isset($array['namespace'])) if(isset($array['namespace']))
$object->Namespace = $array['namespace']; {
$object->namespace = $array['namespace'];
}
if(isset($array['path'])) if(isset($array['path']))
$object->Path = $array['path']; {
$object->path = $array['path'];
}
return $object; return $object;
} }

View file

@ -25,21 +25,23 @@
namespace ncc\Objects\ComposerJson; namespace ncc\Objects\ComposerJson;
class PackageLink use ncc\Interfaces\SerializableObjectInterface;
class PackageLink implements SerializableObjectInterface
{ {
/** /**
* The name of the package that is required * The name of the package that is required
* *
* @var string|null * @var string|null
*/ */
public $package_name; private $package_name;
/** /**
* The version of the package that is required * The version of the package that is required
* *
* @var string|null * @var string|null
*/ */
public $version; private $version;
/** /**
* @param string|null $package_name * @param string|null $package_name
@ -52,9 +54,23 @@
} }
/** /**
* Returns an array representation of object * @return string|null
* */
* @return array public function getPackageName(): ?string
{
return $this->package_name;
}
/**
* @return string|null
*/
public function getVersion(): ?string
{
return $this->version;
}
/**
* @inheritDoc
*/ */
public function toArray(): array public function toArray(): array
{ {
@ -65,10 +81,7 @@
} }
/** /**
* Constructs an object from an array representation * @inheritDoc
*
* @param array $data
* @return PackageLink
*/ */
public static function fromArray(array $data): PackageLink public static function fromArray(array $data): PackageLink
{ {

View file

@ -1,42 +1,47 @@
<?php <?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects\ComposerJson; /** @noinspection PhpMissingFieldTypeInspection */
class Suggestion /*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects\ComposerJson;
use ncc\Interfaces\SerializableObjectInterface;
class Suggestion implements SerializableObjectInterface
{ {
/** /**
* The name of the package suggestion * The name of the package suggestion
* *
* @var string * @var string
*/ */
public $package_name; private $package_name;
/** /**
* The comment for the suggestion * The comment for the suggestion
* *
* @var string * @var string
*/ */
public $comment; private $comment;
/** /**
* @param string|null $packageName * @param string|null $packageName
@ -49,9 +54,23 @@ namespace ncc\Objects\ComposerJson;
} }
/** /**
* Returns an array representation of the object * @return string|null
* */
* @return array public function getPackageName(): ?string
{
return $this->package_name;
}
/**
* @return string|null
*/
public function getComment(): ?string
{
return $this->comment;
}
/**
* @inheritDoc
*/ */
public function toArray(): array public function toArray(): array
{ {
@ -62,20 +81,21 @@ namespace ncc\Objects\ComposerJson;
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return Suggestion
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): Suggestion
{ {
$object = new self(); $object = new self();
if(isset($data['package_name'])) if(isset($data['package_name']))
{
$object->package_name = $data['package_name']; $object->package_name = $data['package_name'];
}
if(isset($data['comment'])) if(isset($data['comment']))
{
$object->comment = $data['comment']; $object->comment = $data['comment'];
}
return $object; return $object;
} }

View file

@ -25,75 +25,147 @@
namespace ncc\Objects\ComposerJson; namespace ncc\Objects\ComposerJson;
class Support use ncc\Interfaces\SerializableObjectInterface;
class Support implements SerializableObjectInterface
{ {
/** /**
* Email address for support * Email address for support
* *
* @var string|null * @var string|null
*/ */
public $email; private $email;
/** /**
* URL to the issue tracker * URL to the issue tracker
* *
* @var string|null * @var string|null
*/ */
public $issues; private $issues;
/** /**
* URL to the forum * URL to the forum
* *
* @var string|null * @var string|null
*/ */
public $forum; private $forum;
/** /**
* URL to the Wiki * URL to the Wiki
* *
* @var string|null * @var string|null
*/ */
public $wiki; private $wiki;
/** /**
* The IRC channel for support, as irc://server/channel * The IRC channel for support, as irc://server/channel
* *
* @var string|null * @var string|null
*/ */
public $irc; private $irc;
/** /**
* URL to browse or download the sources * URL to browse or download the sources
* *
* @var string|null * @var string|null
*/ */
public $source; private $source;
/** /**
* URL to the documentation * URL to the documentation
* *
* @var string|null * @var string|null
*/ */
public $docs; private $docs;
/** /**
* URL to the RSS feed * URL to the RSS feed
* *
* @var string|null * @var string|null
*/ */
public $rss; private $rss;
/** /**
* URL to the chat channel * URL to the chat channel
* *
* @var string|null * @var string|null
*/ */
public $chat; private $chat;
/** /**
* Returns an array representation of the object * @return string|null
* */
* @return array public function getEmail(): ?string
{
return $this->email;
}
/**
* @return string|null
*/
public function getIssues(): ?string
{
return $this->issues;
}
/**
* @return string|null
*/
public function getForum(): ?string
{
return $this->forum;
}
/**
* @return string|null
*/
public function getWiki(): ?string
{
return $this->wiki;
}
/**
* @return string|null
*/
public function getIrc(): ?string
{
return $this->irc;
}
/**
* @return string|null
*/
public function getSource(): ?string
{
return $this->source;
}
/**
* @return string|null
*/
public function getDocs(): ?string
{
return $this->docs;
}
/**
* @return string|null
*/
public function getRss(): ?string
{
return $this->rss;
}
/**
* @return string|null
*/
public function getChat(): ?string
{
return $this->chat;
}
/**
* @inheritDoc
*/ */
public function toArray(): array public function toArray(): array
{ {
@ -111,12 +183,9 @@
} }
/** /**
* Constructs object from array representation * @inheritDoc
*
* @param array $data
* @return Support
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): Support
{ {
$object = new self(); $object = new self();

View file

@ -82,9 +82,9 @@
if($overwrite) if($overwrite)
{ {
$this->deleteUnit($unit->execution_policy->getName()); $this->deleteUnit($unit->getExecutionPolicy()->getName());
} }
elseif($this->getUnit($unit->execution_policy->getName()) !== null) elseif($this->getUnit($unit->getExecutionPolicy()->getName()) !== null)
{ {
return false; return false;
} }
@ -111,7 +111,7 @@
$new_pointers = []; $new_pointers = [];
foreach($this->pointers as $pointer) foreach($this->pointers as $pointer)
{ {
if($pointer->execution_policy->getName() !== $name) if($pointer->getExecutionPolicy()->getName() !== $name)
{ {
$new_pointers[] = $pointer; $new_pointers[] = $pointer;
} }
@ -132,7 +132,7 @@
/** @var ExecutionPointer $pointer */ /** @var ExecutionPointer $pointer */
foreach($this->pointers as $pointer) foreach($this->pointers as $pointer)
{ {
if($pointer->execution_policy->getName() === $name) if($pointer->getExecutionPolicy()->getName() === $name)
{ {
return $pointer; return $pointer;
} }

View file

@ -1,53 +1,78 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * Copyright (c) Nosial 2022-2023, all rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without * associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\ExecutionPointers; namespace ncc\Objects\ExecutionPointers;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Objects\Package\ExecutionUnit; use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy; use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
class ExecutionPointer class ExecutionPointer implements BytecodeObjectInterface
{ {
/** /**
* @var string * @var string
*/ */
public $id; private $id;
/** /**
* The execution policy for this execution unit * The execution policy for this execution unit
* *
* @var ExecutionPolicy * @var ExecutionPolicy
*/ */
public $execution_policy; private $execution_policy;
/** /**
* The file pointer for where the target script should be executed * The file pointer for where the target script should be executed
* *
* @var string * @var string
*/ */
public $file_pointer; private $file_pointer;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @return ExecutionPolicy
*/
public function getExecutionPolicy(): ExecutionPolicy
{
return $this->execution_policy;
}
/**
* @return string|null
*/
public function getFilePointer(): ?string
{
return $this->file_pointer;
}
/** /**
* Public Constructor with optional ExecutionUnit parameter to construct object from * Public Constructor with optional ExecutionUnit parameter to construct object from
@ -63,7 +88,7 @@
} }
$this->id = $unit->getId(); $this->id = $unit->getId();
$this->execution_policy = $unit->execution_policy; $this->execution_policy = $unit->getExecutionPolicy();
$this->file_pointer = $bin_file; $this->file_pointer = $bin_file;
} }
@ -88,7 +113,7 @@
* @param array $data * @param array $data
* @return ExecutionPointer * @return ExecutionPointer
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): ExecutionPointer
{ {
$object = new self(); $object = new self();

View file

@ -26,24 +26,25 @@
use ncc\Exceptions\IOException; use ncc\Exceptions\IOException;
use ncc\Exceptions\PathNotFoundException; use ncc\Exceptions\PathNotFoundException;
use ncc\Interfaces\SerializableObjectInterface;
use ncc\Utilities\IO; use ncc\Utilities\IO;
use RuntimeException; use RuntimeException;
class Component class Component implements SerializableObjectInterface
{ {
/** /**
* The Vendor of the component * The Vendor of the component
* *
* @var string * @var string
*/ */
public $vendor; private $vendor;
/** /**
* The name of the package * The name of the package
* *
* @var string * @var string
*/ */
public $package_name; private $package_name;
/** /**
* Attempts to resolve the component's build version * Attempts to resolve the component's build version
@ -65,6 +66,22 @@
return IO::fread($component_path . 'VERSION'); return IO::fread($component_path . 'VERSION');
} }
/**
* @return string
*/
public function getVendor(): string
{
return $this->vendor;
}
/**
* @return string
*/
public function getPackageName(): string
{
return $this->package_name;
}
/** /**
* Returns an array representation of the object * Returns an array representation of the object
* *

View file

@ -214,7 +214,7 @@
{ {
foreach($this->execution_units as $unit) foreach($this->execution_units as $unit)
{ {
if($unit->execution_policy->getName() === $name) if($unit->getExecutionPolicy()->getName() === $name)
{ {
return $unit; return $unit;
} }
@ -276,33 +276,33 @@
$package_type = substr($encoding_header, 3, 2); $package_type = substr($encoding_header, 3, 2);
$magic_bytes = new MagicBytes(); $magic_bytes = new MagicBytes();
$magic_bytes->PackageStructureVersion = $package_structure_version; $magic_bytes->setPackageStructureVersion($package_structure_version);
// Determine the encoding type // Determine the encoding type
switch($encoding_type) switch($encoding_type)
{ {
case '300': case '300':
$magic_bytes->Encoder = EncoderType::ZI_PROTO; $magic_bytes->setEncoder(EncoderType::ZI_PROTO);
$magic_bytes->IsCompressed = false; $magic_bytes->setCompressed(false);
$magic_bytes->IsEncrypted = false; $magic_bytes->setCompressed(false);
break; break;
case '301': case '301':
$magic_bytes->Encoder = EncoderType::ZI_PROTO; $magic_bytes->setEncoder(EncoderType::ZI_PROTO);
$magic_bytes->IsCompressed = true; $magic_bytes->setCompressed(true);
$magic_bytes->IsEncrypted = false; $magic_bytes->setEncrypted(false);
break; break;
case '310': case '310':
$magic_bytes->Encoder = EncoderType::ZI_PROTO; $magic_bytes->setEncoder(EncoderType::ZI_PROTO);
$magic_bytes->IsCompressed = false; $magic_bytes->setCompressed(false);
$magic_bytes->IsEncrypted = true; $magic_bytes->setEncrypted(true);
break; break;
case '311': case '311':
$magic_bytes->Encoder = EncoderType::ZI_PROTO; $magic_bytes->setEncoder(EncoderType::ZI_PROTO);
$magic_bytes->IsCompressed = true; $magic_bytes->setCompressed(true);
$magic_bytes->IsEncrypted = true; $magic_bytes->setEncrypted(true);
break; break;
default: default:
@ -313,18 +313,18 @@
switch($package_type) switch($package_type)
{ {
case '40': case '40':
$magic_bytes->IsInstallable = true; $magic_bytes->setInstallable(true);
$magic_bytes->IsExecutable = false; $magic_bytes->setExecutable(false);
break; break;
case '41': case '41':
$magic_bytes->IsInstallable = false; $magic_bytes->setInstallable(false);
$magic_bytes->IsExecutable = true; $magic_bytes->setExecutable(true);
break; break;
case '42': case '42':
$magic_bytes->IsInstallable = true; $magic_bytes->setInstallable(true);
$magic_bytes->IsExecutable = true; $magic_bytes->setExecutable(true);
break; break;
default: default:

View file

@ -24,30 +24,31 @@
namespace ncc\Objects\Package; namespace ncc\Objects\Package;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
class Component class Component implements BytecodeObjectInterface
{ {
/** /**
* The name of the component or the file name of the component * The name of the component or the file name of the component
* *
* @var string * @var string
*/ */
public $name; private $name;
/** /**
* Flags associated with the component created by the compiler extension * Flags associated with the component created by the compiler extension
* *
* @var array * @var array
*/ */
public $flags; private $flags;
/** /**
* The data type of the component * The data type of the component
* *
* @var string * @var string
*/ */
public $data_types; private $data_type;
/** /**
* A sha1 hash checksum of the component, this will be compared against the data to determine * A sha1 hash checksum of the component, this will be compared against the data to determine
@ -62,7 +63,7 @@
* *
* @var mixed * @var mixed
*/ */
public $data; private $data;
/** /**
* Validates the checksum of the component, returns false if the checksum or data is invalid or if the checksum * Validates the checksum of the component, returns false if the checksum or data is invalid or if the checksum
@ -82,12 +83,7 @@
return true; // Return true if the data is null return true; // Return true if the data is null
} }
if(hash('sha1', $this->data, true) !== $this->checksum) return hash_equals($this->checksum, hash('sha1', $this->data, true));
{
return false; // Return false if the checksum failed
}
return true;
} }
/** /**
@ -105,6 +101,106 @@
} }
} }
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return array
*/
public function getFlags(): array
{
return $this->flags;
}
/**
* @param array $flags
*/
public function setFlags(array $flags): void
{
$this->flags = $flags;
}
/**
* @param string $flag
* @return void
*/
public function addFlag(string $flag): void
{
$this->flags[] = $flag;
}
/**
* @param string $flag
* @return void
*/
public function removeFlag(string $flag): void
{
$this->flags = array_filter($this->flags, static function($f) use ($flag) {
return $f !== $flag;
});
}
/**
* @return string
*/
public function getDataType(): string
{
return $this->data_type;
}
/**
* @param string $data_type
*/
public function setDataType(string $data_type): void
{
$this->data_type = $data_type;
}
/**
* @return string
*/
public function getChecksum(): string
{
return $this->checksum;
}
/**
* @param string $checksum
*/
public function setChecksum(string $checksum): void
{
$this->checksum = $checksum;
}
/**
* @return mixed
*/
public function getData(): mixed
{
return $this->data;
}
/**
* @param mixed $data
*/
public function setData(mixed $data): void
{
$this->data = $data;
}
/** /**
* Returns an array representation of the component. * Returns an array representation of the component.
* *
@ -116,7 +212,7 @@
return [ return [
($bytecode ? Functions::cbc('name') : 'name') => $this->name, ($bytecode ? Functions::cbc('name') : 'name') => $this->name,
($bytecode ? Functions::cbc('flags') : 'flags') => $this->flags, ($bytecode ? Functions::cbc('flags') : 'flags') => $this->flags,
($bytecode ? Functions::cbc('data_type') : 'data_type') => $this->data_types, ($bytecode ? Functions::cbc('data_type') : 'data_type') => $this->data_type,
($bytecode ? Functions::cbc('checksum') : 'checksum') => $this->checksum, ($bytecode ? Functions::cbc('checksum') : 'checksum') => $this->checksum,
($bytecode ? Functions::cbc('data') : 'data') => $this->data, ($bytecode ? Functions::cbc('data') : 'data') => $this->data,
]; ];
@ -128,16 +224,16 @@
* @param array $data * @param array $data
* @return Component * @return Component
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): Component
{ {
$Object = new self(); $object = new self();
$Object->name = Functions::array_bc($data, 'name'); $object->name = Functions::array_bc($data, 'name');
$Object->flags = Functions::array_bc($data, 'flags'); $object->flags = Functions::array_bc($data, 'flags');
$Object->data_types = Functions::array_bc($data, 'data_type'); $object->data_type = Functions::array_bc($data, 'data_type');
$Object->checksum = Functions::array_bc($data, 'checksum'); $object->checksum = Functions::array_bc($data, 'checksum');
$Object->data = Functions::array_bc($data, 'data'); $object->data = Functions::array_bc($data, 'data');
return $Object; return $object;
} }
} }

View file

@ -1,33 +1,34 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * Copyright (c) Nosial 2022-2023, all rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without * associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\Package; namespace ncc\Objects\Package;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy; use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
class ExecutionUnit class ExecutionUnit implements BytecodeObjectInterface
{ {
/** /**
* @var string|null * @var string|null
@ -39,54 +40,21 @@
* *
* @var ExecutionPolicy * @var ExecutionPolicy
*/ */
public $execution_policy; private $execution_policy;
/** /**
* The data of the unit to execute * The data of the unit to execute
* *
* @var string * @var string
*/ */
public $Data; private $data;
/**
* Returns an array representation of the object
*
* @param bool $bytecode
* @return array
*/
public function toArray(bool $bytecode=false): array
{
return [
($bytecode ? Functions::cbc('execution_policy') : 'execution_policy') => $this->execution_policy->toArray($bytecode),
($bytecode ? Functions::cbc('data') : 'data') => $this->Data,
];
}
/**
* Constructs object from an array representation
*
* @param array $data
* @return static
*/
public static function fromArray(array $data): self
{
$object = new self();
$object->execution_policy = Functions::array_bc($data, 'execution_policy');
$object->Data = Functions::array_bc($data, 'data');
if($object->execution_policy !== null)
$object->execution_policy = ExecutionPolicy::fromArray($object->execution_policy);
return $object;
}
/** /**
* @return string * @return string
*/ */
public function getId(): string public function getId(): string
{ {
if($this->id == null) if($this->id === null)
{ {
$this->id = hash('sha1', $this->execution_policy->getName()); $this->id = hash('sha1', $this->execution_policy->getName());
} }
@ -94,4 +62,64 @@
return $this->id; return $this->id;
} }
/**
* @return ExecutionPolicy
*/
public function getExecutionPolicy(): ExecutionPolicy
{
return $this->execution_policy;
}
/**
* @param ExecutionPolicy $execution_policy
*/
public function setExecutionPolicy(ExecutionPolicy $execution_policy): void
{
$this->execution_policy = $execution_policy;
}
/**
* @return string
*/
public function getData(): string
{
return $this->data;
}
/**
* @param string $data
*/
public function setData(string $data): void
{
$this->data = $data;
}
/**
* @inheritDoc
*/
public function toArray(bool $bytecode=false): array
{
return [
($bytecode ? Functions::cbc('execution_policy') : 'execution_policy') => $this->execution_policy->toArray($bytecode),
($bytecode ? Functions::cbc('data') : 'data') => $this->data,
];
}
/**
* @inheritDoc
*/
public static function fromArray(array $data): ExecutionUnit
{
$object = new self();
$object->execution_policy = Functions::array_bc($data, 'execution_policy');
$object->data = Functions::array_bc($data, 'data');
if($object->execution_policy !== null)
{
$object->execution_policy = ExecutionPolicy::fromArray($object->execution_policy);
}
return $object;
}
} }

View file

@ -24,94 +24,202 @@
namespace ncc\Objects\Package; namespace ncc\Objects\Package;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Objects\ProjectConfiguration\Compiler; use ncc\Objects\ProjectConfiguration\Compiler;
use ncc\Objects\ProjectConfiguration\UpdateSource; use ncc\Objects\ProjectConfiguration\UpdateSource;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
class Header class Header implements BytecodeObjectInterface
{ {
/** /**
* The compiler extension information that was used to build the package * The compiler extension information that was used to build the package
* *
* @var Compiler * @var Compiler
*/ */
public $CompilerExtension; private $compiler_extension;
/** /**
* An array of constants that are set when the package is imported or executed during runtime. * An array of constants that are set when the package is imported or executed during runtime.
* *
* @var array * @var array
*/ */
public $RuntimeConstants; private $runtime_constants;
/** /**
* The version of NCC that was used to compile the package, can be used for backwards compatibility * The version of NCC that was used to compile the package, can be used for backwards compatibility
* *
* @var string * @var string
*/ */
public $CompilerVersion; private $compiler_version;
/** /**
* An array of options to pass on to the extension * An array of options to pass on to the extension
* *
* @var array|null * @var array|null
*/ */
public $Options; private $options;
/** /**
* The optional update source to where the package can be updated from * The optional update source to where the package can be updated from
* *
* @var UpdateSource|null * @var UpdateSource|null
*/ */
public $UpdateSource; private $update_source;
/** /**
* Public Constructor * Public Constructor
*/ */
public function __construct() public function __construct()
{ {
$this->CompilerExtension = new Compiler(); $this->compiler_extension = new Compiler();
$this->RuntimeConstants = []; $this->runtime_constants = [];
$this->Options = []; $this->options = [];
}
/**
* @return Compiler
*/
public function getCompilerExtension(): Compiler
{
return $this->compiler_extension;
}
/**
* @param Compiler $compiler_extension
*/
public function setCompilerExtension(Compiler $compiler_extension): void
{
$this->compiler_extension = $compiler_extension;
} }
/** /**
* Returns an array representation of the object
*
* @param bool $bytecode
* @return array * @return array
*/ */
public function getRuntimeConstants(): array
{
return $this->runtime_constants;
}
/**
* @param array $runtime_constants
*/
public function setRuntimeConstants(array $runtime_constants): void
{
$this->runtime_constants = $runtime_constants;
}
/**
* @return string
*/
public function getCompilerVersion(): string
{
return $this->compiler_version;
}
/**
* @param string $compiler_version
*/
public function setCompilerVersion(string $compiler_version): void
{
$this->compiler_version = $compiler_version;
}
/**
* @return array|null
*/
public function getOptions(): ?array
{
return $this->options;
}
/**
* @param array|null $options
*/
public function setOptions(?array $options): void
{
$this->options = $options;
}
/**
* @param string $key
* @param $value
* @return void
*/
public function setOption(string $key, $value): void
{
$this->options[$key] = $value;
}
/**
* @param string $key
* @return void
*/
public function removeOption(string $key): void
{
unset($this->options[$key]);
}
/**
* @param string $key
* @return mixed|null
*/
public function getOption(string $key): mixed
{
return $this->options[$key] ?? null;
}
/**
* @return UpdateSource|null
*/
public function getUpdateSource(): ?UpdateSource
{
return $this->update_source;
}
/**
* @param UpdateSource|null $update_source
*/
public function setUpdateSource(?UpdateSource $update_source): void
{
$this->update_source = $update_source;
}
/**
* @inheritDoc
*/
public function toArray(bool $bytecode=false): array public function toArray(bool $bytecode=false): array
{ {
return [ return [
($bytecode ? Functions::cbc('compiler_extension') : 'compiler_extension') => $this->CompilerExtension->toArray(), ($bytecode ? Functions::cbc('compiler_extension') : 'compiler_extension') => $this->compiler_extension->toArray(),
($bytecode ? Functions::cbc('runtime_constants') : 'runtime_constants') => $this->RuntimeConstants, ($bytecode ? Functions::cbc('runtime_constants') : 'runtime_constants') => $this->runtime_constants,
($bytecode ? Functions::cbc('compiler_version') : 'compiler_version') => $this->CompilerVersion, ($bytecode ? Functions::cbc('compiler_version') : 'compiler_version') => $this->compiler_version,
($bytecode ? Functions::cbc('update_source') : 'update_source') => ($this->UpdateSource?->toArray($bytecode) ?? null), ($bytecode ? Functions::cbc('update_source') : 'update_source') => ($this->update_source?->toArray($bytecode)),
($bytecode ? Functions::cbc('options') : 'options') => $this->Options, ($bytecode ? Functions::cbc('options') : 'options') => $this->options,
]; ];
} }
/** /**
* Constructs the object from an array representation * @inheritDoc
*
* @param array $data
* @return static
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): Header
{ {
$object = new self(); $object = new self();
$object->CompilerExtension = Functions::array_bc($data, 'compiler_extension'); $object->compiler_extension = Functions::array_bc($data, 'compiler_extension');
$object->RuntimeConstants = Functions::array_bc($data, 'runtime_constants'); $object->runtime_constants = Functions::array_bc($data, 'runtime_constants');
$object->CompilerVersion = Functions::array_bc($data, 'compiler_version'); $object->compiler_version = Functions::array_bc($data, 'compiler_version');
$object->UpdateSource = Functions::array_bc($data, 'update_source'); $object->update_source = Functions::array_bc($data, 'update_source');
$object->Options = Functions::array_bc($data, 'options'); $object->options = Functions::array_bc($data, 'options');
if($object->CompilerExtension !== null) if($object->compiler_extension !== null)
$object->CompilerExtension = Compiler::fromArray($object->CompilerExtension); {
if($object->UpdateSource !== null) $object->compiler_extension = Compiler::fromArray($object->compiler_extension);
$object->UpdateSource = UpdateSource::fromArray($object->UpdateSource); }
if($object->update_source !== null)
{
$object->update_source = UpdateSource::fromArray($object->update_source);
}
return $object; return $object;
} }

View file

@ -1,120 +1,209 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * Copyright (c) Nosial 2022-2023, all rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without * associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\Package; namespace ncc\Objects\Package;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
class Installer class Installer implements BytecodeObjectInterface
{ {
/** /**
* An array of execution policies to execute pre install * An array of execution policies to execute pre install
* *
* @var string[]|null * @var string[]|null
*/ */
public $PreInstall; private $pre_install;
/** /**
* An array of execution policies to execute post install * An array of execution policies to execute post install
* *
* @var string[]|null * @var string[]|null
*/ */
public $PostInstall; private $post_install;
/** /**
* An array of execution policies to execute pre uninstall * An array of execution policies to execute pre uninstall
* *
* @var string[]|null * @var string[]|null
*/ */
public $PreUninstall; private $pre_uninstall;
/** /**
* An array of execution policies to execute post uninstall * An array of execution policies to execute post uninstall
* *
* @var string[]|null * @var string[]|null
*/ */
public $PostUninstall; private $post_uninstall;
/** /**
* An array of execution policies to execute pre update * An array of execution policies to execute pre update
* *
* @var string[]|null * @var string[]|null
*/ */
public $PreUpdate; private $pre_update;
/** /**
* An array of execution policies to execute post update * An array of execution policies to execute post update
* *
* @var string[]|null * @var string[]|null
*/ */
public $PostUpdate; private $post_update;
/** /**
* Returns an array representation of the object * @return string[]|null
* Returns null if all properties are not set
*
* @param bool $bytecode
* @return array|null
*/ */
public function toArray(bool $bytecode=false): ?array public function getPreInstall(): ?array
{
return $this->pre_install;
}
/**
* @param string[]|null $pre_install
*/
public function setPreInstall(?array $pre_install): void
{
$this->pre_install = $pre_install;
}
/**
* @return string[]|null
*/
public function getPostInstall(): ?array
{
return $this->post_install;
}
/**
* @param string[]|null $post_install
*/
public function setPostInstall(?array $post_install): void
{
$this->post_install = $post_install;
}
/**
* @return string[]|null
*/
public function getPreUninstall(): ?array
{
return $this->pre_uninstall;
}
/**
* @param string[]|null $pre_uninstall
*/
public function setPreUninstall(?array $pre_uninstall): void
{
$this->pre_uninstall = $pre_uninstall;
}
/**
* @return string[]|null
*/
public function getPostUninstall(): ?array
{
return $this->post_uninstall;
}
/**
* @param string[]|null $post_uninstall
*/
public function setPostUninstall(?array $post_uninstall): void
{
$this->post_uninstall = $post_uninstall;
}
/**
* @return string[]|null
*/
public function getPreUpdate(): ?array
{
return $this->pre_update;
}
/**
* @param string[]|null $pre_update
*/
public function setPreUpdate(?array $pre_update): void
{
$this->pre_update = $pre_update;
}
/**
* @return string[]|null
*/
public function getPostUpdate(): ?array
{
return $this->post_update;
}
/**
* @param string[]|null $post_update
*/
public function setPostUpdate(?array $post_update): void
{
$this->post_update = $post_update;
}
/**
* @inheritDoc
*/
public function toArray(bool $bytecode=false): array
{ {
if( if(
$this->PreInstall == null && $this->PostInstall == null && $this->pre_install === null && $this->post_install === null &&
$this->PreUninstall == null && $this->PostUninstall == null && $this->pre_uninstall === null && $this->post_uninstall === null &&
$this->PreUpdate == null && $this->PostUpdate == null $this->pre_update === null && $this->post_update === null
) )
{ {
return null; return [];
} }
return [ return [
($bytecode ? Functions::cbc('pre_install') : 'pre_install') => ($this->PreInstall == null ? null : $this->PreInstall), ($bytecode ? Functions::cbc('pre_install') : 'pre_install') => $this->pre_install,
($bytecode ? Functions::cbc('post_install') : 'post_install') => ($this->PostInstall == null ? null : $this->PostInstall), ($bytecode ? Functions::cbc('post_install') : 'post_install') => $this->post_install,
($bytecode ? Functions::cbc('pre_uninstall') : 'pre_uninstall') => ($this->PreUninstall == null ? null : $this->PreUninstall), ($bytecode ? Functions::cbc('pre_uninstall') : 'pre_uninstall') => $this->pre_uninstall,
($bytecode? Functions::cbc('post_uninstall') : 'post_uninstall') => ($this->PostUninstall == null ? null : $this->PostUninstall), ($bytecode? Functions::cbc('post_uninstall') : 'post_uninstall') => $this->post_uninstall,
($bytecode? Functions::cbc('pre_update') : 'pre_update') => ($this->PreUpdate == null ? null : $this->PreUpdate), ($bytecode? Functions::cbc('pre_update') : 'pre_update') => $this->pre_update,
($bytecode? Functions::cbc('post_update') : 'post_update') => ($this->PostUpdate == null ? null : $this->PostUpdate) ($bytecode? Functions::cbc('post_update') : 'post_update') => $this->post_update
]; ];
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return Installer
* @noinspection DuplicatedCode
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): Installer
{ {
$object = new self(); $object = new self();
$object->PreInstall = Functions::array_bc($data, 'pre_install'); $object->pre_install = Functions::array_bc($data, 'pre_install');
$object->PostInstall = Functions::array_bc($data, 'post_install'); $object->post_install = Functions::array_bc($data, 'post_install');
$object->PreUninstall = Functions::array_bc($data, 'pre_uninstall'); $object->pre_uninstall = Functions::array_bc($data, 'pre_uninstall');
$object->PostUninstall = Functions::array_bc($data, 'post_uninstall'); $object->post_uninstall = Functions::array_bc($data, 'post_uninstall');
$object->PreUpdate = Functions::array_bc($data, 'pre_update'); $object->pre_update = Functions::array_bc($data, 'pre_update');
$object->PostUpdate = Functions::array_bc($data, 'post_update'); $object->post_update = Functions::array_bc($data, 'post_update');
return $object; return $object;
} }

View file

@ -1,24 +1,24 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * Copyright (c) Nosial 2022-2023, all rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without * associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
@ -26,95 +26,189 @@
use ncc\Enums\EncoderType; use ncc\Enums\EncoderType;
use ncc\Enums\Versions; use ncc\Enums\Versions;
use ncc\Interfaces\SerializableObjectInterface;
class MagicBytes class MagicBytes implements SerializableObjectInterface
{ {
/** /**
* The version of the package structure standard that is used * The version of the package structure standard that is used
* *
* @var string * @var string
*/ */
public $PackageStructureVersion; private $package_structure_version;
/** /**
* The type of encoder that was used to encode the package structure * The type of encoder that was used to encode the package structure
* *
* @var string|EncoderType * @var string|EncoderType
*/ */
public $Encoder; private $encoder;
/** /**
* Indicates whether the package structure is compressed * Indicates whether the package structure is compressed
* *
* @var bool * @var bool
*/ */
public $IsCompressed; private $compressed;
/** /**
* Indicates whether the package structure is encrypted * Indicates whether the package structure is encrypted
* *
* @var bool * @var bool
*/ */
public $IsEncrypted; private $encrypted;
/** /**
* Indicates whether the package is installable * Indicates whether the package is installable
* *
* @var bool * @var bool
*/ */
public $IsInstallable; private $installable;
/** /**
* Indicates whether the package is a executable * Indicates whether the package is a executable
* *
* @var bool * @var bool
*/ */
public $IsExecutable; private $executable;
/** /**
* Basic Public Constructor with default values * Basic Public Constructor with default values
*/ */
public function __construct() public function __construct()
{ {
$this->PackageStructureVersion = Versions::PACKAGE_STRUCTURE_VERSION; $this->package_structure_version = Versions::PACKAGE_STRUCTURE_VERSION;
$this->Encoder = EncoderType::ZI_PROTO; $this->encoder = EncoderType::ZI_PROTO;
$this->IsCompressed = false; $this->compressed = false;
$this->IsEncrypted = false; $this->encrypted = false;
$this->IsInstallable = false; $this->installable = false;
$this->IsExecutable = false; $this->executable = false;
} }
/** /**
* Returns an array representation of the object * @return string
* */
* @return array public function getPackageStructureVersion(): string
{
return $this->package_structure_version;
}
/**
* @param string $package_structure_version
*/
public function setPackageStructureVersion(string $package_structure_version): void
{
$this->package_structure_version = $package_structure_version;
}
/**
* @return EncoderType|string
*/
public function getEncoder(): EncoderType|string
{
return $this->encoder;
}
/**
* @param EncoderType|string $encoder
*/
public function setEncoder(EncoderType|string $encoder): void
{
$this->encoder = $encoder;
}
/**
* @return bool
*/
public function isCompressed(): bool
{
return $this->compressed;
}
/**
* @param bool $compressed
*/
public function setCompressed(bool $compressed): void
{
$this->compressed = $compressed;
}
/**
* @return bool
*/
public function isEncrypted(): bool
{
return $this->encrypted;
}
/**
* @param bool $encrypted
*/
public function setEncrypted(bool $encrypted): void
{
$this->encrypted = $encrypted;
}
/**
* @return bool
*/
public function isInstallable(): bool
{
return $this->installable;
}
/**
* @param bool $installable
*/
public function setInstallable(bool $installable): void
{
$this->installable = $installable;
}
/**
* @return bool
*/
public function isExecutable(): bool
{
return $this->executable;
}
/**
* @param bool $executable
*/
public function setExecutable(bool $executable): void
{
$this->executable = $executable;
}
/**
* @inheritDoc
*/ */
public function toArray(): array public function toArray(): array
{ {
return [ return [
'package_structure_version' => $this->PackageStructureVersion, 'package_structure_version' => $this->package_structure_version,
'encoder' => $this->Encoder, 'encoder' => $this->encoder,
'is_compressed' => $this->IsCompressed, 'is_compressed' => $this->compressed,
'is_encrypted' => $this->IsEncrypted, 'is_encrypted' => $this->encrypted,
'is_installable' => $this->IsInstallable, 'is_installable' => $this->installable,
'is_executable' => $this->IsExecutable 'is_executable' => $this->executable
]; ];
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return MagicBytes
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): self
{ {
$Object = new self(); $object = new self();
if(isset($data['is_executable'])) if(isset($data['is_executable']))
$Object->IsExecutable = (bool)$data['is_executable']; {
$object->executable = (bool)$data['is_executable'];
}
return $Object; return $object;
} }
/** /**
@ -125,12 +219,12 @@
public function toString(): string public function toString(): string
{ {
// NCC_PACKAGE1.0 // NCC_PACKAGE1.0
$magic_bytes = 'NCC_PACKAGE' . $this->PackageStructureVersion; $magic_bytes = 'NCC_PACKAGE' . $this->package_structure_version;
// NCC_PACKAGE1.03 // NCC_PACKAGE1.03
$magic_bytes .= $this->Encoder; $magic_bytes .= $this->encoder;
if($this->IsEncrypted) if($this->encrypted)
{ {
// NCC_PACKAGE1.031 // NCC_PACKAGE1.031
$magic_bytes .= '1'; $magic_bytes .= '1';
@ -141,7 +235,7 @@
$magic_bytes .= '0'; $magic_bytes .= '0';
} }
if($this->IsCompressed) if($this->compressed)
{ {
// NCC_PACKAGE1.0301 // NCC_PACKAGE1.0301
$magic_bytes .= '1'; $magic_bytes .= '1';
@ -152,17 +246,17 @@
$magic_bytes .= '0'; $magic_bytes .= '0';
} }
if($this->IsExecutable && $this->IsInstallable) if($this->executable && $this->installable)
{ {
// NCC_PACKAGE1.030142 // NCC_PACKAGE1.030142
$magic_bytes .= '42'; $magic_bytes .= '42';
} }
elseif($this->IsExecutable) elseif($this->executable)
{ {
// NCC_PACKAGE1.030141 // NCC_PACKAGE1.030141
$magic_bytes .= '41'; $magic_bytes .= '41';
} }
elseif($this->IsInstallable) elseif($this->installable)
{ {
// NCC_PACKAGE1.030140 // NCC_PACKAGE1.030140
$magic_bytes .= '40'; $magic_bytes .= '40';

View file

@ -1,39 +1,40 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * Copyright (c) Nosial 2022-2023, all rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without * associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\Package; namespace ncc\Objects\Package;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
class Resource class Resource implements BytecodeObjectInterface
{ {
/** /**
* The file/path name of the resource * The file/path name of the resource
* *
* @var string * @var string
*/ */
public $Name; private $name;
/** /**
* A sha1 hash checksum of the resource, this will be compared against the data to determine * A sha1 hash checksum of the resource, this will be compared against the data to determine
@ -41,14 +42,14 @@
* *
* @var string * @var string
*/ */
private $Checksum; private $checksum;
/** /**
* The raw data of the resource * The raw data of the resource
* *
* @var string * @var string
*/ */
public $Data; private $data;
/** /**
* Validates the checksum of the resource, returns false if the checksum or data is invalid or if the checksum * Validates the checksum of the resource, returns false if the checksum or data is invalid or if the checksum
@ -58,16 +59,17 @@
*/ */
public function validateChecksum(): bool public function validateChecksum(): bool
{ {
if($this->Checksum === null) if($this->checksum === null)
{
return false; return false;
}
if($this->Data === null) if($this->data === null)
{
return false; return false;
}
if(hash('sha1', $this->Data, true) !== $this->Checksum) return hash_equals($this->checksum, hash('sha1', $this->data, true));
return false;
return true;
} }
/** /**
@ -77,42 +79,84 @@
*/ */
public function updateChecksum(): void public function updateChecksum(): void
{ {
$this->Checksum = null; $this->checksum = null;
if(gettype($this->Data) == 'string') if(is_string($this->data))
{ {
$this->Checksum = hash('sha1', $this->Data, true); $this->checksum = hash('sha1', $this->data, true);
} }
} }
/** /**
* Returns an array representation of the resource. * @return string
* */
* @param bool $bytecode public function getName(): string
* @return array {
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return string
*/
public function getChecksum(): string
{
return $this->checksum;
}
/**
* @param string $checksum
*/
public function setChecksum(string $checksum): void
{
$this->checksum = $checksum;
}
/**
* @return string
*/
public function getData(): string
{
return $this->data;
}
/**
* @param string $data
*/
public function setData(string $data): void
{
$this->data = $data;
}
/**
* @inheritDoc
*/ */
public function toArray(bool $bytecode=false): array public function toArray(bool $bytecode=false): array
{ {
return [ return [
($bytecode ? Functions::cbc('name') : 'name') => $this->Name, ($bytecode ? Functions::cbc('name') : 'name') => $this->name,
($bytecode ? Functions::cbc('checksum') : 'checksum') => $this->Checksum, ($bytecode ? Functions::cbc('checksum') : 'checksum') => $this->checksum,
($bytecode ? Functions::cbc('data') : 'data') => $this->Data, ($bytecode ? Functions::cbc('data') : 'data') => $this->data,
]; ];
} }
/** /**
* Constructs a new object from an array representation * @inheritDoc
*
* @param array $data
* @return Resource
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): self
{ {
$object = new self(); $object = new self();
$object->Name = Functions::array_bc($data, 'name'); $object->name = Functions::array_bc($data, 'name');
$object->Checksum = Functions::array_bc($data, 'checksum'); $object->checksum = Functions::array_bc($data, 'checksum');
$object->Data = Functions::array_bc($data, 'data'); $object->data = Functions::array_bc($data, 'data');
return $object; return $object;
} }

View file

@ -88,18 +88,16 @@
{ {
$package_entry = new PackageEntry(); $package_entry = new PackageEntry();
$package_entry->addVersion($package, $install_path, true); $package_entry->addVersion($package, $install_path, true);
$package_entry->Name = $package->assembly->getPackage(); $package_entry->setName($package->assembly->getPackage());
$package_entry->UpdateSource = $package->header->UpdateSource; $package_entry->setUpdateSource($package->header->getUpdateSource());
$package_entry->getDataPath();
$this->Packages[$package->assembly->getPackage()] = $package_entry; $this->Packages[$package->assembly->getPackage()] = $package_entry;
$this->update(); $this->update();
return; return;
} }
$this->Packages[$package->assembly->getPackage()]->UpdateSource = $package->header->UpdateSource; $this->Packages[$package->assembly->getPackage()]->setUpdateSource($package->header->getUpdateSource());
$this->Packages[$package->assembly->getPackage()]->addVersion($package, $install_path, true); $this->Packages[$package->assembly->getPackage()]->addVersion($package, $install_path, true);
$this->Packages[$package->assembly->getPackage()]->getDataPath();
$this->update(); $this->update();
} }
@ -254,7 +252,7 @@
foreach($packages as $_datum) foreach($packages as $_datum)
{ {
$entry = PackageEntry::fromArray($_datum); $entry = PackageEntry::fromArray($_datum);
$object->Packages[$entry->Name] = $entry; $object->Packages[$entry->getName()] = $entry;
} }
} }

View file

@ -1,83 +1,113 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * Copyright (c) Nosial 2022-2023, all rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without * associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\PackageLock; namespace ncc\Objects\PackageLock;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Objects\ProjectConfiguration\Dependency; use ncc\Objects\ProjectConfiguration\Dependency;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
class DependencyEntry class DependencyEntry implements BytecodeObjectInterface
{ {
/** /**
* The name of the package dependency * The name of the package dependency
* *
* @var string * @var string
*/ */
public $PackageName; private $package_name;
/** /**
* The version of the package dependency * The version of the package dependency
* *
* @var string * @var string
*/ */
public $Version; private $version;
/**
* @param Dependency|null $dependency
*/
public function __construct(?Dependency $dependency=null) public function __construct(?Dependency $dependency=null)
{ {
if($dependency !== null) if($dependency !== null)
{ {
$this->PackageName = $dependency->getName(); $this->package_name = $dependency->getName();
$this->Version = $dependency->getVersion(); $this->version = $dependency->getVersion();
} }
} }
/** /**
* Returns an array representation of the object * @return string
* */
* @param bool $bytecode public function getPackageName(): string
* @return array {
return $this->package_name;
}
/**
* @param string $package_name
*/
public function setPackageName(string $package_name): void
{
$this->package_name = $package_name;
}
/**
* @return string
*/
public function getVersion(): string
{
return $this->version;
}
/**
* @param string $version
*/
public function setVersion(string $version): void
{
$this->version = $version;
}
/**
* @inheritDoc
*/ */
public function toArray(bool $bytecode=false): array public function toArray(bool $bytecode=false): array
{ {
return [ return [
($bytecode ? Functions::cbc('package_name') : 'package_name') => $this->PackageName, ($bytecode ? Functions::cbc('package_name') : 'package_name') => $this->package_name,
($bytecode ? Functions::cbc('version') : 'version') => $this->Version, ($bytecode ? Functions::cbc('version') : 'version') => $this->version,
]; ];
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return DependencyEntry
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): DependencyEntry
{ {
$object = new self(); $object = new self();
$object->PackageName = Functions::array_bc($data, 'package_name'); $object->package_name = Functions::array_bc($data, 'package_name');
$object->Version = Functions::array_bc($data, 'version'); $object->version = Functions::array_bc($data, 'version');
return $object; return $object;
} }

View file

@ -28,6 +28,7 @@
use ncc\Enums\Versions; use ncc\Enums\Versions;
use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\ConfigurationException;
use ncc\Exceptions\IOException; use ncc\Exceptions\IOException;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Objects\Package; use ncc\Objects\Package;
use ncc\Objects\ProjectConfiguration\UpdateSource; use ncc\Objects\ProjectConfiguration\UpdateSource;
use ncc\ThirdParty\jelix\Version\VersionComparator; use ncc\ThirdParty\jelix\Version\VersionComparator;
@ -36,42 +37,42 @@
use ncc\Utilities\PathFinder; use ncc\Utilities\PathFinder;
use ncc\Utilities\Resolver; use ncc\Utilities\Resolver;
class PackageEntry class PackageEntry implements BytecodeObjectInterface
{ {
/** /**
* The name of the package that's installed * The name of the package that's installed
* *
* @var string * @var string
*/ */
public $Name; private $name;
/** /**
* The latest version of the package entry, this is updated automatically * The latest version of the package entry, this is updated automatically
* *
* @var string|null * @var string|null
*/ */
private $LatestVersion; private $latest_version;
/** /**
* An array of installed versions for this package * An array of installed versions for this package
* *
* @var VersionEntry[] * @var VersionEntry[]
*/ */
public $Versions; private $versions;
/** /**
* The update source of the package entry * The update source of the package entry
* *
* @var UpdateSource|null * @var UpdateSource|null
*/ */
public $UpdateSource; private $update_source;
/** /**
* Public Constructor * Public Constructor
*/ */
public function __construct() public function __construct()
{ {
$this->Versions = []; $this->versions = [];
} }
/** /**
@ -84,15 +85,15 @@
*/ */
public function getVersion(string $version, bool $throw_exception=false): ?VersionEntry public function getVersion(string $version, bool $throw_exception=false): ?VersionEntry
{ {
if($version === Versions::LATEST && $this->LatestVersion !== null) if($version === Versions::LATEST && $this->latest_version !== null)
{ {
/** @noinspection CallableParameterUseCaseInTypeContextInspection */ /** @noinspection CallableParameterUseCaseInTypeContextInspection */
$version = $this->LatestVersion; $version = $this->latest_version;
} }
foreach($this->Versions as $versionEntry) foreach($this->versions as $versionEntry)
{ {
if($versionEntry->Version === $version) if($versionEntry->getVersion() === $version)
{ {
return $versionEntry; return $versionEntry;
} }
@ -100,7 +101,7 @@
if($throw_exception) if($throw_exception)
{ {
throw new IOException(sprintf('Version %s of %s is not installed', $version, $this->Name)); throw new IOException(sprintf('Version %s of %s is not installed', $version, $this->name));
} }
return null; return null;
@ -118,9 +119,9 @@
$count = 0; $count = 0;
$found_node = false; $found_node = false;
foreach($this->Versions as $versionEntry) foreach($this->versions as $versionEntry)
{ {
if($versionEntry->Version === $version) if($versionEntry->getVersion() === $version)
{ {
$found_node = true; $found_node = true;
break; break;
@ -131,7 +132,7 @@
if($found_node) if($found_node)
{ {
unset($this->Versions[$count]); unset($this->versions[$count]);
$this->updateLatestVersion(); $this->updateLatestVersion();
return true; return true;
} }
@ -169,23 +170,23 @@
} }
$version = new VersionEntry(); $version = new VersionEntry();
$version->Version = $package->assembly->getVersion(); $version->setVersion($package->assembly->getVersion());
$version->Compiler = $package->header->CompilerExtension; $version->setCompiler($package->header->getCompilerExtension());
$version->ExecutionUnits = $package->execution_units; $version->setExecutionUnits($package->execution_units);
$version->MainExecutionPolicy = $package->main_execution_policy; $version->main_execution_policy = $package->main_execution_policy;
$version->Location = $install_path; $version->location = $install_path;
foreach($version->ExecutionUnits as $unit) foreach($version->getExecutionUnits() as $unit)
{ {
$unit->Data = null; $unit->setData(null);
} }
foreach($package->dependencies as $dependency) foreach($package->dependencies as $dependency)
{ {
$version->Dependencies[] = new DependencyEntry($dependency); $version->addDependency(new DependencyEntry($dependency));
} }
$this->Versions[] = $version; $this->versions[] = $version;
$this->updateLatestVersion(); $this->updateLatestVersion();
return true; return true;
} }
@ -199,9 +200,9 @@
{ {
$latest_version = null; $latest_version = null;
foreach($this->Versions as $version) foreach($this->versions as $version)
{ {
$version = $version->Version; $version = $version->getVersion();
if($latest_version === null) if($latest_version === null)
{ {
@ -215,7 +216,7 @@
} }
} }
$this->LatestVersion = $latest_version; $this->latest_version = $latest_version;
} }
/** /**
@ -223,7 +224,7 @@
*/ */
public function getLatestVersion(): ?string public function getLatestVersion(): ?string
{ {
return $this->LatestVersion; return $this->latest_version;
} }
/** /**
@ -235,12 +236,13 @@
{ {
$r = []; $r = [];
foreach($this->Versions as $version) foreach($this->versions as $version)
{ {
$r[] = $version->Version; $r[] = $version->getVersion();
} }
return $r; return $r;
} }
/** /**
@ -249,7 +251,7 @@
*/ */
public function getDataPath(): string public function getDataPath(): string
{ {
$path = PathFinder::getPackageDataPath($this->Name); $path = PathFinder::getPackageDataPath($this->name);
if(!file_exists($path) && Resolver::resolveScope() === Scopes::SYSTEM) if(!file_exists($path) && Resolver::resolveScope() === Scopes::SYSTEM)
{ {
@ -260,6 +262,38 @@
return $path; return $path;
} }
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return UpdateSource|null
*/
public function getUpdateSource(): ?UpdateSource
{
return $this->update_source;
}
/**
* @param UpdateSource|null $update_source
*/
public function setUpdateSource(?UpdateSource $update_source): void
{
$this->update_source = $update_source;
}
/** /**
* Returns an array representation of the object * Returns an array representation of the object
* *
@ -270,16 +304,16 @@
{ {
$versions = []; $versions = [];
foreach($this->Versions as $version) foreach($this->versions as $version)
{ {
$versions[] = $version->toArray($bytecode); $versions[] = $version->toArray($bytecode);
} }
return [ return [
($bytecode ? Functions::cbc('name') : 'name') => $this->Name, ($bytecode ? Functions::cbc('name') : 'name') => $this->name,
($bytecode ? Functions::cbc('latest_version') : 'latest_version') => $this->LatestVersion, ($bytecode ? Functions::cbc('latest_version') : 'latest_version') => $this->latest_version,
($bytecode ? Functions::cbc('versions') : 'versions') => $versions, ($bytecode ? Functions::cbc('versions') : 'versions') => $versions,
($bytecode ? Functions::cbc('update_source') : 'update_source') => ($this->UpdateSource?->toArray($bytecode)), ($bytecode ? Functions::cbc('update_source') : 'update_source') => ($this->update_source?->toArray($bytecode)),
]; ];
} }
@ -289,25 +323,25 @@
* @param array $data * @param array $data
* @return PackageEntry * @return PackageEntry
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): PackageEntry
{ {
$object = new self(); $object = new self();
$object->Name = Functions::array_bc($data, 'name'); $object->name = Functions::array_bc($data, 'name');
$object->LatestVersion = Functions::array_bc($data, 'latest_version'); $object->latest_version = Functions::array_bc($data, 'latest_version');
$object->UpdateSource = Functions::array_bc($data, 'update_source'); $object->update_source = Functions::array_bc($data, 'update_source');
$versions = Functions::array_bc($data, 'versions'); $versions = Functions::array_bc($data, 'versions');
if($object->UpdateSource !== null) if($object->update_source !== null)
{ {
$object->UpdateSource = UpdateSource::fromArray($object->UpdateSource); $object->update_source = UpdateSource::fromArray($object->update_source);
} }
if($versions !== null) if($versions !== null)
{ {
foreach($versions as $_datum) foreach($versions as $_datum)
{ {
$object->Versions[] = VersionEntry::fromArray($_datum); $object->versions[] = VersionEntry::fromArray($_datum);
} }
} }

View file

@ -1,83 +1,84 @@
<?php <?php
/* /*
* Copyright (c) Nosial 2022-2023, all rights reserved. * Copyright (c) Nosial 2022-2023, all rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without * associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions: * conditions:
* *
* The above copyright notice and this permission notice shall be included in all copies or substantial portions * The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software. * of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
* *
*/ */
/** @noinspection PhpMissingFieldTypeInspection */ /** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\PackageLock; namespace ncc\Objects\PackageLock;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Objects\InstallationPaths; use ncc\Objects\InstallationPaths;
use ncc\Objects\Package\ExecutionUnit; use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\Compiler; use ncc\Objects\ProjectConfiguration\Compiler;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
class VersionEntry class VersionEntry implements BytecodeObjectInterface
{ {
/** /**
* The version of the package that's installed * The version of the package that's installed
* *
* @var string * @var string
*/ */
public $Version; private $version;
/** /**
* The compiler extension used for the package * The compiler extension used for the package
* *
* @var Compiler * @var Compiler
*/ */
public $Compiler; private $compiler;
/** /**
* An array of packages that this package depends on * An array of packages that this package depends on
* *
* @var DependencyEntry[] * @var DependencyEntry[]
*/ */
public $Dependencies; private $dependencies;
/** /**
* @var ExecutionUnit[] * @var ExecutionUnit[]
*/ */
public $ExecutionUnits; public $execution_units;
/** /**
* The main execution policy for this version entry if applicable * The main execution policy for this version entry if applicable
* *
* @var string|null * @var string|null
*/ */
public $MainExecutionPolicy; public $main_execution_policy;
/** /**
* The path where the package is located * The path where the package is located
* *
* @var string * @var string
*/ */
public $Location; public $location;
/** /**
* Public Constructor * Public Constructor
*/ */
public function __construct() public function __construct()
{ {
$this->Dependencies = []; $this->dependencies = [];
$this->ExecutionUnits = []; $this->execution_units = [];
} }
/** /**
@ -87,7 +88,112 @@
*/ */
public function getInstallPaths(): InstallationPaths public function getInstallPaths(): InstallationPaths
{ {
return new InstallationPaths($this->Location); return new InstallationPaths($this->location);
}
/**
* @return string
*/
public function getVersion(): string
{
return $this->version;
}
/**
* @param string $version
*/
public function setVersion(string $version): void
{
$this->version = $version;
}
/**
* @return Compiler
*/
public function getCompiler(): Compiler
{
return $this->compiler;
}
/**
* @param Compiler $compiler
*/
public function setCompiler(Compiler $compiler): void
{
$this->compiler = $compiler;
}
/**
* @return array|DependencyEntry[]
*/
public function getDependencies(): array
{
return $this->dependencies;
}
/**
* @param array|DependencyEntry[] $dependencies
*/
public function setDependencies(array $dependencies): void
{
$this->dependencies = $dependencies;
}
/**
* @param DependencyEntry $dependency
* @return void
*/
public function addDependency(DependencyEntry $dependency): void
{
$this->dependencies[] = $dependency;
}
/**
* @return array|ExecutionUnit[]
*/
public function getExecutionUnits(): array
{
return $this->execution_units;
}
/**
* @param array|ExecutionUnit[] $execution_units
*/
public function setExecutionUnits(array $execution_units): void
{
$this->execution_units = $execution_units;
}
/**
* @return string|null
*/
public function getMainExecutionPolicy(): ?string
{
return $this->main_execution_policy;
}
/**
* @param string|null $main_execution_policy
*/
public function setMainExecutionPolicy(?string $main_execution_policy): void
{
$this->main_execution_policy = $main_execution_policy;
}
/**
* @return string
*/
public function getLocation(): string
{
return $this->location;
}
/**
* @param string $location
*/
public function setLocation(string $location): void
{
$this->location = $location;
} }
/** /**
@ -99,24 +205,24 @@
public function toArray(bool $bytecode=false): array public function toArray(bool $bytecode=false): array
{ {
$dependencies = []; $dependencies = [];
foreach($this->Dependencies as $dependency) foreach($this->dependencies as $dependency)
{ {
$dependencies[] = $dependency->toArray($bytecode); $dependencies[] = $dependency->toArray($bytecode);
} }
$execution_units = []; $execution_units = [];
foreach($this->ExecutionUnits as $executionUnit) foreach($this->execution_units as $executionUnit)
{ {
$execution_units[] = $executionUnit->toArray($bytecode); $execution_units[] = $executionUnit->toArray($bytecode);
} }
return [ return [
($bytecode ? Functions::cbc('version') : 'version') => $this->Version, ($bytecode ? Functions::cbc('version') : 'version') => $this->version,
($bytecode ? Functions::cbc('compiler') : 'compiler') => $this->Compiler->toArray(), ($bytecode ? Functions::cbc('compiler') : 'compiler') => $this->compiler->toArray(),
($bytecode ? Functions::cbc('dependencies') : 'dependencies') => $dependencies, ($bytecode ? Functions::cbc('dependencies') : 'dependencies') => $dependencies,
($bytecode ? Functions::cbc('execution_units') : 'execution_units') => $execution_units, ($bytecode ? Functions::cbc('execution_units') : 'execution_units') => $execution_units,
($bytecode ? Functions::cbc('main_execution_policy') : 'main_execution_policy') => $this->MainExecutionPolicy, ($bytecode ? Functions::cbc('main_execution_policy') : 'main_execution_policy') => $this->main_execution_policy,
($bytecode ? Functions::cbc('location') : 'location') => $this->Location, ($bytecode ? Functions::cbc('location') : 'location') => $this->location,
]; ];
} }
@ -126,20 +232,20 @@
* @param array $data * @param array $data
* @return VersionEntry * @return VersionEntry
*/ */
public static function fromArray(array $data): self public static function fromArray(array $data): VersionEntry
{ {
$object = new self(); $object = new self();
$object->Version = Functions::array_bc($data, 'version'); $object->version = Functions::array_bc($data, 'version');
$object->Compiler = Compiler::fromArray(Functions::array_bc($data, 'compiler')); $object->compiler = Compiler::fromArray(Functions::array_bc($data, 'compiler'));
$object->MainExecutionPolicy = Functions::array_bc($data, 'main_execution_policy'); $object->main_execution_policy = Functions::array_bc($data, 'main_execution_policy');
$object->Location = Functions::array_bc($data, 'location'); $object->location = Functions::array_bc($data, 'location');
$dependencies = Functions::array_bc($data, 'dependencies'); $dependencies = Functions::array_bc($data, 'dependencies');
if($dependencies !== null) if($dependencies !== null)
{ {
foreach($dependencies as $_datum) foreach($dependencies as $_datum)
{ {
$object->Dependencies[] = DependencyEntry::fromArray($_datum); $object->dependencies[] = DependencyEntry::fromArray($_datum);
} }
} }
@ -148,7 +254,7 @@
{ {
foreach($execution_units as $_datum) foreach($execution_units as $_datum)
{ {
$object->ExecutionUnits[] = ExecutionUnit::fromArray($_datum); $object->execution_units[] = ExecutionUnit::fromArray($_datum);
} }
} }

View file

@ -140,26 +140,26 @@
throw new ImportException(sprintf('Failed to check if package %s is imported', $package), $e); throw new ImportException(sprintf('Failed to check if package %s is imported', $package), $e);
} }
if($version_entry->Dependencies !== null && count($version_entry->Dependencies) > 0) if(count($version_entry->getDependencies()) > 0)
{ {
// Import all dependencies first // Import all dependencies first
/** @var Dependency $dependency */ /** @var Dependency $dependency */
foreach($version_entry->Dependencies as $dependency) foreach($version_entry->getDependencies() as $dependency)
{ {
self::import($dependency->PackageName, $dependency->getVersion(), $options); self::import($dependency->getPackageName(), $dependency->getVersion(), $options);
} }
} }
try try
{ {
switch($version_entry->Compiler->getExtension()) switch($version_entry->getCompiler()->getExtension())
{ {
case CompilerExtensions::PHP: case CompilerExtensions::PHP:
PhpRuntime::import($version_entry, $options); PhpRuntime::import($version_entry, $options);
break; break;
default: default:
throw new ImportException(sprintf('Compiler extension %s is not supported in this runtime', $version_entry->Compiler->getExtension())); throw new ImportException(sprintf('Compiler extension %s is not supported in this runtime', $version_entry->getCompiler()->getExtension()));
} }
} }
catch(Exception $e) catch(Exception $e)