<?php
/**
 * Created by PhpStorm.
 * User: silas
 * Date: 17.10.18
 * Time: 16:47
 */

namespace Application\Factory\Model\Manager;

use Application\Model\Level;
use Application\Model\Manager\LevelManager;
use Application\Model\Manager\WordManager;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;

class LevelManagerFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        return $this->createService($container, $requestedName);
    }

    public function createService(ContainerInterface $serviceLocator, $managerName)
    {
        $em = $serviceLocator->get('doctrine.entitymanager.orm_default');
        /** @var WordManager $wordManager */
        $wordManager = $serviceLocator->get(WordManager::class);
        return new LevelManager($em->getRepository(Level::class), $wordManager);
    }
}