Implemented php runtime functions into extension

https://git.n64.cc/nosial/ncc/-/issues/33
This commit is contained in:
Netkas 2022-12-15 00:57:53 -05:00
parent 0fbb374507
commit 7a7ceb319b

View file

@ -1,8 +1,15 @@
<?php <?php
if(defined('NCC_INIT') == false) use ncc\Abstracts\Versions;
use ncc\Exceptions\ConstantReadonlyException;
use ncc\Exceptions\ImportException;
use ncc\Exceptions\InvalidConstantNameException;
use ncc\ncc;
use ncc\Runtime;
if(!defined('NCC_INIT'))
{ {
if(file_exists('%ncc_install' . DIRECTORY_SEPARATOR . 'autoload.php') == false) if(!file_exists('%ncc_install' . DIRECTORY_SEPARATOR . 'autoload.php'))
{ {
throw new RuntimeException('Cannot locate file \'%ncc_install' . DIRECTORY_SEPARATOR . 'autoload.php\''); throw new RuntimeException('Cannot locate file \'%ncc_install' . DIRECTORY_SEPARATOR . 'autoload.php\'');
} }
@ -10,4 +17,99 @@
{ {
require('%ncc_install' . DIRECTORY_SEPARATOR . 'autoload.php'); require('%ncc_install' . DIRECTORY_SEPARATOR . 'autoload.php');
} }
if(!function_exists('import'))
{
/**
* Attempts to import a package into the current runtime
*
* @param string $package
* @param string $version
* @param array $options
* @return void
* @throws ImportException
*/
function import(string $package, string $version= Versions::Latest, array $options=[]): void
{
Runtime::import($package, $version, $options);
}
}
if(!function_exists('get_imported'))
{
/**
* Returns an array of all imported packages
*
* @return array
*/
function get_imported(): array
{
return Runtime::getImportedPackages();
}
}
if(!function_exists('ncc_constants'))
{
/**
* Returns an array of constants defined by NCC
*
* @return array
* @throws \ncc\Exceptions\RuntimeException
*/
function ncc_constants(): array
{
return ncc::getConstants();
}
}
if(!function_exists('consts_get'))
{
/**
* Returns the value of a constant defined in NCC's runtime environment
*
* @param string $package
* @param string $name
* @return string|null
*/
function consts_get(string $package, string $name): ?string
{
return Runtime\Constants::get($package, $name);
}
}
if(!function_exists('consts_set'))
{
/**
* Sets the value of a constant defined in NCC's runtime environment
*
* @param string $package
* @param string $name
* @param string $value
* @param bool $readonly
* @return void
* @throws ConstantReadonlyException
* @throws InvalidConstantNameException
*/
function consts_set(string $package, string $name, string $value, bool $readonly=false): void
{
Runtime\Constants::register($package, $name, $value, $readonly);
}
}
if(!function_exists('consts_delete'))
{
/**
* Deletes a constant defined in NCC's runtime environment
*
* @param string $package
* @param string $name
* @return void
* @throws ConstantReadonlyException
*/
function consts_delete(string $package, string $name): void
{
Runtime\Constants::delete($package, $name);
}
}
} }