How to register a manager / reader

It can be useful to have a reader or manager interface when getting objects or lists of objects, so the object type can be enforced through an interface.

In order to let other packages only depend on the interface and not on DI packages, the managers and readers can be generated during the compile step of Alumio.

Given the following interface:

<?php
namespace Acme;

use Magement\SearchCriteria\SearchCriteriaInterface;

interface FooManagerInterface
{
public function getByIdentifier(string $identifier): FooInterface;

public function getList(SearchCriteriaInterface $criteria): FooIteratorInterface;

public function has(string $identifier): bool;

public function count(SearchCriteriaInterface $criteria): int;
}

The following is required to automatically generate an implementation:

{library}/magement/foo.manager.json

{
"$schema": "../../../magement/di/schema/register.manager.json",
"interface": "Acme\\FooManagerInterface",
"methods": [
{
"name": "getByIdentifier",
"type": "get"
},
{
"name": "getList",
"type": "list",
"interface": "Acme\\FooInterface",
"iterator": "Acme\\FooIterator"
},
{
"name": "has",
"type": "has",
"interface": "Acme\\FooInterface"
},
{
"name": "count",
"type": "count",
"interface": "Acme\\FooInterface"
}
]
}

This will generate a manager that is registered on the service: Acme\\FooManagerInterface. It uses dependency injection configuration under the hood to search and select the correct objects.