Removed ExecutionPointer.php & Implemented ValidatableObjectInterface into BuildConfiguration.php

This commit is contained in:
Netkas 2023-09-26 17:33:14 -04:00
parent f62856b530
commit 9aba1cbf38
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
2 changed files with 31 additions and 137 deletions

View file

@ -1,131 +0,0 @@
<?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.
*
*/
/** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\ExecutionPointers;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Utilities\Functions;
class ExecutionPointer implements BytecodeObjectInterface
{
/**
* @var string
*/
private $id;
/**
* The execution policy for this execution unit
*
* @var ExecutionPolicy
*/
private $execution_policy;
/**
* The file pointer for where the target script should be executed
*
* @var string
*/
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
*
* @param ExecutionUnit|null $unit
* @param string|null $bin_file
*/
public function __construct(?ExecutionUnit $unit=null, ?string $bin_file=null)
{
if($unit === null)
{
return;
}
$this->id = $unit->getId();
$this->execution_policy = $unit->getExecutionPolicy();
$this->file_pointer = $bin_file;
}
/**
* Returns an array representation of the object
*
* @param bool $bytecode
* @return array
*/
public function toArray(bool $bytecode=false): array
{
return [
($bytecode ? Functions::cbc('id') : 'id') => $this->id,
($bytecode ? Functions::cbc('execution_policy') : 'execution_policy') => $this->execution_policy->toArray($bytecode),
($bytecode ? Functions::cbc('file_pointer') : 'file_pointer') => $this->file_pointer,
];
}
/**
* Constructs an object from an array representation
*
* @param array $data
* @return ExecutionPointer
*/
public static function fromArray(array $data): ExecutionPointer
{
$object = new self();
$object->id = Functions::array_bc($data, 'id');
$object->execution_policy = Functions::array_bc($data, 'execution_policy');
$object->file_pointer = Functions::array_bc($data, 'file_pointer');
if($object->execution_policy !== null)
{
$object->execution_policy = ExecutionPolicy::fromArray($object->execution_policy);
}
return $object;
}
}

View file

@ -26,7 +26,9 @@
use ncc\Enums\Types\BuildOutputType; use ncc\Enums\Types\BuildOutputType;
use ncc\Exceptions\ConfigurationException; use ncc\Exceptions\ConfigurationException;
use ncc\Exceptions\NotSupportedException;
use ncc\Interfaces\BytecodeObjectInterface; use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Interfaces\ValidatableObjectInterface;
use ncc\Objects\ProjectConfiguration\Dependency; use ncc\Objects\ProjectConfiguration\Dependency;
use ncc\Utilities\Functions; use ncc\Utilities\Functions;
use ncc\Utilities\Validate; use ncc\Utilities\Validate;
@ -35,7 +37,7 @@
* @author Zi Xing Narrakas * @author Zi Xing Narrakas
* @copyright Copyright (C) 2022-2023. Nosial - All Rights Reserved. * @copyright Copyright (C) 2022-2023. Nosial - All Rights Reserved.
*/ */
class BuildConfiguration implements BytecodeObjectInterface class BuildConfiguration implements BytecodeObjectInterface, ValidatableObjectInterface
{ {
/** /**
* The unique name of the build configuration * The unique name of the build configuration
@ -63,6 +65,13 @@
*/ */
private $output_path; private $output_path;
/**
* Optional. The name of the output file, eg; %ASSEMBLY.PACKAGE%.ncc
*
* @var string|null
*/
private $output_name;
/** /**
* An array of constants to define for the build when importing or executing. * An array of constants to define for the build when importing or executing.
* *
@ -118,11 +127,11 @@
/** /**
* Validates the BuildConfiguration object * Validates the BuildConfiguration object
* *
* @param bool $throw_exception * @return void
* @return bool
* @throws ConfigurationException * @throws ConfigurationException
* @throws NotSupportedException
*/ */
public function validate(): bool public function validate(): void
{ {
if(!Validate::nameFriendly($this->name)) if(!Validate::nameFriendly($this->name))
{ {
@ -164,8 +173,6 @@
{ {
$dependency->validate(); $dependency->validate();
} }
return True;
} }
/** /**
@ -244,6 +251,22 @@
$this->output_path = $output_path; $this->output_path = $output_path;
} }
/**
* @return string|null
*/
public function getOutputName(): ?string
{
return $this->output_name;
}
/**
* @param string|null $output_name
*/
public function setOutputName(?string $output_name): void
{
$this->output_name = $output_name;
}
/** /**
* @return array|string[] * @return array|string[]
*/ */
@ -407,6 +430,7 @@
$results[($bytecode ? Functions::cbc('name') : 'name')] = $this->name; $results[($bytecode ? Functions::cbc('name') : 'name')] = $this->name;
$results[($bytecode ? Functions::cbc('build_type') : 'build_type')] = $this->build_type; $results[($bytecode ? Functions::cbc('build_type') : 'build_type')] = $this->build_type;
$results[($bytecode ? Functions::cbc('output_path') : 'output_path')] = $this->output_path; $results[($bytecode ? Functions::cbc('output_path') : 'output_path')] = $this->output_path;
$results[($bytecode ? Functions::cbc('output_name') : 'output_path')] = $this->output_name;
if(count($this->options) > 0) if(count($this->options) > 0)
{ {
@ -462,6 +486,7 @@
$object = new BuildConfiguration($name, $output_path); $object = new BuildConfiguration($name, $output_path);
$object->output_name = Functions::array_bc($data, 'output_name');
$object->build_type = Functions::array_bc($data, 'build_type') ?? BuildOutputType::NCC_PACKAGE; $object->build_type = Functions::array_bc($data, 'build_type') ?? BuildOutputType::NCC_PACKAGE;
$object->options = Functions::array_bc($data, 'options') ?? []; $object->options = Functions::array_bc($data, 'options') ?? [];
$object->define_constants = Functions::array_bc($data, 'define_constants') ?? []; $object->define_constants = Functions::array_bc($data, 'define_constants') ?? [];