wearelaradev/callables

Callables trait

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 1

Open Issues: 0

Type:package

pkg:composer/wearelaradev/callables

dev-main 2024-04-11 18:35 UTC

This package is not auto-updated.

Last update: 2025-12-20 00:44:44 UTC


README

This php package allows any php object to create magic getter, setter and adder functions. This avoids creating a multitude of methods that are not always optimal to read.

Getting started

    composer require wearelaradev/callables

Usage

use Laradev\Callables\Callables;

class MyObject 
{
    use Callables;
    
    public string $foo = "foo";
    protected string $bar = "bar";
    private string $toto = "toto";
    private array $arr = [];
}

var_dump((new MyObject())->getBar());
//output: "bar"

$obj = (new MyObject())
    ->setFoo("foo1")
    ->setToto("toto1")
    ->addArr("test")
;

var_dump(["foo" => $obj->getFoo(), "toto" => $obj->getToto(), "arr" => $obj->getArr()]);
// output: ["foo" => "foo1", "toto" => "toto1", "arr" => ["test"]];

Additional information

If you encounter a bug or have any ideas for improvement, don't hesitate to send me a PR or contact me via email at florian@laradev.ca :)