protected function getCategory($categoryId) { $category = $this->getContainer()->get('elcodi.repository.category')->find($categoryId); if (!$category instanceof ProductInterface) { throw new EntityNotFoundException(sprintf('Category with id %d was not found', $categoryId)); } return $category; }