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

2.x #6136

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ build/
/node_modules/
npm-debug.log
yarn-error.log
.idea
71 changes: 36 additions & 35 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,48 @@
"homepage": "https://github.com/EasyCorp/EasyAdminBundle/blob/master/CONTRIBUTORS.md"
}
],
"minimum-stability": "dev",
"minimum-stability": "stable",
"require": {
"php": ">=7.1.3",
"doctrine/common": "^2.8 || ^3.0",
"doctrine/doctrine-bundle": "^1.8|^2.0",
"doctrine/orm": "^2.6.3",
"doctrine/persistence": "^1.3.4 || ^2.0",
"pagerfanta/pagerfanta": "^1.0.1|^2.0",
"symfony/asset": "^4.2|^5.0",
"symfony/cache": "^4.2|^5.0",
"symfony/config": "^4.2|^5.0",
"symfony/dependency-injection": "^4.2|^5.0",
"symfony/doctrine-bridge": "^4.2|^5.0",
"symfony/error-handler": "^4.4|^5.0",
"symfony/event-dispatcher": "^4.2|^5.0",
"symfony/expression-language": "^4.2|^5.0",
"symfony/finder": "^4.2|^5.0",
"symfony/form": "^4.2|^5.0",
"symfony/framework-bundle": "^4.2|^5.0",
"symfony/http-foundation": "^4.2|^5.0",
"symfony/http-kernel": "^4.3.7|^5.0",
"php": ">=8.0",
"doctrine/common": "^3.0.3",
"doctrine/doctrine-bundle": "^2.5",
"doctrine/orm": "^2.11",
"doctrine/persistence": "^2.4 || ^3",
"pagerfanta/core": "^3.7",
"pagerfanta/doctrine-orm-adapter": "^3.7",
"symfony/asset": "^5.4|^6.0",
"symfony/cache": "^5.4|^6.0",
"symfony/config": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/doctrine-bridge": "^5.4|^6.0",
"symfony/error-handler": "^5.4|^6.0",
"symfony/event-dispatcher": "^5.4|^6.0",
"symfony/expression-language": "^5.4|^6.0",
"symfony/finder": "^5.4|^6.0",
"symfony/form": "^5.4|^6.0",
"symfony/framework-bundle": "^5.4|^6.0",
"symfony/http-foundation": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/polyfill-mbstring": "^1.7",
"symfony/property-access": "^4.2|^5.0",
"symfony/security-bundle": "^4.2|^5.0",
"symfony/translation": "^4.2|^5.0",
"symfony/twig-bridge": "^4.2|^5.0",
"symfony/twig-bundle": "^4.2|^5.0",
"symfony/validator": "^4.2|^5.0",
"twig/twig": "^2.11.3|^3.0"
"symfony/property-access": "^5.4|^6.0",
"symfony/security-bundle": "^5.4|^6.0",
"symfony/translation": "^5.4|^6.0",
"symfony/twig-bridge": "^5.4|^6.0",
"symfony/twig-bundle": "^5.4|^6.0",
"symfony/validator": "^5.4|^6.0",
"twig/twig": "^3.3"
},
"require-dev": {
"doctrine/data-fixtures": "^1.3",
"doctrine/doctrine-fixtures-bundle": "^3.0",
"psr/log": "~1.0",
"symfony/browser-kit": "^4.2|^5.0",
"symfony/console": "^4.2|^5.0",
"symfony/css-selector": "^4.2|^5.0",
"symfony/dom-crawler": "^4.2|^5.0",
"symfony/phpunit-bridge": "^4.3.5|^5.0",
"symfony/var-dumper": "^4.2|^5.0",
"symfony/yaml": "^4.2|^5.0"
"psr/log": "^1|^2|^3",
"symfony/browser-kit": "^5.4|^6.0",
"symfony/console": "^5.4|^6.0",
"symfony/css-selector": "^5.4|^6.0",
"symfony/dom-crawler": "^5.4|^6.0",
"symfony/phpunit-bridge": "^5.4|^6.0",
"symfony/var-dumper": "^5.4|^6.0",
"symfony/yaml": "^5.4|^6.0"
},
"config": {
"sort-packages": true,
Expand Down
7 changes: 4 additions & 3 deletions src/Command/MakeAdminMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace EasyCorp\Bundle\EasyAdminBundle\Command;

use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigManager;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -15,9 +16,9 @@
*
* @author Javier Eguiluz <[email protected]>
*/
#[AsCommand('make:admin:migration')]
class MakeAdminMigrationCommand extends Command
{
protected static $defaultName = 'make:admin:migration';
private $configManager;
private $projectDir;

Expand All @@ -29,7 +30,7 @@ public function __construct(ConfigManager $configManager, string $projectDir)
$this->projectDir = $projectDir;
}

protected function configure()
protected function configure(): void
{
$this
->setDescription('Exports EasyAdmin 2 config to later migrate it to EasyAdmin 3 config.')
Expand All @@ -39,7 +40,7 @@ protected function configure()
/**
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('EasyAdmin 2 to EasyAdmin 3 Migration Assistant');
Expand Down
48 changes: 27 additions & 21 deletions src/Controller/AdminControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents;
use EasyCorp\Bundle\EasyAdminBundle\Exception\EntityRemoveException;
use EasyCorp\Bundle\EasyAdminBundle\Exception\ForbiddenActionException;
Expand Down Expand Up @@ -52,14 +53,13 @@ trait AdminControllerTrait
protected $em;

/**
* @Route("/", name="easyadmin")
*
* @param Request $request
*
* @return RedirectResponse|Response
*
* @throws ForbiddenActionException
*/
#[Route('/', name: 'easyadmin')]
public function indexAction(Request $request)
{
$this->initialize($request);
Expand All @@ -77,7 +77,7 @@ public function indexAction(Request $request)
$id = $this->request->query->get('id');
$entity = $this->request->attributes->get('easyadmin')['item'];
$requiredPermission = $this->entity[$action]['item_permission'];
$userHasPermission = $this->get('easyadmin.security.authorization_checker')->isGranted($requiredPermission, $entity);
$userHasPermission = $this->container->get('easyadmin.security.authorization_checker')->isGranted($requiredPermission, $entity);
if (false === $userHasPermission) {
throw new NoPermissionException(['action' => $action, 'entity_name' => $this->entity['name'], 'entity_id' => $id]);
}
Expand All @@ -99,7 +99,7 @@ protected function initialize(Request $request)
{
$this->dispatch(EasyAdminEvents::PRE_INITIALIZE);

$this->config = $this->get('easyadmin.config.manager')->getBackendConfig();
$this->config = $this->container->get('easyadmin.config.manager')->getBackendConfig();

if (0 === \count($this->config['entities'])) {
throw new NoEntitiesConfiguredException();
Expand All @@ -115,7 +115,7 @@ protected function initialize(Request $request)
throw new UndefinedEntityException(['entity_name' => $entityName]);
}

$this->entity = $this->get('easyadmin.config.manager')->getEntityConfig($entityName);
$this->entity = $this->container->get('easyadmin.config.manager')->getEntityConfig($entityName);

$action = $request->query->get('action', 'list');
if (!$request->query->has('sortField')) {
Expand Down Expand Up @@ -146,9 +146,9 @@ protected function dispatch($eventName, array $arguments = [])
$event = new GenericEvent($subject, $arguments);

if (Kernel::VERSION_ID >= 40300) {
$this->get('event_dispatcher')->dispatch($event, $eventName);
$this->container->get('event_dispatcher')->dispatch($event, $eventName);
} else {
$this->get('event_dispatcher')->dispatch($eventName, $event);
$this->container->get('event_dispatcher')->dispatch($eventName, $event);
}
}

Expand All @@ -160,7 +160,7 @@ protected function dispatch($eventName, array $arguments = [])
*/
protected function autocompleteAction()
{
$results = $this->get('easyadmin.autocomplete')->find(
$results = $this->container->get('easyadmin.autocomplete')->find(
$this->request->query->get('entity'),
$this->request->query->get('query'),
$this->request->query->get('page', 1)
Expand Down Expand Up @@ -385,7 +385,7 @@ protected function searchAction()
$queryParameters = array_replace($this->request->query->all(), ['action' => 'list']);
unset($queryParameters['query']);

return $this->redirect($this->get('router')->generate('easyadmin', $queryParameters));
return $this->redirect($this->container->get('router')->generate('easyadmin', $queryParameters));
}

$searchableFields = $this->entity['search']['fields'];
Expand Down Expand Up @@ -439,7 +439,7 @@ protected function batchAction(): Response

protected function createBatchForm(string $entityName): FormInterface
{
return $this->get('form.factory')->createNamed('batch_form', EasyAdminBatchFormType::class, null, [
return $this->container->get('form.factory')->createNamed('batch_form', EasyAdminBatchFormType::class, null, [
'action' => $this->generateUrl('easyadmin', ['action' => 'batch', 'entity' => $entityName]),
'entity' => $entityName,
]);
Expand Down Expand Up @@ -500,7 +500,7 @@ protected function filterQueryBuilder(QueryBuilder $queryBuilder): void
}

/** @var FilterRegistry $filterRegistry */
$filterRegistry = $this->get('easyadmin.filter.registry');
$filterRegistry = $this->container->get('easyadmin.filter.registry');

$appliedFilters = [];
foreach ($filtersForm as $filterForm) {
Expand Down Expand Up @@ -532,7 +532,7 @@ protected function filterQueryBuilder(QueryBuilder $queryBuilder): void

protected function createFiltersForm(string $entityName): FormInterface
{
return $this->get('form.factory')->createNamed('filters', EasyAdminFiltersFormType::class, null, [
return $this->container->get('form.factory')->createNamed('filters', EasyAdminFiltersFormType::class, null, [
'method' => 'GET',
'entity' => $entityName,
]);
Expand Down Expand Up @@ -595,11 +595,11 @@ protected function updateEntityProperty($entity, $property, $value)
{
$entityConfig = $this->entity;

if (!$this->get('easyadmin.property_accessor')->isWritable($entity, $property)) {
if (!$this->container->get('easyadmin.property_accessor')->isWritable($entity, $property)) {
throw new \RuntimeException(sprintf('The "%s" property of the "%s" entity is not writable.', $property, $entityConfig['name']));
}

$this->get('easyadmin.property_accessor')->setValue($entity, $property, $value);
$this->container->get('easyadmin.property_accessor')->setValue($entity, $property, $value);

$this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity, 'property' => $property, 'newValue' => $value]);
$this->executeDynamicMethod('update<EntityName>Entity', [$entity]);
Expand Down Expand Up @@ -687,7 +687,7 @@ protected function findAll($entityClass, $page = 1, $maxPerPage = 15, $sortField
'sort_direction' => $sortDirection,
]);

return $this->get('easyadmin.paginator')->createOrmPaginator($queryBuilder, $page, $maxPerPage);
return $this->container->get('easyadmin.paginator')->createOrmPaginator($queryBuilder, $page, $maxPerPage);
}

/**
Expand All @@ -702,7 +702,7 @@ protected function findAll($entityClass, $page = 1, $maxPerPage = 15, $sortField
*/
protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
{
return $this->get('easyadmin.query_builder')->createListQueryBuilder($this->entity, $sortField, $sortDirection, $dqlFilter);
return $this->container->get('easyadmin.query_builder')->createListQueryBuilder($this->entity, $sortField, $sortDirection, $dqlFilter);
}

/**
Expand Down Expand Up @@ -736,7 +736,7 @@ protected function findBy($entityClass, $searchQuery, array $searchableFields, $
'searchable_fields' => $searchableFields,
]);

return $this->get('easyadmin.paginator')->createOrmPaginator($queryBuilder, $page, $maxPerPage);
return $this->container->get('easyadmin.paginator')->createOrmPaginator($queryBuilder, $page, $maxPerPage);
}

/**
Expand All @@ -753,7 +753,7 @@ protected function findBy($entityClass, $searchQuery, array $searchableFields, $
*/
protected function createSearchQueryBuilder($entityClass, $searchQuery, array $searchableFields, $sortField = null, $sortDirection = null, $dqlFilter = null)
{
return $this->get('easyadmin.query_builder')->createSearchQueryBuilder($this->entity, $searchQuery, $sortField, $sortDirection, $dqlFilter);
return $this->container->get('easyadmin.query_builder')->createSearchQueryBuilder($this->entity, $searchQuery, $sortField, $sortDirection, $dqlFilter);
}

/**
Expand Down Expand Up @@ -794,7 +794,7 @@ protected function createEntityFormBuilder($entity, $view)
{
$formOptions = $this->executeDynamicMethod('get<EntityName>EntityFormOptions', [$entity, $view]);

return $this->get('form.factory')->createNamedBuilder(mb_strtolower($this->entity['name']), EasyAdminFormType::class, $entity, $formOptions);
return $this->container->get('form.factory')->createNamedBuilder(mb_strtolower($this->entity['name']), EasyAdminFormType::class, $entity, $formOptions);
}

/**
Expand Down Expand Up @@ -859,7 +859,7 @@ protected function createEntityForm($entity, array $entityProperties, $view)
protected function createDeleteForm($entityName, $entityId)
{
/** @var FormBuilder $formBuilder */
$formBuilder = $this->get('form.factory')->createNamedBuilder('delete_form')
$formBuilder = $this->container->get('form.factory')->createNamedBuilder('delete_form')
->setAction($this->generateUrl('easyadmin', ['action' => 'delete', 'entity' => $entityName, 'id' => $entityId]))
->setMethod('DELETE')
;
Expand Down Expand Up @@ -919,7 +919,7 @@ protected function redirectToBackendHomepage()
{
$homepageConfig = $this->config['homepage'];

$url = $homepageConfig['url'] ?? $this->get('router')->generate($homepageConfig['route'], $homepageConfig['params']);
$url = $homepageConfig['url'] ?? $this->container->get('router')->generate($homepageConfig['route'], $homepageConfig['params']);

return $this->redirect($url);
}
Expand Down Expand Up @@ -987,4 +987,10 @@ protected function renderTemplate($actionName, $templatePath, array $parameters
{
return $this->render($templatePath, $parameters);
}


protected function getDoctrine(): ManagerRegistry
{
return $this->container->get('doctrine');
}
}
2 changes: 2 additions & 0 deletions src/Controller/EasyAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EasyCorp\Bundle\EasyAdminBundle\Controller;

use Doctrine\Persistence\ManagerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigManager;
use EasyCorp\Bundle\EasyAdminBundle\Form\Filter\FilterRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Search\Autocomplete;
Expand Down Expand Up @@ -32,6 +33,7 @@ public static function getSubscribedServices(): array
'easyadmin.filter.registry' => FilterRegistry::class,
'easyadmin.security.authorization_checker' => AuthorizationChecker::class,
'event_dispatcher' => EventDispatcherInterface::class,
'doctrine' => ManagerRegistry::class,
]);
}
}
6 changes: 3 additions & 3 deletions src/DataCollector/EasyAdminDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(ConfigManager $configManager)
/**
* {@inheritdoc}
*/
public function reset()
public function reset(): void
{
$this->data = [
'num_entities' => 0,
Expand All @@ -42,7 +42,7 @@ public function reset()
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Throwable $exception = null)
public function collect(Request $request, Response $response, \Throwable $exception = null): void
{
if ('easyadmin' !== $request->attributes->get('_route')) {
return;
Expand Down Expand Up @@ -142,7 +142,7 @@ public function dump($variable)
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return 'easyadmin';
}
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/EasyAdminConfigPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class EasyAdminConfigPass implements CompilerPassInterface
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$configPasses = $this->findAndSortTaggedServices('easyadmin.config_pass', $container);
$definition = $container->getDefinition('easyadmin.config.manager');
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Compiler/EasyAdminFormTypePass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EasyAdminFormTypePass implements CompilerPassInterface
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$this->registerTypeConfigurators($container);
}
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('easy_admin');
$rootNode = $this->getRootNode($treeBuilder, 'easy_admin');
Expand Down
Loading
Loading