cyclessem / type

自定义面向对象的PHP变量类型

0.0.0 2022-09-13 02:04 UTC

This package is auto-updated.

Last update: 2024-09-13 06:19:03 UTC


README

SIKessEm logo

自定义面向对象的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'

许可证

此库在License下分发

安全报告

请将任何敏感问题发送至ske@sikessem.com。谢谢!