Initial Codebase, Added Assembly with validation

This commit is contained in:
Zi Xing 2022-04-06 22:17:14 -04:00
parent 51a7296894
commit 7cbb50e095
21 changed files with 553 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View file

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

8
.idea/modules.xml generated Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ncc.iml" filepath="$PROJECT_DIR$/.idea/ncc.iml" />
</modules>
</component>
</project>

10
.idea/ncc.iml generated Normal file
View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

14
.idea/webResources.xml generated Normal file
View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WebResourcesPaths">
<contentEntries>
<entry url="file://$PROJECT_DIR$">
<entryData>
<resourceRoots>
<path value="file://$PROJECT_DIR$/templates" />
</resourceRoots>
</entryData>
</entry>
</contentEntries>
</component>
</project>

View file

@ -0,0 +1 @@
,netkas,netkas-desktop,06.04.2022 21:07,file:///home/netkas/.config/libreoffice/4;

Binary file not shown.

View file

@ -0,0 +1,13 @@
<?php
namespace ncc\Abstracts;
use ncc\Exceptions\InvalidProjectConfigurationException;
abstract class ExceptionCodes
{
/**
* @see InvalidProjectConfigurationException
*/
const InvalidProjectConfigurationException = -1700;
}

View file

@ -0,0 +1,16 @@
<?php
namespace ncc\Abstracts;
abstract class RegexPatterns
{
const UUIDv4 = '/[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-4[0-9A-Za-z]{3}-[89ABab][0-9A-Za-z]{3}-[0-9A-Za-z]{12}/m';
const PackageNameFormat = '/^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/';
const ComposerVersionFormat = '/^([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/';
const PythonVersionFormat = '/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/';
const SemanticVersioning2 = '/^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/m';
}

View file

@ -0,0 +1,36 @@
<?php
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
use Throwable;
class InvalidProjectConfigurationException extends Exception
{
/**
* @var Throwable|null
*/
private ?Throwable $previous;
/**
* The full property name that needs correcting
*
* @var string|null
*/
private ?string $property;
/**
* @param string $message
* @param string|null $property
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?string $property=null, ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::InvalidProjectConfigurationException, $previous);
$this->message = $message;
$this->previous = $previous;
$this->property = $property;
}
}

View file

@ -0,0 +1,54 @@
<?php
namespace ncc\Objects;
use ncc\Objects\ProjectConfiguration\Assembly;
use ncc\Objects\ProjectConfiguration\Build;
use ncc\Objects\ProjectConfiguration\Project;
class ProjectConfiguration
{
/**
* The project configuration
*
* @var Project
*/
public $Project;
/**
* Assembly information for the build output
*
* @var Assembly
*/
public $Assembly;
/**
* Build configuration for the project
*
* @var Build
*/
public $Build;
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [];
}
/**
* Constructs the object from an array representation
*
* @param array $data
* @return ProjectConfiguration
*/
public static function fromArray(array $data): ProjectConfiguration
{
$ProjectConfigurationObject = new ProjectConfiguration();
return $ProjectConfigurationObject;
}
}

View file

@ -0,0 +1,202 @@
<?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Objects\ProjectConfiguration;
use ncc\Abstracts\RegexPatterns;
use ncc\Exceptions\InvalidProjectConfigurationException;
use ncc\Utilities\Functions;
use ncc\Utilities\Validate;
class Assembly
{
/**
* The software name
*
* @var string
*/
public $Name;
/**
* The package name used to identify the package
*
* @var string
*/
public $Package;
/**
* The software description
*
* @var string|null
*/
public $Description;
/**
* @var string|null
*/
public $Company;
/**
* The product name
*
* @var string|null
*/
public $Product;
/**
* The copyright header for the product
*
* @var string|null
*/
public $Copyright;
/**
* Product trademark
*
* @var string|null
*/
public $Trademark;
/**
* Software version
*
* @var string
*/
public $Version;
/**
* Universally Unique Identifier
*
* @var string
*/
public $UUID;
/**
* Validates the object information to detect possible errors
*
* @param bool $throw_exception
* @return bool
* @throws InvalidProjectConfigurationException
*/
public function validate(bool $throw_exception=false): bool
{
if(preg_match(RegexPatterns::UUIDv4, $this->UUID) == false)
{
if($throw_exception)
throw new InvalidProjectConfigurationException('The UUID is not a valid v4 UUID', 'Assembly.UUID');
return false;
}
if(Validate::version($this->Version) == false)
{
if($throw_exception)
throw new InvalidProjectConfigurationException('The version number is invalid', 'Assembly.Version');
return false;
}
if(preg_match(RegexPatterns::PackageNameFormat, $this->Package) == false)
{
if($throw_exception)
throw new InvalidProjectConfigurationException('The package name is invalid', 'Assembly.Package');
return false;
}
if(strlen($this->Name) > 40)
{
if($throw_exception)
throw new InvalidProjectConfigurationException('The name cannot be larger than 40 characters', 'Assembly.Name');
return false;
}
if(strlen($this->Description) > 512)
{
if($throw_exception)
throw new InvalidProjectConfigurationException('The description cannot be larger than 512 characters', 'Assembly.Description');
return false;
}
if(strlen($this->Company) > 126)
{
if($throw_exception)
throw new InvalidProjectConfigurationException('The company cannot be larger than 126 characters', 'Assembly.Company');
return false;
}
if(strlen($this->Product) > 64)
{
if($throw_exception)
throw new InvalidProjectConfigurationException('The company cannot be larger than 64 characters', 'Assembly.Product');
return false;
}
if(strlen($this->Copyright) > 64)
{
if($throw_exception)
throw new InvalidProjectConfigurationException('The copyright cannot be larger than 64 characters', 'Assembly.Copyright');
return false;
}
if(strlen($this->Trademark) > 64)
{
if($throw_exception)
throw new InvalidProjectConfigurationException('The trademark cannot be larger than 64 characters', 'Assembly.Trademark');
return false;
}
return true;
}
/**
* Returns an array representation of the object
*
* @param bool $bytecode
* @return array
*/
public function toArray(bool $bytecode=false): array
{
return [
($bytecode ? Functions::cbc('name') : 'name') => $this->Name,
($bytecode ? Functions::cbc('package') : 'package') => $this->Package,
($bytecode ? Functions::cbc('description') : 'description') => ($this->Description !== null && strlen($this->Description) > 0 ? $this->Description : null),
($bytecode ? Functions::cbc('company') : 'company') => ($this->Company !== null && strlen($this->Company) > 0 ? $this->Company : null),
($bytecode ? Functions::cbc('product') : 'product') => ($this->Product !== null && strlen($this->Product) > 0 ? $this->Product : null),
($bytecode ? Functions::cbc('copyright') : 'copyright') => ($this->Copyright !== null && strlen($this->Copyright) > 0 ? $this->Copyright : null),
($bytecode ? Functions::cbc('trademark') : 'trademark') => ($this->Trademark !== null && strlen($this->Trademark) > 0 ? $this->Trademark : null),
($bytecode ? Functions::cbc('version') : 'version') => $this->Version,
($bytecode ? Functions::cbc('uid') : 'uid') => $this->UUID,
];
}
/**
* Constructs object from an array representation
*
* @param array $data
* @return Assembly
*/
public static function fromArray(array $data): Assembly
{
$AssemblyObject = new Assembly();
$AssemblyObject->Name = Functions::array_bc($data, 'name');
$AssemblyObject->Package = Functions::array_bc($data, 'package');
$AssemblyObject->Description = Functions::array_bc($data, 'description');
$AssemblyObject->Company = Functions::array_bc($data, 'company');
$AssemblyObject->Product = Functions::array_bc($data, 'product');
$AssemblyObject->Copyright = Functions::array_bc($data, 'copyright');
$AssemblyObject->Trademark = Functions::array_bc($data, 'trademark');
$AssemblyObject->Version = Functions::array_bc($data, 'version');
$AssemblyObject->UUID = Functions::array_bc($data, 'uid');
return $AssemblyObject;
}
}

View file

@ -0,0 +1,8 @@
<?php
namespace ncc\Objects\ProjectConfiguration;
class Build
{
}

View file

@ -0,0 +1,8 @@
<?php
namespace ncc\Objects\ProjectConfiguration;
class BuildConfiguration
{
}

View file

@ -0,0 +1,8 @@
<?php
namespace ncc\Objects\ProjectConfiguration;
class Compiler
{
}

View file

@ -0,0 +1,8 @@
<?php
namespace ncc\Objects\ProjectConfiguration;
class Dependency
{
}

View file

@ -0,0 +1,8 @@
<?php
namespace ncc\Objects\ProjectConfiguration;
class Project
{
}

View file

@ -0,0 +1,36 @@
<?php
namespace ncc\Utilities;
class Functions
{
/**
* Calculates a byte-code representation of the input using CRC32
*
* @param string $input
* @return int
*/
public static function cbc(string $input): int
{
return hexdec(hash('crc32', $input));
}
/**
* Returns the specified of a value of an array using plaintext, if none is found it will
* attempt to use the cbc method to find the selected input, if all fails then null will be returned.
*
* @param array $data
* @param string $select
* @return mixed|null
*/
public static function array_bc(array $data, string $select)
{
if(isset($data[$select]))
return $data[$select];
if(isset($data[self::cbc($select)]))
return $data[self::cbc($select)];
return null;
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace ncc\Utilities;
use ncc\Abstracts\RegexPatterns;
class Validate
{
/**
* Validates the version number
*
* @param string $input
* @return bool
*/
public static function version(string $input): bool
{
if(preg_match(RegexPatterns::SemanticVersioning2, $input))
return true;
if(preg_match(RegexPatterns::ComposerVersionFormat, $input))
return true;
if(preg_match(RegexPatterns::PythonVersionFormat, $input))
return true;
return false;
}
}

21
src/ncc/ncc.php Normal file
View file

@ -0,0 +1,21 @@
<?php
namespace ncc;
/**
*
* @author netkas
*
*/
class ncc
{
/**
* NCC Public Constructor
*/
public function __construct()
{
}
}

60
templates/project.json Normal file
View file

@ -0,0 +1,60 @@
{
"project": {
"compiler": {
"extension": "php",
"minimum_version": "7.4",
"maximum_version": "8.1"
},
"options": {}
},
"assembly":{
"name": "Example",
"package": "com.example.library",
"description": "An example project for NCC to build",
"company": null,
"product": null,
"copyright": "Copyright (c) Test 2022",
"trademark": null,
"version": "1.0.0.0",
"uid": "4aaa878e-b600-11ec-b909-0242ac120002"
},
"build": {
"source_path": "src/ExampleLibrary",
"default_configuration": "debug",
"exclude_files": [
"README.md"
],
"options": {},
"scope": "user",
"define_constants": ["%ASSEMBLY.NAME%_HELLO"],
"dependencies": [
{"name": "mbstring", "source": "extension", "version": "latest"},
{"name": "com.example.dependency", "source": "default@github/example/ncc_dependency", "version": "latest"},
{"name": "com.symfony.process", "source": "symfony@cmoposer/process", "version": "latest"}
],
"configurations": [
{
"name": "debug",
"options": {},
"static_linking": true,
"output_path": "build/debug",
"define_constants": ["%ASSEMBLY.NAME%_DEBUG"],
"strict_constants": false,
"exclude_files": [],
"dependencies": [
{"name": "x-debug", "source": "extension", "version": "latest"}
]
},
{
"name": "release",
"options": {},
"static_linking": true,
"output_path": "build/release",
"define_constants": [],
"strict_constants": false,
"exclude_files": [],
"dependencies": []
}
]
}
}