1.0.0 Alpha Release #59

Merged
netkas merged 213 commits from v1.0.0_alpha into master 2023-01-29 23:27:58 +00:00
Showing only changes of commit 334c40c1f3 - Show all commits

View file

@ -2,12 +2,16 @@
namespace ncc\Classes\PhpExtension; namespace ncc\Classes\PhpExtension;
use Exception;
use ncc\Abstracts\Options\RuntimeImportOptions; use ncc\Abstracts\Options\RuntimeImportOptions;
use ncc\Exceptions\AccessDeniedException; use ncc\Classes\NccExtension\ConstantCompiler;
use ncc\Exceptions\FileNotFoundException; use ncc\Exceptions\ConstantReadonlyException;
use ncc\Exceptions\IOException; use ncc\Exceptions\ImportException;
use ncc\Exceptions\InvalidConstantNameException;
use ncc\Interfaces\RuntimeInterface; use ncc\Interfaces\RuntimeInterface;
use ncc\Objects\PackageLock\VersionEntry; use ncc\Objects\PackageLock\VersionEntry;
use ncc\Objects\ProjectConfiguration\Assembly;
use ncc\Runtime\Constants;
use ncc\Utilities\IO; use ncc\Utilities\IO;
use ncc\ZiProto\ZiProto; use ncc\ZiProto\ZiProto;
@ -20,14 +24,57 @@
* @param VersionEntry $versionEntry * @param VersionEntry $versionEntry
* @param array $options * @param array $options
* @return bool * @return bool
* @throws AccessDeniedException * @throws ImportException
* @throws FileNotFoundException
* @throws IOException
*/ */
public static function import(VersionEntry $versionEntry, array $options=[]): bool public static function import(VersionEntry $versionEntry, array $options=[]): bool
{ {
$autoload_path = $versionEntry->getInstallPaths()->getBinPath() . DIRECTORY_SEPARATOR . 'autoload.php'; $autoload_path = $versionEntry->getInstallPaths()->getBinPath() . DIRECTORY_SEPARATOR . 'autoload.php';
$static_files = $versionEntry->getInstallPaths()->getBinPath() . DIRECTORY_SEPARATOR . 'static_autoload.bin'; $static_files = $versionEntry->getInstallPaths()->getBinPath() . DIRECTORY_SEPARATOR . 'static_autoload.bin';
$constants_path = $versionEntry->getInstallPaths()->getDataPath() . DIRECTORY_SEPARATOR . 'const';
$assembly_path = $versionEntry->getInstallPaths()->getDataPath() . DIRECTORY_SEPARATOR . 'assembly';
if(!file_exists($assembly_path))
throw new ImportException('Cannot locate assembly file \'' . $assembly_path . '\'');
try
{
$assembly_content = ZiProto::decode(IO::fread($assembly_path));
$assembly = Assembly::fromArray($assembly_content);
}
catch(Exception $e)
{
throw new ImportException('Failed to load assembly file \'' . $assembly_path . '\': ' . $e->getMessage());
}
if(file_exists($constants_path))
{
try
{
$constants = ZiProto::decode(IO::fread($constants_path));
}
catch(Exception $e)
{
throw new ImportException('Failed to load constants file \'' . $constants_path . '\': ' . $e->getMessage());
}
foreach($constants as $name => $value)
{
$value = ConstantCompiler::compileRuntimeConstants($value);
try
{
Constants::register($assembly->Package, $name, $value, true);
}
catch (ConstantReadonlyException $e)
{
trigger_error('Constant \'' . $name . '\' is readonly (' . $assembly->Package . ')', E_USER_WARNING);
}
catch (InvalidConstantNameException $e)
{
throw new ImportException('Invalid constant name \'' . $name . '\' (' . $assembly->Package . ')', $e);
}
}
}
if(file_exists($autoload_path) && !in_array(RuntimeImportOptions::ImportAutoloader, $options)) if(file_exists($autoload_path) && !in_array(RuntimeImportOptions::ImportAutoloader, $options))
{ {
@ -35,11 +82,19 @@
} }
if(file_exists($static_files) && !in_array(RuntimeImportOptions::ImportStaticFiles, $options)) if(file_exists($static_files) && !in_array(RuntimeImportOptions::ImportStaticFiles, $options))
{
try
{ {
$static_files = ZiProto::decode(IO::fread($static_files)); $static_files = ZiProto::decode(IO::fread($static_files));
foreach($static_files as $file) foreach($static_files as $file)
require_once($file); require_once($file);
} }
catch(Exception $e)
{
throw new ImportException('Failed to load static files: ' . $e->getMessage(), $e);
}
}
if(!file_exists($autoload_path) && !file_exists($static_files)) if(!file_exists($autoload_path) && !file_exists($static_files))
return false; return false;