Elcodi\Store\ProductBundle\Controller\CategoryController::getCurrentCategoryGivenRequest PHP Метод

getCurrentCategoryGivenRequest() защищенный Метод

Given a request, return the current highlight-able category
protected getCurrentCategoryGivenRequest ( Request $request ) : Elcodi\Component\Product\Entity\Interfaces\CategoryInterface | null
$request Symfony\Component\HttpFoundation\Request Request
Результат Elcodi\Component\Product\Entity\Interfaces\CategoryInterface | null
    protected function getCurrentCategoryGivenRequest(Request $request)
    {
        $masterRoute = $request->get('_route');
        $category = null;
        /**
         * @var CategoryInterface $category
         * @var PurchasableInterface $purchasable
         */
        if ($masterRoute === 'store_purchasable_view') {
            $purchasableId = $request->get('id');
            $productRepository = $this->get('elcodi.repository.purchasable');
            $purchasable = $productRepository->find($purchasableId);
            $category = $purchasable->getPrincipalCategory();
        } elseif ($masterRoute === 'store_category_purchasables_list') {
            $categoryId = $request->get('id');
            $categoryRepository = $this->get('elcodi.repository.category');
            $category = $categoryRepository->find($categoryId);
        }
        return $category;
    }