<?php

namespace App\Model\Services;


use Kdyby\Doctrine\EntityManager;
use Kdyby\Doctrine\EntityRepository;

abstract class BaseService
{
    /** @var EntityManager */
    private $entityManager;

    /**
     * BaseService constructor.
     * @param $entityManager
     */
    public function __construct(EntityManager $entityManager)
    {
        $this->entityManager = $entityManager;

        $this->startup();
    }

    /**
     * @param $repositoryName
     * @return EntityRepository
     */
    protected function getRepository($repositoryName)
    {
        return $this->entityManager->getRepository($repositoryName);
    }

    /**
     * @param $entity
     */
    protected function persist($entity)
    {
        $this->entityManager->persist($entity);
    }

    protected function startup()
    {
        // override this
    }

}