cyclessem / type
自定义面向对象的PHP变量类型
0.0.0
2022-09-13 02:04 UTC
Requires
- php: ^8.0.22
Requires (Dev)
- pestphp/pest: ^1.22
README

自定义面向对象的PHP变量类型
此包允许定义变量类型或从已存在的对象类型中声明PHP变量。
安装
使用Composer,您可以使用以下命令安装Type
composer require sikessem/type
使用方法
定义变量类型
<?php namespace App\Types; use Sikessem\Type\Statement; class MyType implements Statement { public function __construct(protected string $value) { $this->setValue($value); } protected string $value; public function setValue(string $value): self { $this->value = $value; return $this; } public function getValue(): string { return $this->value; } public function dump(): void { exit($this->value); } // The method to define to parse a value public static function parse(mixed $value): self { return new self((string)$value); } }
声明具有定义类型的变量
<?php use App\Types\MyType; $myVar = let(MyType::class, 'Hello'); $myVar->dump(); // Exit with the string 'Hello'
许可证
安全报告
请将任何敏感问题发送至ske@sikessem.com。谢谢!