<commit_before><?php

namespace EasyCorp\Bundle\EasyAdminBundle\Router;

use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Registry\CrudControllerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Registry\DashboardControllerRegistry;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
final class AdminUrlGenerator
{
    private $isInitialized;
    private $adminContextProvider;
    private $urlGenerator;
    private $dashboardControllerRegistry;
    private $crudControllerRegistry;
    private $urlSigner;
    private $dashboardRoute;
    private $includeReferrer;
    private $addSignature;
    private $routeParameters;
    private $currentPageReferrer;

    public function __construct(AdminContextProvider $adminContextProvider, UrlGeneratorInterface $urlGenerator, DashboardControllerRegistry $dashboardControllerRegistry, CrudControllerRegistry $crudControllerRegistry, UrlSigner $urlSigner)
    {
        $this->isInitialized = false;
        $this->adminContextProvider = $adminContextProvider;
        $this->urlGenerator = $urlGenerator;
        $this->dashboardControllerRegistry = $dashboardControllerRegistry;
        $this->crudControllerRegistry = $crudControllerRegistry;
        $this->urlSigner = $urlSigner;
    }

    public function setDashboard(string $dashboardControllerFqcn): self
    {
        $this->setRouteParameter(EA::DASHBOARD_CONTROLLER_FQCN, $dashboardControllerFqcn);

        return $this;
    }

    public function setCrudId(string $crudId): self
    {
        $crudControllerFqcn = $this->crudControllerRegistry->findCrudFqcnByCrudId($crudId);
        trigger_deprecation('easycorp/easyadmin-bundle', '3.2.0', 'The "setCrudId()" method of the "%s" service and the related "%s" query parameter are deprecated. Instead, use the CRUD Controller FQCN and the "setController()" method like this: ->setController(\'%s\').', __CLASS__, EA::CRUD_ID, str_replace('\\', '\\\\', $crudControllerFqcn));

        $this->setRouteParameter(EA::CRUD_CONTROLLER_FQCN, $crudControllerFqcn);

        return $this;
    }

    public function setController(string $crudControllerFqcn): self
    {
        $this->setRouteParameter(EA::CRUD_CONTROLLER_FQCN, $crudControllerFqcn);
        $this->unset(EA::ROUTE_NAME);
        $this->unset(EA::ROUTE_PARAMS);

        return $this;
    }

    public function setAction(string $action): self
    {
        $this->setRouteParameter(EA::CRUD_ACTION, $action);
        $this->unset(EA::ROUTE_NAME);
        $this->unset(EA::ROUTE_PARAMS);

        return $this;
    }

    public function setRoute(string $routeName, array $routeParameters = []): self
    {
        $this->unsetAllExcept(EA::MENU_INDEX, EA::SUBMENU_INDEX);
        $this->setRouteParameter(EA::ROUTE_NAME, $routeName);<commit_msg>bug #4413 Fixed the URL generation when using multiple dashboards (javiereguiluz)<commit_after><?php

namespace EasyCorp\Bundle\EasyAdminBundle\Router;

use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Registry\CrudControllerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Registry\DashboardControllerRegistry;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
 * @author <NAME> <<EMAIL>>
 */
final class AdminUrlGenerator
{
    private $isInitialized;
    private $adminContextProvider;
    private $urlGenerator;
    private $dashboardControllerRegistry;
    private $crudControllerRegistry;
    private $urlSigner;
    private $dashboardRoute;
    private $includeReferrer;
    private $addSignature;
    private $routeParameters;
    private $currentPageReferrer;

    public function __construct(AdminContextProvider $adminContextProvider, UrlGeneratorInterface $urlGenerator, DashboardControllerRegistry $dashboardControllerRegistry, CrudControllerRegistry $crudControllerRegistry, UrlSigner $urlSigner)
    {
        $this->isInitialized = false;
        $this->adminContextProvider = $adminContextProvider;
        $this->urlGenerator = $urlGenerator;
        $this->dashboardControllerRegistry = $dashboardControllerRegistry;
        $this->crudControllerRegistry = $crudControllerRegistry;
        $this->urlSigner = $urlSigner;
    }

    public function setDashboard(string $dashboardControllerFqcn): self
    {
        $this->setRouteParameter(EA::DASHBOARD_CONTROLLER_FQCN, $dashboardControllerFqcn);

        return $this;
    }

    public function setCrudId(string $crudId): self
    {
        $crudControllerFqcn = $this->crudControllerRegistry->findCrudFqcnByCrudId($crudId);
        trigger_deprecation('easycorp/easyadmin-bundle', '3.2.0', 'The "setCrudId()" method of the "%s" service and the related "%s" query parameter are deprecated. Instead, use the CRUD Controller FQCN and the "setController()" method like this: ->setController(\'%s\').', __CLASS__, EA::CRUD_ID, str_replace('\\', '\\\\', $crudControllerFqcn));

        $this->setRouteParameter(EA::CRUD_CONTROLLER_FQCN, $crudControllerFqcn);

        return $this;
    }

    public function setController(string $crudControllerFqcn): self
    {
        $this->setRouteParameter(EA::CRUD_CONTROLLER_FQCN, $crudControllerFqcn);
        $this->unset(EA::ROUTE_NAME);
        $this->unset(EA::ROUTE_PARAMS);

        return $this;
    }

    public function setAction(string $action): self
    {
        $this->setRouteParameter(EA::CRUD_ACTION, $action);
        $this->unset(EA::ROUTE_NAME);
        $this->unset(EA::ROUTE_PARAMS);

        return $this;
    }

    public function setRoute(string $routeName, array $routeParameters = []): self
    {
        $this->unsetAllExcept(EA::MENU_INDEX, EA::SUBMENU_INDEX, EA::DASHBOARD_CONTROLLER_FQCN);
        $this->setRouteParameter(EA::ROUTE_NAME, $routeName);
{'fraction_non_alphanumeric': 0.1088563787950291, 'fraction_numerical': 0.0015730690577316344, 'mean_word_length': 4.636524822695035, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '500588', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1883, 'n_words': 326}