zloynick/joole-containers

v8.1.3 2022-04-26 11:35 UTC

This package is not auto-updated.

Last update: 2024-05-08 18:20:49 UTC


README

Joole Containers is a library for storing objects. At its core, it is an implementation of PSR-12 and its complement.

Getting started

  • Install it with using composer:
composer require zloynick/joole-containers

Using

  • Create a container object:

use joole\containers\Container;

$container = new Container();
...

  • Register your object to created container:
...
class MyCustomPeople{

    private string $age;
    private string $name;

    public function __construct(
        $name,
        $age
    )
    {
        $this->name = $name;
        $this->age = $age;
    }

    public function getName(): string
    {
        return $this->name;
    }

}

$container->register(MyCustomPeople::class, ['name' => 'Alex', 'age' => 22]);
...

Now we can use the object from the container


...
echo $container->get(MyCustomPeople::class)->getName();// Alex
...

Addition functional

  • You can get number of object in container: $count = count($container);
  • Multiple push:

$container->multiplePush(['param1' => [1, 2, 3], 'param2' => new stdClass()], Class1::class, Class2::class);

Note: the keys of the array of parameters must correspond to the name of the variables of the constructor classthe keys of the array of parameters must correspond to the name of the variables of the constructor class.