decodelabs / gadgets
Useful tools for building PHP libraries
Installs: 3 370
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ^7.2|^8.0
- decodelabs/exceptional: ^0.3
Requires (Dev)
README
Useful tools for building PHP libraries.
Installation
Install via Composer:
composer require decodelabs/gadgets
PHP version
Please note, the final v1 releases of all Decode Labs libraries will target PHP8 or above.
Current support for earlier versions of PHP will be phased out in the coming months.
Usage
Method chaining
The Then
interface for structured method chaining has been moved to its own project, Fluidity.
Constraints
namespace DecodeLabs\Gadgets\Constraint; interface Disableable { public function isDisabled(): bool; public function setDisabled(bool $disabled): Disableable; } interface Nullable { public function isNullable(): bool; public function setNullable(bool $nullable): Nullable; } interface Immutable { public function isImmutable(): bool; public function setImmutable(bool $immutable): Immutable; } interface Requirable { public function isRequired(): bool; public function setRequired(bool $required): Requirable; }
Add common constraints to your objects.
Sanitizer
Add basic input value sanitizing to your objects by returning a Sanitizer
.
use DecodeLabs\Gadgets\Sanitizer; $test = new class { public $value = 'my value'; public function sanitizeValue(bool $required=true): Sanitizer { return new Sanitizer($this->value, $required); } } $myString = $test->sanitizeValue()->asString(); // All good $myInt = $test->sanitizeValue()->asInt(); // Will try to convert to int
Licensing
Gadgets is licensed under the MIT License. See LICENSE for the full license text.