Object Storage

Within a Container, objects are stored in an ObjectStorageInterface instance.

Centum\Container\ObjectStorage();

Centum\Container\ObjectStorage implements Centum\Interfaces\Container\ObjectStorageInterface.

You can obtain the Object Storage from a Container:

use Centum\Interfaces\Container\ContainerInterface;

/** @var ContainerInterface $container */

$objectStorage = $container->getObjectStorage();

Checking if an object exists

You can check if objects exist using the has() method:

use Centum\Interfaces\Container\ObjectStorageInterface;
use Centum\Interfaces\Router\RouterInterface;

/** @var ObjectStorageInterface $objectStorage */

if ($objectStorage->has(RouterInterface::class)) {
    echo "There is a `RouterInterface` in the object storage.";
} else {
    echo "`RouterInterface` is not in the object storage.";
}

If the object does not exist, then null will be returned.

Retrieving objects

Objects can be retreived using the get() method:

use Centum\Interfaces\Container\ObjectStorageInterface;
use Centum\Interfaces\Router\RouterInterface;

/** @var ObjectStorageInterface $objectStorage */

$router = $objectStorage->get(RouterInterface::class);

If the object does not exist, then null will be returned.

Specifying objects

Objects can be set using the set() method:

use Centum\Clock\Clock;
use Centum\Interfaces\Container\ObjectStorageInterface;
use Centum\Interfaces\Clock\ClockInterface;

/** @var ObjectStorageInterface $objectStorage */

$clock = new Clock();

$objectStorage->set(ClockInterface::class, $clock);

Removing objects

You can remove objects using the remove() method:

use Centum\Interfaces\Container\ObjectStorageInterface;
use Centum\Interfaces\Router\RouterInterface;

/** @var ObjectStorageInterface $objectStorage */

$objectStorage->remove(RouterInterface::class);