Skip to content

Commit

Permalink
Merge pull request #1 from radek-baczynski/feature/use-symfony-5
Browse files Browse the repository at this point in the history
Use symfony 5
  • Loading branch information
radek-baczynski committed Jun 10, 2021
2 parents bee5e8c + 2c88fc8 commit 4c367d8
Show file tree
Hide file tree
Showing 37 changed files with 218 additions and 96 deletions.
8 changes: 4 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('kitpages_data_grid');
$treeBuilder = new TreeBuilder('kitpages_data_grid');
$rootNode = $treeBuilder->getRootNode();

$this->addGridConfiguration($rootNode);
$this->addPaginatorConfiguration($rootNode);
Expand All @@ -44,7 +44,7 @@ private function addGridConfiguration(ArrayNodeDefinition $node)
->end()
->scalarNode('default_twig')
->cannotBeEmpty()
->defaultValue('KitpagesDataGridBundle:Grid:grid.html.twig')
->defaultValue('@KitpagesDataGrid/Grid/grid.html.twig')
->end()
->end()
->end()
Expand All @@ -62,7 +62,7 @@ private function addPaginatorConfiguration(ArrayNodeDefinition $node)
->children()
->scalarNode('default_twig')
->cannotBeEmpty()
->defaultValue('KitpagesDataGridBundle:Paginator:paginator.html.twig')
->defaultValue('@KitpagesDataGrid/Paginator/paginator.html.twig')
->end()
->scalarNode('item_count_in_page')
->cannotBeEmpty()
Expand Down
6 changes: 3 additions & 3 deletions Event/AbstractEvent.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Kitpages\DataGridBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

abstract class AbstractEvent extends Event
{
Expand All @@ -22,12 +22,12 @@ public function isDefaultPrevented()
return $this->isDefaultPrevented;
}

public function stopPropagation()
public function stopPropagation(): void
{
$this->isPropagationStopped = true;
}

public function isPropagationStopped()
public function isPropagationStopped(): bool
{
return $this->isPropagationStopped;
}
Expand Down
8 changes: 8 additions & 0 deletions Event/AfterApplyFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class AfterApplyFilter extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/AfterApplySelector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class AfterApplySelector extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/AfterApplySort.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class AfterApplySort extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/AfterDisplayGridValueConversion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class AfterDisplayGridValueConversion extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/AfterGetGridQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class AfterGetGridQuery extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/AfterGetPaginatorQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class AfterGetPaginatorQuery extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/DataGridEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@

class DataGridEvent extends AbstractEvent
{
public function __construct(DataGridEvent $event = null)
{
if ($event) {
$this->data = $event->data;
$this->isDefaultPrevented = $event->isDefaultPrevented;
$this->isPropagationStopped = $event->isPropagationStopped;
}
}
}
8 changes: 8 additions & 0 deletions Event/OnApplyFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class OnApplyFilter extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/OnApplySelector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class OnApplySelector extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/OnApplySort.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class OnApplySort extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/OnDisplayGridValueConversion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class OnDisplayGridValueConversion extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/OnGetGridQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class OnGetGridQuery extends DataGridEvent
{

}
8 changes: 8 additions & 0 deletions Event/OnGetPaginatorQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace Kitpages\DataGridBundle\Event;

class OnGetPaginatorQuery extends DataGridEvent
{

}
7 changes: 5 additions & 2 deletions Grid/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Kitpages\DataGridBundle\Grid;

use Kitpages\DataGridBundle\Event\AfterDisplayGridValueConversion;
use Kitpages\DataGridBundle\Event\OnDisplayGridValueConversion;
use Kitpages\DataGridBundle\Paginator\Paginator;
use Kitpages\DataGridBundle\Tool\UrlTool;
use Kitpages\DataGridBundle\Grid\Field;
use Kitpages\DataGridBundle\DataGridException;
Expand Down Expand Up @@ -123,7 +126,7 @@ public function displayGridValue($row, Field $field)
$event->set('value', $value);
$event->set('row', $row);
$event->set('field', $field);
$this->dispatcher->dispatch(KitpagesDataGridEvents::ON_DISPLAY_GRID_VALUE_CONVERSION, $event);
$this->dispatcher->dispatch(new OnDisplayGridValueConversion($event));

if (!$event->isDefaultPrevented()) {
$value = $event->get('value');
Expand All @@ -135,7 +138,7 @@ public function displayGridValue($row, Field $field)
$event->set('returnValue', $returnValue);
}

$this->dispatcher->dispatch(KitpagesDataGridEvents::AFTER_DISPLAY_GRID_VALUE_CONVERSION, $event);
$this->dispatcher->dispatch(new AfterDisplayGridValueConversion($event));
$returnValue = $event->get('returnValue');

// auto escape ? (if null, return null, without autoescape...)
Expand Down
1 change: 1 addition & 0 deletions Grid/GridConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\ORM\QueryBuilder;
use Kitpages\DataGridBundle\Paginator\PaginatorConfig;
use SebastianBergmann\CodeCoverage\Driver\Selector;

class GridConfig
{
Expand Down
24 changes: 16 additions & 8 deletions Grid/GridManager.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?php
namespace Kitpages\DataGridBundle\Grid;

use Kitpages\DataGridBundle\Event\AfterApplyFilter;
use Kitpages\DataGridBundle\Event\AfterApplySelector;
use Kitpages\DataGridBundle\Event\AfterApplySort;
use Kitpages\DataGridBundle\Event\AfterGetGridQuery;
use Kitpages\DataGridBundle\Event\OnApplyFilter;
use Kitpages\DataGridBundle\Event\OnApplySelector;
use Kitpages\DataGridBundle\Event\OnApplySort;
use Kitpages\DataGridBundle\Event\OnGetGridQuery;
use Kitpages\DataGridBundle\Grid\ItemListNormalizer\NormalizerInterface;
use Kitpages\DataGridBundle\Paginator\PaginatorManager;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -123,15 +131,15 @@ public function getGrid(
$event->set("grid", $grid);
$event->set("gridQueryBuilder", $gridQueryBuilder);
$event->set("request", $request);
$this->dispatcher->dispatch(KitpagesDataGridEvents::ON_GET_GRID_QUERY, $event);
$this->dispatcher->dispatch(new OnGetGridQuery($event));

if (!$event->isDefaultPrevented()) {
// execute request
$query = $gridQueryBuilder->getQuery();
$event->set("query", $query);
}

$this->dispatcher->dispatch(KitpagesDataGridEvents::AFTER_GET_GRID_QUERY, $event);
$this->dispatcher->dispatch(new AfterGetGridQuery($event));

// hack : recover query from the event so the developper can build a new grid
// from the gridQueryBuilder in the listener and reinject it in the event.
Expand All @@ -156,7 +164,7 @@ protected function applyFilter(QueryBuilder $queryBuilder, Grid $grid, $filter)
$event->set("grid", $grid);
$event->set("gridQueryBuilder", $queryBuilder);
$event->set("filter", $filter);
$this->dispatcher->dispatch(KitpagesDataGridEvents::ON_APPLY_FILTER, $event);
$this->dispatcher->dispatch(new OnApplyFilter($event));

if (!$event->isDefaultPrevented()) {
$fieldList = $grid->getGridConfig()->getFieldList();
Expand All @@ -173,7 +181,7 @@ protected function applyFilter(QueryBuilder $queryBuilder, Grid $grid, $filter)
}
$grid->setFilterValue($filter);
}
$this->dispatcher->dispatch(KitpagesDataGridEvents::AFTER_APPLY_FILTER, $event);
$this->dispatcher->dispatch(new AfterApplyFilter($event));
}

protected function applySelector(QueryBuilder $queryBuilder, Grid $grid, $selectorField, $selectorValue)
Expand All @@ -186,7 +194,7 @@ protected function applySelector(QueryBuilder $queryBuilder, Grid $grid, $select
$event->set("gridQueryBuilder", $queryBuilder);
$event->set("selectorField", $selectorField);
$event->set("selectorValue", $selectorValue);
$this->dispatcher->dispatch(KitpagesDataGridEvents::ON_APPLY_SELECTOR, $event);
$this->dispatcher->dispatch(new OnApplySelector($event));

if (!$event->isDefaultPrevented()) {
$queryBuilder->andWhere($selectorField." = :selectorValue");
Expand All @@ -195,7 +203,7 @@ protected function applySelector(QueryBuilder $queryBuilder, Grid $grid, $select
$grid->setSelectorField($selectorField);
$grid->setSelectorValue($selectorValue);
}
$this->dispatcher->dispatch(KitpagesDataGridEvents::AFTER_APPLY_SELECTOR, $event);
$this->dispatcher->dispatch(new AfterApplySelector($event));
}

protected function applySort(QueryBuilder $gridQueryBuilder, Grid $grid, $sortField, $sortOrder)
Expand All @@ -208,7 +216,7 @@ protected function applySort(QueryBuilder $gridQueryBuilder, Grid $grid, $sortFi
$event->set("gridQueryBuilder", $gridQueryBuilder);
$event->set("sortField", $sortField);
$event->set("sortOrder", $sortOrder);
$this->dispatcher->dispatch(KitpagesDataGridEvents::ON_APPLY_SORT, $event);
$this->dispatcher->dispatch(new OnApplySort($event));

if (!$event->isDefaultPrevented()) {
$sortFieldObject = null;
Expand All @@ -232,7 +240,7 @@ protected function applySort(QueryBuilder $gridQueryBuilder, Grid $grid, $sortFi
$grid->setSortOrder($sortOrder);
}

$this->dispatcher->dispatch(KitpagesDataGridEvents::AFTER_APPLY_SORT, $event);
$this->dispatcher->dispatch(new AfterApplySort($event));
}

}
38 changes: 26 additions & 12 deletions KitpagesDataGridEvents.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
<?php

namespace Kitpages\DataGridBundle;

use Kitpages\DataGridBundle\Event\AfterApplyFilter;
use Kitpages\DataGridBundle\Event\AfterApplySelector;
use Kitpages\DataGridBundle\Event\AfterApplySort;
use Kitpages\DataGridBundle\Event\AfterDisplayGridValueConversion;
use Kitpages\DataGridBundle\Event\AfterGetGridQuery;
use Kitpages\DataGridBundle\Event\AfterGetPaginatorQuery;
use Kitpages\DataGridBundle\Event\OnApplyFilter;
use Kitpages\DataGridBundle\Event\OnApplySelector;
use Kitpages\DataGridBundle\Event\OnApplySort;
use Kitpages\DataGridBundle\Event\OnDisplayGridValueConversion;
use Kitpages\DataGridBundle\Event\OnGetGridQuery;
use Kitpages\DataGridBundle\Event\OnGetPaginatorQuery;

final class KitpagesDataGridEvents
{
const ON_GET_GRID_QUERY = "kitpages_data_grid.on_get_grid_query";
const AFTER_GET_GRID_QUERY = "kitpages_data_grid.after_get_grid_query";
const ON_GET_GRID_QUERY = OnGetGridQuery::class;
const AFTER_GET_GRID_QUERY = AfterGetGridQuery::class;

const ON_GET_PAGINATOR_QUERY = "kitpages_data_grid.on_get_paginator_query";
const AFTER_GET_PAGINATOR_QUERY = "kitpages_data_grid.after_get_paginator_query";
const ON_GET_PAGINATOR_QUERY = OnGetPaginatorQuery::class;
const AFTER_GET_PAGINATOR_QUERY = AfterGetPaginatorQuery::class;

const ON_APPLY_FILTER = "kitpages_data_grid.on_apply_filter";
const AFTER_APPLY_FILTER = "kitpages_data_grid.after_apply_filter";
const ON_APPLY_FILTER = OnApplyFilter::class;
const AFTER_APPLY_FILTER = AfterApplyFilter::class;

const ON_APPLY_SELECTOR = "kitpages_data_grid.on_apply_selector";
const AFTER_APPLY_SELECTOR = "kitpages_data_grid.after_apply_selector";
const ON_APPLY_SELECTOR = OnApplySelector::class;
const AFTER_APPLY_SELECTOR = AfterApplySelector::class;

const ON_APPLY_SORT = "kitpages_data_grid.on_apply_sort";
const AFTER_APPLY_SORT = "kitpages_data_grid.after_apply_sort";
const ON_APPLY_SORT = OnApplySort::class;
const AFTER_APPLY_SORT = AfterApplySort::class;

const ON_DISPLAY_GRID_VALUE_CONVERSION = "kitpages_data_grid.on_display_grid_value_conversion";
const AFTER_DISPLAY_GRID_VALUE_CONVERSION = "kitpages_data_grid.after_display_grid_value_conversion";
const ON_DISPLAY_GRID_VALUE_CONVERSION = OnDisplayGridValueConversion::class;
const AFTER_DISPLAY_GRID_VALUE_CONVERSION = AfterDisplayGridValueConversion::class;
}
6 changes: 4 additions & 2 deletions Paginator/PaginatorManager.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Kitpages\DataGridBundle\Paginator;

use Kitpages\DataGridBundle\Event\AfterGetPaginatorQuery;
use Kitpages\DataGridBundle\Event\OnGetPaginatorQuery;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

Expand Down Expand Up @@ -73,13 +75,13 @@ public function getPaginator(PaginatorConfig $paginatorConfig, Request $request)
$event->set("paginator", $paginator);
$event->set("paginatorQueryBuilder", $countQueryBuilder);
$event->set("request", $request);
$this->dispatcher->dispatch(KitpagesDataGridEvents::ON_GET_PAGINATOR_QUERY, $event);
$this->dispatcher->dispatch(new OnGetPaginatorQuery($event));

if (!$event->isDefaultPrevented()) {
$query = $countQueryBuilder->getQuery();
$event->set("query", $query);
}
$this->dispatcher->dispatch(KitpagesDataGridEvents::AFTER_GET_PAGINATOR_QUERY, $event);
$this->dispatcher->dispatch(new AfterGetPaginatorQuery($event));

// hack : recover query from the event so the developper can build a new query
// from the paginatorQueryBuilder in the listener and reinject it in the event.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ These values are default values. You can skip the configuration if it is ok for
```yaml
kitpages_data_grid:
grid:
default_twig: KitpagesDataGridBundle:Grid:grid.html.twig
default_twig: @KitpagesDataGrid/Grid/grid.html.twig
paginator:
default_twig: KitpagesDataGridBundle:Paginator:paginator.html.twig
default_twig: @KitpagesDataGrid/Paginator/paginator.html.twig
item_count_in_page: 50
visible_page_count_in_paginator: 5
```
Expand All @@ -110,9 +110,9 @@ Note you can use the followin configuration in order to user Bootstrap 3 :
```yaml
kitpages_data_grid:
grid:
default_twig: KitpagesDataGridBundle:Grid:bootstrap3-grid.html.twig
default_twig: @KitpagesDataGrid/Grid/bootstrap3-grid.html.twig
paginator:
default_twig: KitpagesDataGridBundle:Paginator:bootstrap3-paginator.html.twig
default_twig: @KitpagesDataGrid/Paginator/bootstrap3-paginator.html.twig
```


Expand Down

0 comments on commit 4c367d8

Please sign in to comment.