<?php

declare(strict_types=1);

namespace App\Plates;

use Doctrine\ORM\EntityManager;
use Psr\Container\ContainerInterface;
use Zend\Expressive\Plates\Exception\MissingHelperException;
use Zend\Expressive\Router\RouterInterface;

class NavigationExtensionFactory
{
    public function __invoke(ContainerInterface $container) : NavigationExtension
    {
        if (! $container->has(RouterInterface::class)) {
            throw new MissingHelperException(sprintf(
                '%s requires that the %s service be present; not found',
                NavigationExtension::class,
                RouterInterface::class
            ));
        }

        $router = $container->get(RouterInterface::class);
        $entityManager = $container->get(EntityManager::class);
        return new NavigationExtension($router, $entityManager);
    }
}
