Skip to content

Commit

Permalink
Merge pull request #6 from vysokeskoly/feature/require-php-81
Browse files Browse the repository at this point in the history
Feature/require php 81
  • Loading branch information
MortalFlesh authored Apr 27, 2022
2 parents cba81b6 + 8852253 commit 299986b
Show file tree
Hide file tree
Showing 25 changed files with 242 additions and 246 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/php-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:

strategy:
matrix:
php-version: ['7.4', '8.0', '8.1']
php-version: ['8.1']
dependencies: ['']
include:
- { php-version: '7.4', dependencies: '--prefer-lowest --prefer-stable' }
- { php-version: '8.1', dependencies: '--prefer-lowest --prefer-stable' }

name: Unit tests - PHP ${{ matrix.php-version }} ${{ matrix.dependencies }}

Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
extensions: mbstring, intl
tools: composer:v2

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Changelog
=========

## Unreleased
- Allow Symfony 6
- Require php 8.1
- [**BC**] Use php 8.1 features and types
- Add `FieldOption` Enum

## 5.1.0 - 2022-04-23
- Allow php ^8
Expand Down
100 changes: 59 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ You need to add the following lines in your deps :

Add KitpagesChainBundle in your composer.json

```
```json
{
"require": {
"vysokeskoly/data-grid-bundle": "^5.0"
Expand All @@ -72,17 +72,17 @@ Add KitpagesChainBundle in your composer.json

Now tell composer to download the bundle by running the step:

``` bash
```bash
$ php composer.phar update vysokeskoly/data-grid-bundle
```

AppKernel.php

``` php
$bundles = array(
```php
$bundles = [
...
new Kitpages\DataGridBundle\KitpagesDataGridBundle(),
);
];
```

Configuration in config.yml
Expand Down Expand Up @@ -120,10 +120,11 @@ Simple Usage example
use Kitpages\DataGridBundle\Grid\GridConfig;
use Kitpages\DataGridBundle\Grid\Field;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class ContactController
{
public function productListAction(Request $request)
public function productListAction(Request $request): Response
{
// create query builder
$repository = $this->getDoctrine()->getRepository('AcmeStoreBundle:Product');
Expand All @@ -132,24 +133,22 @@ class ContactController
->setParameter('price', '19.90')
;

$gridConfig = new GridConfig();
$gridConfig = new GridConfig($queryBuilder, 'item.id');
$gridConfig
->setQueryBuilder($queryBuilder)
->setCountFieldName('item.id')
->addField('item.id')
->addField('item.slug', array('filterable' => true))
->addField('item.updatedAt', array(
->addField('item.slug', ['filterable' => true])
->addField('item.updatedAt', [
'sortable' => true,
'formatValueCallback' => function($value) { return $value->format('Y/m/d'); }
))
'formatValueCallback' => fn ($value) => $value->format('Y/m/d')
])
;

$gridManager = $this->get('kitpages_data_grid.grid_manager');
$grid = $gridManager->getGrid($gridConfig, $request);

return $this->render('AppSiteBundle:Default:productList.html.twig', array(
return $this->render('AppSiteBundle:Default:productList.html.twig', [
'grid' => $grid
));
]);
}
}
```
Expand Down Expand Up @@ -193,11 +192,11 @@ More advanced usage
use Kitpages\DataGridBundle\Grid\GridConfig;
use Kitpages\DataGridBundle\Grid\Field;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class AdminController extends Controller
{

public function listAction(Request $request, $state)
public function listAction(Request $request, $state): Response
{
// create query builder
$em = $this->get('doctrine')->getEntityManager();
Expand All @@ -211,23 +210,21 @@ class AdminController extends Controller
->setParameter('state', $state)
;

$gridConfig = new GridConfig();
$gridConfig = new GridConfig($queryBuilder, 'm.id');
$gridConfig
->setQueryBuilder($queryBuilder)
->setCountFieldName("m.id");
->addField('m.title', array('label' => 'title', 'filterable' => true))
->addField('m.country', array('filterable' => true))
->addField('c.corporation', array('filterable' => true))
->addField('e.lastname', array('filterable' => true))
->addField('e.email', array('filterable' => true))
->addField('m.title', ['label' => 'title', 'filterable' => true])
->addField('m.country', ['filterable' => true])
->addField('c.corporation', ['filterable' => true])
->addField('e.lastname', ['filterable' => true])
->addField('e.email', ['filterable' => true])
;

$gridManager = $this->get('kitpages_data_grid.grid_manager');
$grid = $gridManager->getGrid($gridConfig, $request);

return $this->render('KitappMissionBundle:Admin:list.html.twig', array(
return $this->render('KitappMissionBundle:Admin:list.html.twig', [
'grid' => $grid
));
]);
}
}
```
Expand All @@ -241,12 +238,16 @@ Field "as"

For request like

$queryBuilder->select("item, item.id * 3 as foo");
```php
$queryBuilder->select("item, item.id * 3 as foo");
```

You can display the foo field with

$gridConfig->addField("item.id");
$gridConfig->addField("foo");
```php
$gridConfig->addField("item.id");
$gridConfig->addField("foo");
```


Events
Expand All @@ -264,18 +265,20 @@ Tag system is used to get some fields by tags. When you create a field, you can
define some tags associated to this field. After that, in the grid config, you can
find the fields that match this tag.

// add tag as the third parameter of the field
$gridConfig->addField("item.id", [], ['foo', 'bar']);
$gridConfig->addField("foo", [], ['myTag', 'foo']);
```php
// add tag as the third parameter of the field
$gridConfig->addField("item.id", [], ['foo', 'bar']);
$gridConfig->addField("foo", [], ['myTag', 'foo']);

// get fieldList matching 'bar' tag. There is only one result.
$fieldList = $gridConfig->getFieldListByTag('bar');
$fieldList[0] // -> this is the first Field (which name is 'item.id')
// get fieldList matching 'bar' tag. There is only one result.
$fieldList = $gridConfig->getFieldListByTag('bar');
$fieldList[0] // -> this is the first Field (which name is 'item.id')
```

Custom class for the $grid object
=================================

By default, the following line
By default, the following line
```php
$grid = $gridManager->getGrid($gridConfig, $request);
```
Expand All @@ -294,7 +297,7 @@ $grid = $gridManager->getGrid($gridConfig, $request,$myCustomGrid);
// now the $grid object is an instance of CustomGrid (it
// is exactly the same object than $myCustomGrid, not cloned)
```


Reference guide
===============
Expand All @@ -304,17 +307,32 @@ Reference guide
when you add a field, you can set these parameters :

```php
$gridConfig->addField('slug', array(
$gridConfig->addField('slug', [
'label' => 'Mon slug',
'sortable' => false,
'visible' => true,
'filterable' => true,
'translatable' => true,
'formatValueCallback' => function($value) { return strtoupper($value); },
'formatValueCallback' => fn ($value) => strtoupper($value),
'autoEscape' => true,
'category' => null, // only used by you for checking this value in your events if you want to...
'nullIfNotExists' => false, // for leftJoin, if value is not defined, this can return null instead of an exception
));
]);
```

TIP: Use `FieldOption` enum
```php
$gridConfig->addField('slug', [
FieldOption::Label->value => 'Mon slug',
FieldOption::Sortable->value => false,
FieldOption::Visible->value => true,
FieldOption::Filterable->value => true,
FieldOption::Translatable->value => true,
FieldOption::FormatValueCallback->value => fn ($value) => strtoupper($value),
FieldOption::AutoEscape->value => true,
FieldOption::Category->value => null, // only used by you for checking this value in your events if you want to...
FieldOption::NullIfNotExists->value => false, // for leftJoin, if value is not defined, this can return null instead of an exception
]);
```

## What can you personalize in your twig template
Expand Down
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@
],
"homepage": "https://github.com/vysokeskoly/KitpagesDataGridBundle",
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"ext-pdo": "*",
"beberlei/assert": "^3.3",
"doctrine/doctrine-bundle": "^2.5.7",
"doctrine/orm": "^2.11.2",
"symfony/dependency-injection": "^5.0",
"symfony/framework-bundle": "^5.0",
"symfony/templating": "^5.0",
"symfony/translation": "^5.0",
"symfony/twig-bundle": "^5.0",
"symfony/dependency-injection": "^5.0 || ^6.0",
"symfony/framework-bundle": "^5.0 || ^6.0",
"symfony/templating": "^5.0 || ^6.0",
"symfony/translation": "^5.0 || ^6.0",
"symfony/twig-bundle": "^5.0 || ^6.0",
"twig/twig": "^3.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.24",
"lmc/coding-standard": "^3.2",
"lmc/coding-standard": "^3.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.5",
"phpstan/phpstan-beberlei-assert": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "^5.0",
"symfony/finder": "^5.0",
"symfony/yaml": "^5.0"
"phpunit/phpunit": "^9.5.20",
"symfony/browser-kit": "^5.0 || ^6.0",
"symfony/finder": "^5.0 || ^6.0",
"symfony/yaml": "^5.0 || ^6.0"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 8 additions & 4 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
use PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer;
use SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\EasyCodingStandard\ValueObject\Option;

Expand All @@ -14,14 +15,17 @@
Option::SKIP,
[
ForbiddenFunctionsSniff::class => [
__DIR__ . '/src/Grid/Grid.php',
'src/Grid/Grid.php',
],
PhpdocToParamTypeFixer::class => [
__DIR__ . '/src/Hydrators/DataGridHydrator.php',
'src/Hydrators/DataGridHydrator.php',
],
]
ParameterTypeHintSniff::class . '.' . ParameterTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT => [
'src/Hydrators/DataGridHydrator.php',
],
],
);

$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs-7.4.php');
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.1.php');
};
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ parameters:
message: "#^Call to an undefined method object\\:\\:getManager\\(\\)\\.$#"
count: 1
path: tests/BundleOrmTestCase.php
-
message: "#^Parameter \\#1 \\$field of method Kitpages\\\\DataGridBundle\\\\Grid\\\\GridConfig\\:\\:addField\\(\\) expects Kitpages\\\\DataGridBundle\\\\Grid\\\\Field\\|string, array\\|\\(Closure\\)\\|float\\|int\\|stdClass\\|true\\|null given\\.$#"
count: 1
path: tests/Grid/GridConfigTest.php
12 changes: 2 additions & 10 deletions src/Event/AbstractEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,12 @@ public function isPropagationStopped(): bool
return $this->isPropagationStopped;
}

/**
* @param mixed $key
* @param mixed $val
*/
public function set($key, $val): void
public function set(mixed $key, mixed $val): void
{
$this->data[$key] = $val;
}

/**
* @param mixed $key
* @return mixed
*/
public function get($key)
public function get(mixed $key): mixed
{
if (!array_key_exists($key, $this->data)) {
return null;
Expand Down
Loading

0 comments on commit 299986b

Please sign in to comment.