Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Interface for AdminUrlGenerator and replaced declarations in pr… #5909

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/ArgumentResolver/BatchActionDtoResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
Expand All @@ -18,9 +18,9 @@
final class BatchActionDtoResolver implements ValueResolverInterface
{
private AdminContextProvider $adminContextProvider;
private AdminUrlGenerator $adminUrlGenerator;
private AdminUrlGeneratorInterface $adminUrlGenerator;

public function __construct(AdminContextProvider $adminContextProvider, AdminUrlGenerator $adminUrlGenerator)
public function __construct(AdminContextProvider $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator)
{
$this->adminContextProvider = $adminContextProvider;
$this->adminUrlGenerator = $adminUrlGenerator;
Expand Down Expand Up @@ -54,9 +54,9 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
final class BatchActionDtoResolver implements ArgumentValueResolverInterface
{
private AdminContextProvider $adminContextProvider;
private AdminUrlGenerator $adminUrlGenerator;
private AdminUrlGeneratorInterface $adminUrlGenerator;

public function __construct(AdminContextProvider $adminContextProvider, AdminUrlGenerator $adminUrlGenerator)
public function __construct(AdminContextProvider $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator)
{
$this->adminContextProvider = $adminContextProvider;
$this->adminUrlGenerator = $adminUrlGenerator;
Expand Down
6 changes: 3 additions & 3 deletions src/Factory/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use EasyCorp\Bundle\EasyAdminBundle\Translation\TranslatableMessageBuilder;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -26,10 +26,10 @@ final class ActionFactory
{
private AdminContextProvider $adminContextProvider;
private AuthorizationCheckerInterface $authChecker;
private AdminUrlGenerator $adminUrlGenerator;
private AdminUrlGeneratorInterface $adminUrlGenerator;
private ?CsrfTokenManagerInterface $csrfTokenManager;

public function __construct(AdminContextProvider $adminContextProvider, AuthorizationCheckerInterface $authChecker, AdminUrlGenerator $adminUrlGenerator, ?CsrfTokenManagerInterface $csrfTokenManager = null)
public function __construct(AdminContextProvider $adminContextProvider, AuthorizationCheckerInterface $authChecker, AdminUrlGeneratorInterface $adminUrlGenerator, ?CsrfTokenManagerInterface $csrfTokenManager = null)
{
$this->adminContextProvider = $adminContextProvider;
$this->authChecker = $authChecker;
Expand Down
6 changes: 3 additions & 3 deletions src/Factory/MenuFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Dto\UserMenuDto;
use EasyCorp\Bundle\EasyAdminBundle\Menu\MenuItemMatcherInterface;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
Expand All @@ -26,10 +26,10 @@ final class MenuFactory
private AdminContextProvider $adminContextProvider;
private AuthorizationCheckerInterface $authChecker;
private LogoutUrlGenerator $logoutUrlGenerator;
private AdminUrlGenerator $adminUrlGenerator;
private AdminUrlGeneratorInterface $adminUrlGenerator;
private MenuItemMatcherInterface $menuItemMatcher;

public function __construct(AdminContextProvider $adminContextProvider, AuthorizationCheckerInterface $authChecker, LogoutUrlGenerator $logoutUrlGenerator, AdminUrlGenerator $adminUrlGenerator, MenuItemMatcherInterface $menuItemMatcher)
public function __construct(AdminContextProvider $adminContextProvider, AuthorizationCheckerInterface $authChecker, LogoutUrlGenerator $logoutUrlGenerator, AdminUrlGeneratorInterface $adminUrlGenerator, MenuItemMatcherInterface $menuItemMatcher)
{
$this->adminContextProvider = $adminContextProvider;
$this->authChecker = $authChecker;
Expand Down
6 changes: 3 additions & 3 deletions src/Field/Configurator/AssociationConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\CrudAutocompleteType;
use EasyCorp\Bundle\EasyAdminBundle\Form\Type\CrudFormType;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException;
use Symfony\Component\PropertyAccess\PropertyAccessor;
Expand All @@ -30,11 +30,11 @@
final class AssociationConfigurator implements FieldConfiguratorInterface
{
private EntityFactory $entityFactory;
private AdminUrlGenerator $adminUrlGenerator;
private AdminUrlGeneratorInterface $adminUrlGenerator;
private RequestStack $requestStack;
private ControllerFactory $controllerFactory;

public function __construct(EntityFactory $entityFactory, AdminUrlGenerator $adminUrlGenerator, RequestStack $requestStack, ControllerFactory $controllerFactory)
public function __construct(EntityFactory $entityFactory, AdminUrlGeneratorInterface $adminUrlGenerator, RequestStack $requestStack, ControllerFactory $controllerFactory)
{
$this->entityFactory = $entityFactory;
$this->adminUrlGenerator = $adminUrlGenerator;
Expand Down
6 changes: 3 additions & 3 deletions src/Field/Configurator/BooleanConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;

/**
* @author Javier Eguiluz <[email protected]>
*/
final class BooleanConfigurator implements FieldConfiguratorInterface
{
private AdminUrlGenerator $adminUrlGenerator;
private AdminUrlGeneratorInterface $adminUrlGenerator;
private ?CsrfTokenManagerInterface $csrfTokenManager;

public function __construct(AdminUrlGenerator $adminUrlGenerator, ?CsrfTokenManagerInterface $csrfTokenManager = null)
public function __construct(AdminUrlGeneratorInterface $adminUrlGenerator, ?CsrfTokenManagerInterface $csrfTokenManager = null)
{
$this->adminUrlGenerator = $adminUrlGenerator;
$this->csrfTokenManager = $csrfTokenManager;
Expand Down
6 changes: 3 additions & 3 deletions src/Orm/EntityPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Orm\EntityPaginatorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\PaginatorDto;
use EasyCorp\Bundle\EasyAdminBundle\Factory\EntityFactory;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface;

/**
* @author Javier Eguiluz <[email protected]>
*/
final class EntityPaginator implements EntityPaginatorInterface
{
private AdminUrlGenerator $adminUrlGenerator;
private AdminUrlGeneratorInterface $adminUrlGenerator;
private EntityFactory $entityFactory;
private ?int $currentPage = null;
private ?int $pageSize = null;
Expand All @@ -27,7 +27,7 @@ final class EntityPaginator implements EntityPaginatorInterface
private ?int $rangeFirstResultNumber = null;
private ?int $rangeLastResultNumber = null;

public function __construct(AdminUrlGenerator $adminUrlGenerator, EntityFactory $entityFactory)
public function __construct(AdminUrlGeneratorInterface $adminUrlGenerator, EntityFactory $entityFactory)
{
$this->adminUrlGenerator = $adminUrlGenerator;
$this->entityFactory = $entityFactory;
Expand Down
35 changes: 16 additions & 19 deletions src/Router/AdminUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Registry\DashboardControllerRegistry;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
* @author Javier Eguiluz <[email protected]>
javiereguiluz marked this conversation as resolved.
Show resolved Hide resolved
*/
final class AdminUrlGenerator
final class AdminUrlGenerator implements AdminUrlGeneratorInterface
{
private bool $isInitialized = false;
private AdminContextProvider $adminContextProvider;
Expand All @@ -32,14 +29,14 @@ public function __construct(AdminContextProvider $adminContextProvider, UrlGener
$this->dashboardControllerRegistry = $dashboardControllerRegistry;
}

public function setDashboard(string $dashboardControllerFqcn): self
public function setDashboard(string $dashboardControllerFqcn): AdminUrlGeneratorInterface
javiereguiluz marked this conversation as resolved.
Show resolved Hide resolved
{
$this->setRouteParameter(EA::DASHBOARD_CONTROLLER_FQCN, $dashboardControllerFqcn);

return $this;
}

public function setController(string $crudControllerFqcn): self
public function setController(string $crudControllerFqcn): AdminUrlGeneratorInterface
{
$this->setRouteParameter(EA::CRUD_CONTROLLER_FQCN, $crudControllerFqcn);
$this->unset(EA::ROUTE_NAME);
Expand All @@ -48,7 +45,7 @@ public function setController(string $crudControllerFqcn): self
return $this;
}

public function setAction(string $action): self
public function setAction(string $action): AdminUrlGeneratorInterface
{
$this->setRouteParameter(EA::CRUD_ACTION, $action);
$this->unset(EA::ROUTE_NAME);
Expand All @@ -57,7 +54,7 @@ public function setAction(string $action): self
return $this;
}

public function setRoute(string $routeName, array $routeParameters = []): self
public function setRoute(string $routeName, array $routeParameters = []): AdminUrlGeneratorInterface
{
$this->unsetAllExcept(EA::DASHBOARD_CONTROLLER_FQCN);
$this->setRouteParameter(EA::ROUTE_NAME, $routeName);
Expand All @@ -66,14 +63,14 @@ public function setRoute(string $routeName, array $routeParameters = []): self
return $this;
}

public function setEntityId($entityId): self
public function setEntityId($entityId): AdminUrlGeneratorInterface
{
$this->setRouteParameter(EA::ENTITY_ID, $entityId);

return $this;
}

public function get(string $paramName)
public function get(string $paramName): mixed
{
if (false === $this->isInitialized) {
$this->initialize();
Expand All @@ -82,7 +79,7 @@ public function get(string $paramName)
return $this->routeParameters[$paramName] ?? null;
}

public function set(string $paramName, $paramValue): self
public function set(string $paramName, $paramValue): AdminUrlGeneratorInterface
{
if (\in_array($paramName, [EA::MENU_INDEX, EA::SUBMENU_INDEX], true)) {
trigger_deprecation(
Expand All @@ -98,7 +95,7 @@ public function set(string $paramName, $paramValue): self
return $this;
}

public function setAll(array $routeParameters): self
public function setAll(array $routeParameters): AdminUrlGeneratorInterface
{
foreach ($routeParameters as $paramName => $paramValue) {
$this->setRouteParameter($paramName, $paramValue);
Expand All @@ -107,7 +104,7 @@ public function setAll(array $routeParameters): self
return $this;
}

public function unset(string $paramName): self
public function unset(string $paramName): AdminUrlGeneratorInterface
{
if (false === $this->isInitialized) {
$this->initialize();
Expand All @@ -118,7 +115,7 @@ public function unset(string $paramName): self
return $this;
}

public function unsetAll(): self
public function unsetAll(): AdminUrlGeneratorInterface
{
if (false === $this->isInitialized) {
$this->initialize();
Expand All @@ -129,7 +126,7 @@ public function unsetAll(): self
return $this;
}

public function unsetAllExcept(string ...$namesOfParamsToKeep): self
public function unsetAllExcept(string ...$namesOfParamsToKeep): AdminUrlGeneratorInterface
{
if (false === $this->isInitialized) {
$this->initialize();
Expand All @@ -140,7 +137,7 @@ public function unsetAllExcept(string ...$namesOfParamsToKeep): self
return $this;
}

public function includeReferrer(): self
public function includeReferrer(): AdminUrlGeneratorInterface
{
if (false === $this->isInitialized) {
$this->initialize();
Expand All @@ -151,7 +148,7 @@ public function includeReferrer(): self
return $this;
}

public function removeReferrer(): self
public function removeReferrer(): AdminUrlGeneratorInterface
{
if (false === $this->isInitialized) {
$this->initialize();
Expand All @@ -162,7 +159,7 @@ public function removeReferrer(): self
return $this;
}

public function setReferrer(string $referrer): self
public function setReferrer(string $referrer): AdminUrlGeneratorInterface
{
if (false === $this->isInitialized) {
$this->initialize();
Expand All @@ -174,7 +171,7 @@ public function setReferrer(string $referrer): self
return $this;
}

public function addSignature(bool $addSignature = true): self
public function addSignature(bool $addSignature = true): AdminUrlGeneratorInterface
{
trigger_deprecation(
'easycorp/easyadmin-bundle',
Expand Down
48 changes: 48 additions & 0 deletions src/Router/AdminUrlGeneratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace EasyCorp\Bundle\EasyAdminBundle\Router;

/**
* @author Javier Eguiluz <[email protected]>
*/
interface AdminUrlGeneratorInterface
javiereguiluz marked this conversation as resolved.
Show resolved Hide resolved
{
public function setDashboard(string $dashboardControllerFqcn): self;

public function setController(string $crudControllerFqcn): self;

public function setAction(string $action): self;

public function setRoute(
string $routeName,
array $routeParameters = []
): self;

public function setEntityId($entityId): self;

public function get(string $paramName): mixed;

public function set(string $paramName, $paramValue): self;

public function setAll(array $routeParameters): self;

public function unset(string $paramName): self;

public function unsetAll(): self;

public function unsetAllExcept(string ...$namesOfParamsToKeep): self;

public function includeReferrer(): self;

public function removeReferrer(): self;

public function setReferrer(string $referrer): self;

public function addSignature(bool $addSignature = true): self;

public function getSignature(): string;

public function generateUrl(): string;
}
3 changes: 2 additions & 1 deletion src/Test/AbstractCrudTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Test\Trait\CrudTestActions;
use EasyCorp\Bundle\EasyAdminBundle\Test\Trait\CrudTestIndexAsserts;
use EasyCorp\Bundle\EasyAdminBundle\Test\Trait\CrudTestUrlGeneration;
Expand All @@ -17,7 +18,7 @@ abstract class AbstractCrudTestCase extends WebTestCase
use CrudTestUrlGeneration;

protected KernelBrowser $client;
protected AdminUrlGenerator $adminUrlGenerator;
protected AdminUrlGeneratorInterface $adminUrlGenerator;
protected EntityManagerInterface $entityManager;

protected function setUp(): void
Expand Down
3 changes: 2 additions & 1 deletion src/Twig/EasyAdminTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Factory\FieldLayoutFactory;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
Expand Down Expand Up @@ -173,7 +174,7 @@ public function callFunctionIfExists(Environment $environment, string $functionN
return $function->getCallable()(...$functionArguments);
}

public function getAdminUrlGenerator(array $queryParameters = []): AdminUrlGenerator
public function getAdminUrlGenerator(array $queryParameters = []): AdminUrlGeneratorInterface
{
return $this->serviceLocator->get(AdminUrlGenerator::class)->setAll($queryParameters);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Router/AdminUrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Registry\DashboardControllerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -265,7 +266,7 @@ public function testRelativeUrls()
$this->assertSame('http://localhost/admin?crudAction=index&crudControllerFqcn=App%5CController%5CAdmin%5CSomeCrudController&foo=bar&foo1=bar1', $adminUrlGenerator->generateUrl());
}

private function getAdminUrlGenerator(bool $signedUrls = false, bool $absoluteUrls = true): AdminUrlGenerator
private function getAdminUrlGenerator(bool $signedUrls = false, bool $absoluteUrls = true): AdminUrlGeneratorInterface
{
self::bootKernel();

Expand Down
Loading
Loading