/**
  * Returns the CrudService according to the given config.
  * @return AutoTablesCrudService
  */
 public function fetchCrudService(AutoTablesConfiguration $config)
 {
     if ($config->getServiceId()) {
         $this->logger->info(sprintf('Create CrudService from serviceId [%s]', $config->getServiceId()));
         $crudService = $this->get($config->getServiceId());
         Ensure::isNotNull($crudService, 'No service [%s] found', $crudService);
         Ensure::isTrue($crudService instanceof AutoTablesCrudService, 'Service [%s] has to implement %s', $config->getServiceId(), 'AutoTablesCrudService');
     } else {
         $this->logger->info(sprintf('Create CrudService from repositoryId [%s]', $config->getRepositoryId()));
         Ensure::isNotEmpty($config->getRepositoryId(), 'Neither [serviceId] nor [repositoryId] defined for datatables of type [%s]', $config->getId());
         $repository = $this->doctrine->getRepository($config->getRepositoryId());
         Ensure::isNotNull($repository, 'Repository with id [%s] not found', $config->getRepositoryId());
         $crudService = new RepositoryAutoTablesCrudService($this->doctrine->getManager(), $repository);
     }
     return $crudService;
 }