| name | add-service |
| description | Add a new Laminas service (with factory) to this Omeka S module. Invoke with the service name, e.g. /add-service MyNewService |
Add a new service called $ARGUMENTS following the patterns in this module.
Steps
-
Create src/Service/$ARGUMENTS.php — the service class in namespace ExeLearning\Service.
-
Create src/Service/${ARGUMENTS}Factory.php — implements Laminas\ServiceManager\Factory\FactoryInterface:
namespace ExeLearning\Service;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
class ${ARGUMENTS}Factory implements FactoryInterface
{
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
{
return new $ARGUMENTS();
}
}
-
Register in config/module.config.php under service_manager.factories:
'service_manager' => [
'factories' => [
Service\$ARGUMENTS::class => Service\${ARGUMENTS}Factory::class,
],
],
-
Inject where needed — in a controller factory retrieve it with:
$myService = $services->get(\ExeLearning\Service\$ARGUMENTS::class);
-
Write a unit test in test/ExeLearningTest/Service/ using PHPUnit. Add stubs to test/Stubs/ for any new Omeka/Laminas collaborators not already stubbed.
Notes
- Factories are excluded from coverage requirements (see phpunit.xml).
- Common Omeka services:
Omeka\ApiManager, Omeka\EntityManager, Omeka\Logger, Omeka\Settings, Omeka\Acl.
- Use
$services->get('Config') for module config values.