thijsrijpert / php-development-kit
JDK到PHP的端口
1.0.1
2024-07-05 11:07 UTC
Requires
- symfony/string: ^6.0
Requires (Dev)
- phpunit/phpunit: ^10
README
PHP Development Kit是一个将OpenJDK的核心接口和类移植到PHP的项目。
该项目仍在进行中,目前不应在生产环境中使用。
标准
PHP Developement Kit符合以下标准
- PSR-1 - 基本编码标准 (http://www.php-fig.org/psr/psr-1/)
- PSR-4 - 自动加载 (http://www.php-fig.org/psr/psr-4/)
- PSR-12 - 扩展编码风格指南 (http://www.php-fig.org/psr/psr-12/)
使用方法
所有与该库交互的类都应该扩展TObject或实现IObject
所有与该库交互的枚举都应该实现IObject并使用EnumTrait,使其与IObject兼容
对象示例(TBoolean,Shortend)
class TBoolean extends TObject implements Serializable, Comparable
{
/**
* Create a new boolean wrapper object
* @param bool $value the value being wrapped
*/
public function __construct(private readonly bool $value) { }
/**
* Returns the value of this Boolean object as a boolean
* primitive.
*
* @return bool the primitive boolean value of this object.
*/
public function booleanValue(): bool {
return $this->value;
}
/**
* Returns a Boolean instance representing the specified
* boolean value. If the specified boolean value
* is true, this method returns Boolean.TRUE;
* if it is false, this method returns Boolean.FALSE.
* If a new Boolean instance is not required, this method
* should generally be used in preference to the constructor
* {@link #Boolean(boolean)}, as this method is likely to yield
* significantly better space and time performance.
*
* @param bool|string $b a boolean value.
* @return TBoolean a Boolean instance representing b.
* @since 1.4
*/
public static function valueOf(bool|string $b): TBoolean {
if (GType::of($b)->isString()) {
$b = self::parseBoolean($b);
}
return $b ? new TBoolean(true) : new TBoolean(false);
}
/**
* Convert the internal value to a string representation
* @return string the string representation of the internal value
*/
public function toString(): string {
return $b ? "true" : "false";
}
/**
* Returns a hash code for this Boolean object.
*
* @return int the integer 1231 if this object represents
* true; returns the integer 1237 if this
* object represents false.
*/
public function hashCode(): int {
return $value ? 1231 : 1237;
}
/**
* Returns true if and only if the argument is not
* null and is a Boolean object that
* represents the same boolean value as this object.
*
* @param ?IObject $obj the object to compare with.
* @return bool true if the Boolean objects represent the
* same value; false otherwise.
*/
public function equals(?IObject $obj = null): bool {
if ($obj === null) {
return false;
}
if ($obj instanceof TBoolean) {
return $this->value == ($obj->booleanValue());
}
return false;
}
}
枚举示例(GType,Shortend)
enum GType implements IEnum
{
use EnumTrait;
case BOOLEAN;
case INTEGER;
case FLOAT;
case STRING;
case ARRAY;
case OBJECT;
case RESOURCE;
case RESOURCE_CLOSED;
case NULL;
case UNKNOWN;
/*
* Instance Methods
*/
/*
* Class methods
*/
}
测试
所有代码在发布前都应进行单元测试,目标是实现100%的测试覆盖率。
测试通过管道强制执行。
应假定在64位机器上执行编写测试。
许可
此存储库使用GPLv2带有类路径例外,更多详细信息请参阅
- LICENSE
- ADDITIONAL_LICENSE_INFO
我以任何方式都与Oracle或OpenJDK无关。