Skip to content

siguici/type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SIKessEm logo

Customize Object-Oriented PHP Variable Types

This package allows to define variable types or to declare PHP variables from already existing object types.

Installation

Using composer, you can install Type with the following command:

composer require sikessem/type

Usage

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'

License

This library is distributed under the License

Security Reports

Please send any sensitive issue to ske@sikessem.com. Thanks!