Useful tools for building PHP libraries

v0.8.0 2022-03-09 11:48 UTC

This package is auto-updated.

Last update: 2022-08-10 11:42:36 UTC


PHP from Packagist Latest Version Total Downloads GitHub Workflow Status PHPStan License

Useful tools for building PHP libraries.


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.


Method chaining

The Then interface for structured method chaining has been moved to its own project, Fluidity.


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.


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


Gadgets is licensed under the MIT License. See LICENSE for the full license text.