This package allows to define variable types or to declare PHP variables from already existing object types.
Using composer, you can install Type with the following command:
composer require sikessem/type
Define a variable 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);
}
}
Declare a variable with the defined type:
<?php
use App\Types\MyType;
$myVar = let(MyType::class, 'Hello');
$myVar->dump(); // Exit with the string 'Hello'
This library is distributed under the
Please send any sensitive issue to ske@sikessem.com. Thanks!