Removed unused Constants.php
This commit is contained in:
parent
234c6e955b
commit
4d317d61ab
2 changed files with 0 additions and 119 deletions
1
Makefile
1
Makefile
|
@ -45,7 +45,6 @@ $(SRC_PATH)/ncc/autoload_spl.php:
|
||||||
$(SRC_PATH)/ncc/Interfaces \
|
$(SRC_PATH)/ncc/Interfaces \
|
||||||
$(SRC_PATH)/ncc/Managers \
|
$(SRC_PATH)/ncc/Managers \
|
||||||
$(SRC_PATH)/ncc/Objects \
|
$(SRC_PATH)/ncc/Objects \
|
||||||
$(SRC_PATH)/ncc/Runtime \
|
|
||||||
$(SRC_PATH)/ncc/Utilities \
|
$(SRC_PATH)/ncc/Utilities \
|
||||||
$(SRC_PATH)/ncc/ncc.php \
|
$(SRC_PATH)/ncc/ncc.php \
|
||||||
$(SRC_PATH)/ncc/Runtime.php
|
$(SRC_PATH)/ncc/Runtime.php
|
||||||
|
|
|
@ -1,118 +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\Runtime;
|
|
||||||
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use ncc\Exceptions\IntegrityException;
|
|
||||||
use ncc\Objects\Constant;
|
|
||||||
use ncc\Utilities\Resolver;
|
|
||||||
use ncc\Utilities\Validate;
|
|
||||||
|
|
||||||
class Constants
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The registered constants in memory
|
|
||||||
*
|
|
||||||
* @var Constant[]
|
|
||||||
*/
|
|
||||||
private static $constants;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new constant
|
|
||||||
*
|
|
||||||
* @param string $scope The package name that owns this constant
|
|
||||||
* @param string $name The name of the constant
|
|
||||||
* @param string $value The value of the constant
|
|
||||||
* @param bool $readonly Indicates if the constant cannot be changed with the registerConstant function once it's registered
|
|
||||||
* @return void
|
|
||||||
* @throws IntegrityException
|
|
||||||
*/
|
|
||||||
public static function register(string $scope, string $name, string $value, bool $readonly=false): void
|
|
||||||
{
|
|
||||||
if(!Validate::constantName($name))
|
|
||||||
{
|
|
||||||
throw new InvalidArgumentException(sprintf('The name \'%s\' is not a valid constant name', $name));
|
|
||||||
}
|
|
||||||
|
|
||||||
$constant_hash = Resolver::resolveConstantHash($scope, $name);
|
|
||||||
|
|
||||||
if(isset(self::$constants[$constant_hash]))
|
|
||||||
{
|
|
||||||
self::$constants[$constant_hash]->setValue($value, $readonly);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self::$constants[$constant_hash] = new Constant($scope, $name, $value, $readonly);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes the constant
|
|
||||||
*
|
|
||||||
* @param string $scope
|
|
||||||
* @param string $name
|
|
||||||
* @return void
|
|
||||||
* @throws IntegrityException
|
|
||||||
*/
|
|
||||||
public static function delete(string $scope, string $name): void
|
|
||||||
{
|
|
||||||
if(!Validate::constantName($name))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$constant_hash = Resolver::resolveConstantHash($scope, $name);
|
|
||||||
|
|
||||||
if(isset(self::$constants[$constant_hash]) && self::$constants[$constant_hash]->isReadonly())
|
|
||||||
{
|
|
||||||
throw new IntegrityException('Cannot delete the constant \'' . self::$constants[$constant_hash]->getFullName() . '\', constant is readonly');
|
|
||||||
}
|
|
||||||
|
|
||||||
unset(self::$constants[$constant_hash]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the constant
|
|
||||||
*
|
|
||||||
* @param string $scope
|
|
||||||
* @param string $name
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public static function get(string $scope, string $name): ?string
|
|
||||||
{
|
|
||||||
if(!Validate::constantName($name))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$constant_hash = Resolver::resolveConstantHash($scope, $name);
|
|
||||||
|
|
||||||
if(isset(self::$constants[$constant_hash]))
|
|
||||||
{
|
|
||||||
return self::$constants[$constant_hash]->getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue