An open API service indexing awesome lists of open source software.

https://github.com/siguici/typed

Customize Object-Oriented PHP Variable Types
https://github.com/siguici/typed

oop oriented-object-programming php8 sikessem type-library var-type

Last synced: 6 days ago
JSON representation

Customize Object-Oriented PHP Variable Types

Awesome Lists containing this project

README

        

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](https://getcomposer.org/), you can install Type with the following command:

```bash
composer require sikessem/type
```

## Usage

Define a variable type:

```php
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
dump(); // Exit with the string 'Hello'

```

## License

This library is distributed under the [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

## Security Reports

Please send any sensitive issue to [[email protected]](mailto:[email protected]). Thanks!