From aef5b93123fab16f5cc7e4c367ea5e8ddace6074 Mon Sep 17 00:00:00 2001 From: stephanvierkant Date: Wed, 3 Jul 2019 15:54:55 +0200 Subject: [PATCH 01/15] Very very early stage proof of concept of Columns as a Service --- Datatable/AbstractDatatable.php | 5 ++-- Datatable/Column/ColumnBuilder.php | 28 ++++++++++++++++--- DependencyInjection/SgDatatablesExtension.php | 4 +++ Resources/config/services.yml | 27 ++++++++++-------- Resources/doc/cache.md | 3 +- Resources/doc/installation.md | 15 ++++++---- Resources/doc/query.md | 4 ++- 7 files changed, 62 insertions(+), 24 deletions(-) diff --git a/Datatable/AbstractDatatable.php b/Datatable/AbstractDatatable.php index 6faa8049..57da569e 100644 --- a/Datatable/AbstractDatatable.php +++ b/Datatable/AbstractDatatable.php @@ -173,7 +173,8 @@ public function __construct( TranslatorInterface $translator, RouterInterface $router, EntityManagerInterface $em, - Twig_Environment $twig + Twig_Environment $twig, + $columns ) { $this->validateName(); @@ -191,7 +192,7 @@ public function __construct( $this->twig = $twig; $metadata = $em->getClassMetadata($this->getEntity()); - $this->columnBuilder = new ColumnBuilder($metadata, $twig, $this->getName(), $em); + $this->columnBuilder = new ColumnBuilder($metadata, $twig, $this->getName(), $em, $columns); $this->ajax = new Ajax(); $this->options = new Options(); diff --git a/Datatable/Column/ColumnBuilder.php b/Datatable/Column/ColumnBuilder.php index 44b7a191..dd99f940 100644 --- a/Datatable/Column/ColumnBuilder.php +++ b/Datatable/Column/ColumnBuilder.php @@ -11,11 +11,10 @@ namespace Sg\DatatablesBundle\Datatable\Column; -use Sg\DatatablesBundle\Datatable\Factory; - use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\MappingException; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; use Twig_Environment; use Exception; @@ -83,6 +82,12 @@ class ColumnBuilder */ private $entityClassName; + /** + * Column services + * + * @var \Symfony\Component\DependencyInjection\Argument\RewindableGenerator + */ + private $columnTypes; //------------------------------------------------- // Ctor. //------------------------------------------------- @@ -94,8 +99,9 @@ class ColumnBuilder * @param Twig_Environment $twig * @param string $datatableName * @param EntityManagerInterface $em + * @param RewindableGenerator $columnTypes */ - public function __construct(ClassMetadata $metadata, Twig_Environment $twig, $datatableName, EntityManagerInterface $em) + public function __construct(ClassMetadata $metadata, Twig_Environment $twig, $datatableName, EntityManagerInterface $em, $columnTypes) { $this->metadata = $metadata; $this->twig = $twig; @@ -106,6 +112,7 @@ public function __construct(ClassMetadata $metadata, Twig_Environment $twig, $da $this->columnNames = array(); $this->uniqueColumns = array(); $this->entityClassName = $metadata->getName(); + $this->columnTypes = $columnTypes; } //------------------------------------------------- @@ -124,7 +131,20 @@ public function __construct(ClassMetadata $metadata, Twig_Environment $twig, $da */ public function add($dql, $class, array $options = array()) { - $column = Factory::create($class, ColumnInterface::class); + if (is_object($class)) { + throw new \RuntimeException('Use FCQN instead of object: ' . get_class($class)); + } + + $columns = []; + foreach ($this->columnTypes as $column) { + $columns[get_class($column)] = $column; + } + + if (! array_key_exists($class, $columns)) { + throw new \RuntimeException(sprintf('Column %s is not a service', $class)); + } + + $column = clone $columns[$class]; $column->initOptions(); $this->handleDqlProperties($dql, $options, $column); diff --git a/DependencyInjection/SgDatatablesExtension.php b/DependencyInjection/SgDatatablesExtension.php index 37e1ee8f..8afbe4e6 100644 --- a/DependencyInjection/SgDatatablesExtension.php +++ b/DependencyInjection/SgDatatablesExtension.php @@ -11,6 +11,7 @@ namespace Sg\DatatablesBundle\DependencyInjection; +use Sg\DatatablesBundle\Datatable\Column\ColumnInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; @@ -36,6 +37,9 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('services.yml'); $container->setParameter('sg_datatables.datatable.query', $config['datatable']['query']); + $container->registerForAutoconfiguration(ColumnInterface::class) + ->addTag('sg_datatables.column') + ; } /** diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 594ca6ea..b13c2422 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,12 +1,16 @@ services: - sg_datatables.twig.extension: - class: Sg\DatatablesBundle\Twig\DatatableTwigExtension - public: false - tags: - - { name: twig.extension } + _defaults: + autoconfigure: true + autowire: true - sg_datatables.datatable.abstract: - class: Sg\DatatablesBundle\Datatable\AbstractDatatable + _instanceof: + Sg\DatatablesBundle\Datatable\Column\Column: + tags: ['sg_datatables.column'] + + Sg\DatatablesBundle\Datatable\Column\: + resource: '../../Datatable/Column/*' + + Sg\DatatablesBundle\Datatable\AbstractDatatable: abstract: true arguments: - '@security.authorization_checker' @@ -15,15 +19,14 @@ services: - '@router' - '@doctrine.orm.entity_manager' - '@twig' + - ! tagged sg_datatables.column - sg_datatables.response: - class: Sg\DatatablesBundle\Response\DatatableResponse + Sg\DatatablesBundle\Response\DatatableResponse: public: true arguments: - '@request_stack' - sg_datatables.factory: - class: Sg\DatatablesBundle\Datatable\DatatableFactory + Sg\DatatablesBundle\Datatable\DatatableFactory: public: true arguments: - '@security.authorization_checker' @@ -32,3 +35,5 @@ services: - '@router' - '@doctrine.orm.entity_manager' - '@twig' + + Sg\DatatablesBundle\Twig\DatatableTwigExtension: ~ diff --git a/Resources/doc/cache.md b/Resources/doc/cache.md index 5a669ee1..20abb7d9 100644 --- a/Resources/doc/cache.md +++ b/Resources/doc/cache.md @@ -12,9 +12,10 @@ Doctrine Query when creating response for DataTable. ``` php get('sg_datatables.response'); + $responseService = $this->get(DatatableResponse::class); $responseService->setDatatable($datatable); $datatableQueryBuilder = $responseService->getDatatableQueryBuilder(); diff --git a/Resources/doc/installation.md b/Resources/doc/installation.md index edb2ed7a..4c94d2f4 100644 --- a/Resources/doc/installation.md +++ b/Resources/doc/installation.md @@ -365,14 +365,19 @@ class PostDatatable extends AbstractDatatable # app/config/services.yml services: - app.datatable.post: - class: AppBundle\Datatables\PostDatatable - parent: sg_datatables.datatable.abstract + _defaults: + autoconfigure: true + autowire: true + AppBundle\Datatables\PostDatatable: + bind: + $columns: !tagged sg_datatables.column ``` ### Step 3: The Controller actions ``` php +use Sg\DatatablesBundle\Datatable\DatatableFactory; +use Sg\DatatablesBundle\Response\DatatableResponse; /** * Lists all Post entities. * @@ -393,11 +398,11 @@ public function indexAction(Request $request) // or use the DatatableFactory /** @var DatatableInterface $datatable */ - $datatable = $this->get('sg_datatables.factory')->create(PostDatatable::class); + $datatable = $this->get(DatatableFactory::class)->create(PostDatatable::class); $datatable->buildDatatable(); if ($isAjax) { - $responseService = $this->get('sg_datatables.response'); + $responseService = $this->get(DatatableResponse::class); $responseService->setDatatable($datatable); $responseService->getDatatableQueryBuilder(); diff --git a/Resources/doc/query.md b/Resources/doc/query.md index aba9af1e..41c64802 100644 --- a/Resources/doc/query.md +++ b/Resources/doc/query.md @@ -40,12 +40,14 @@ class Post Now you can view all posts created by `root`. The additional `where statement` now works like a filter. ``` php +use Sg\DatatablesBundle\Response\DatatableResponse; + public function indexAction(Request $request) { // ... if ($request->isXmlHttpRequest()) { - $responseService = $this->get('sg_datatables.response'); + $responseService = $this->get(DatatableResponse::class); $responseService->setDatatable($datatable); $datatableQueryBuilder = $responseService->getDatatableQueryBuilder(); From 7f18b5a7d8f117c9f1ba0fcc635da3d9d0408d78 Mon Sep 17 00:00:00 2001 From: stephanvierkant Date: Tue, 16 Jul 2019 09:01:39 +0200 Subject: [PATCH 02/15] iterable --- Datatable/AbstractDatatable.php | 6 ++++-- Datatable/Column/ColumnBuilder.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Datatable/AbstractDatatable.php b/Datatable/AbstractDatatable.php index 57da569e..b13354d4 100644 --- a/Datatable/AbstractDatatable.php +++ b/Datatable/AbstractDatatable.php @@ -11,6 +11,7 @@ namespace Sg\DatatablesBundle\Datatable; +use phpDocumentor\Reflection\Types\Iterable_; use Sg\DatatablesBundle\Datatable\Column\ColumnBuilder; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -164,6 +165,7 @@ abstract class AbstractDatatable implements DatatableInterface * @param RouterInterface $router * @param EntityManagerInterface $em * @param Twig_Environment $twig + * @param iterable $columnTypes * * @throws Exception */ @@ -174,7 +176,7 @@ public function __construct( RouterInterface $router, EntityManagerInterface $em, Twig_Environment $twig, - $columns + iterable $columnTypes ) { $this->validateName(); @@ -192,7 +194,7 @@ public function __construct( $this->twig = $twig; $metadata = $em->getClassMetadata($this->getEntity()); - $this->columnBuilder = new ColumnBuilder($metadata, $twig, $this->getName(), $em, $columns); + $this->columnBuilder = new ColumnBuilder($metadata, $twig, $this->getName(), $em, $columnTypes); $this->ajax = new Ajax(); $this->options = new Options(); diff --git a/Datatable/Column/ColumnBuilder.php b/Datatable/Column/ColumnBuilder.php index dd99f940..72487741 100644 --- a/Datatable/Column/ColumnBuilder.php +++ b/Datatable/Column/ColumnBuilder.php @@ -101,7 +101,7 @@ class ColumnBuilder * @param EntityManagerInterface $em * @param RewindableGenerator $columnTypes */ - public function __construct(ClassMetadata $metadata, Twig_Environment $twig, $datatableName, EntityManagerInterface $em, $columnTypes) + public function __construct(ClassMetadata $metadata, Twig_Environment $twig, $datatableName, EntityManagerInterface $em, iterable $columnTypes) { $this->metadata = $metadata; $this->twig = $twig; From 2d095fa89dddc0794ce3bed7e304447f22e2e25f Mon Sep 17 00:00:00 2001 From: stephanvierkant Date: Wed, 17 Jul 2019 09:34:30 +0200 Subject: [PATCH 03/15] wrong use statement --- Datatable/AbstractDatatable.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Datatable/AbstractDatatable.php b/Datatable/AbstractDatatable.php index b13354d4..53aa48b5 100644 --- a/Datatable/AbstractDatatable.php +++ b/Datatable/AbstractDatatable.php @@ -11,9 +11,7 @@ namespace Sg\DatatablesBundle\Datatable; -use phpDocumentor\Reflection\Types\Iterable_; use Sg\DatatablesBundle\Datatable\Column\ColumnBuilder; - use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Translation\TranslatorInterface; From 85e3c4baf4d0b3d9a47e936650721e5d774ef1e2 Mon Sep 17 00:00:00 2001 From: stephanvierkant Date: Wed, 17 Jul 2019 09:49:57 +0200 Subject: [PATCH 04/15] Support objects as column types to maintain backwards compatibility --- Datatable/Column/ColumnBuilder.php | 29 +++++++++++++++++------------ Datatable/Factory.php | 10 +++++----- Resources/config/services.yml | 15 +++++++++++++++ Resources/doc/installation.md | 2 +- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/Datatable/Column/ColumnBuilder.php b/Datatable/Column/ColumnBuilder.php index 72487741..d262f11c 100644 --- a/Datatable/Column/ColumnBuilder.php +++ b/Datatable/Column/ColumnBuilder.php @@ -14,9 +14,15 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\MappingException; use Doctrine\ORM\EntityManagerInterface; +use Sg\DatatablesBundle\Datatable\Factory; use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; use Twig_Environment; use Exception; +use function array_key_exists; +use function sprintf; +use function trigger_error; +use const E_USER_DEPRECATED; +use function get_class; /** * Class ColumnBuilder @@ -88,9 +94,6 @@ class ColumnBuilder * @var \Symfony\Component\DependencyInjection\Argument\RewindableGenerator */ private $columnTypes; - //------------------------------------------------- - // Ctor. - //------------------------------------------------- /** * ColumnBuilder constructor. @@ -132,19 +135,21 @@ public function __construct(ClassMetadata $metadata, Twig_Environment $twig, $da public function add($dql, $class, array $options = array()) { if (is_object($class)) { - throw new \RuntimeException('Use FCQN instead of object: ' . get_class($class)); - } + $column = Factory::create($class, ColumnInterface::class); + @trigger_error(sprintf('Using an object as column type is deprecated since 1.3 and will be removed in 2.0. Use a class name (FQCN) instead.'), E_USER_DEPRECATED); + } else { + $columns = []; + foreach ($this->columnTypes as $column) { + $columns[get_class($column)] = $column; + } - $columns = []; - foreach ($this->columnTypes as $column) { - $columns[get_class($column)] = $column; - } + if (! array_key_exists($class, $columns)) { + throw new \RuntimeException(sprintf('Column %s is not a service', $class)); + } - if (! array_key_exists($class, $columns)) { - throw new \RuntimeException(sprintf('Column %s is not a service', $class)); + $column = clone $columns[$class]; } - $column = clone $columns[$class]; $column->initOptions(); $this->handleDqlProperties($dql, $options, $column); diff --git a/Datatable/Factory.php b/Datatable/Factory.php index 1661bcba..d9a8efdb 100644 --- a/Datatable/Factory.php +++ b/Datatable/Factory.php @@ -31,7 +31,7 @@ class Factory */ public static function create($class, $interface) { - if (empty($class) || !is_string($class) && !$class instanceof $interface) { + if (empty($class) || ( ! is_string($class) && ! $class instanceof $interface)) { throw new Exception("Factory::create(): String or $interface expected."); } @@ -44,11 +44,11 @@ public static function create($class, $interface) if (!$instance instanceof $interface) { throw new Exception("Factory::create(): String or $interface expected."); - } else { - return $instance; } - } else { - throw new Exception("Factory::create(): $class is not callable."); + + return $instance; } + + throw new Exception("Factory::create(): $class is not callable."); } } diff --git a/Resources/config/services.yml b/Resources/config/services.yml index b13c2422..8aa87dee 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -37,3 +37,18 @@ services: - '@twig' Sg\DatatablesBundle\Twig\DatatableTwigExtension: ~ + + # aliases for backwards compatibility, will be removed in 2.0 + sg_datatables.twig.extension: + alias: Sg\DatatablesBundle\Twig\DatatableTwigExtension + + sg_datatables.datatable.abstract: + alias: Sg\DatatablesBundle\Datatable\AbstractDatatable + + sg_datatables.response: + alias: Sg\DatatablesBundle\Response\DatatableResponse + public: true + + sg_datatables.factory: + alias: Sg\DatatablesBundle\Datatable\DatatableFactory + public: true diff --git a/Resources/doc/installation.md b/Resources/doc/installation.md index 4c94d2f4..3ec718d8 100644 --- a/Resources/doc/installation.md +++ b/Resources/doc/installation.md @@ -370,7 +370,7 @@ services: autowire: true AppBundle\Datatables\PostDatatable: bind: - $columns: !tagged sg_datatables.column + $columnTypes: !tagged sg_datatables.column ``` ### Step 3: The Controller actions From 3a1ffbef50f6aa10f681ee15599940a9ebb1f965 Mon Sep 17 00:00:00 2001 From: stephanvierkant Date: Wed, 17 Jul 2019 10:05:07 +0200 Subject: [PATCH 05/15] remove RewindableGenerator from typehinting since it's marked as internal --- Datatable/Column/ColumnBuilder.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Datatable/Column/ColumnBuilder.php b/Datatable/Column/ColumnBuilder.php index d262f11c..e7f113aa 100644 --- a/Datatable/Column/ColumnBuilder.php +++ b/Datatable/Column/ColumnBuilder.php @@ -15,7 +15,6 @@ use Doctrine\ORM\Mapping\MappingException; use Doctrine\ORM\EntityManagerInterface; use Sg\DatatablesBundle\Datatable\Factory; -use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; use Twig_Environment; use Exception; use function array_key_exists; @@ -102,7 +101,7 @@ class ColumnBuilder * @param Twig_Environment $twig * @param string $datatableName * @param EntityManagerInterface $em - * @param RewindableGenerator $columnTypes + * @param iterable $columnTypes */ public function __construct(ClassMetadata $metadata, Twig_Environment $twig, $datatableName, EntityManagerInterface $em, iterable $columnTypes) { From b11f84f83186890519ddf57a4e1124fb74ef8472 Mon Sep 17 00:00:00 2001 From: stephanvierkant Date: Thu, 22 Aug 2019 15:32:37 +0200 Subject: [PATCH 06/15] columnbuilder update --- Datatable/Column/ColumnBuilder.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Datatable/Column/ColumnBuilder.php b/Datatable/Column/ColumnBuilder.php index e7f113aa..b7574b5c 100644 --- a/Datatable/Column/ColumnBuilder.php +++ b/Datatable/Column/ColumnBuilder.php @@ -17,11 +17,6 @@ use Sg\DatatablesBundle\Datatable\Factory; use Twig_Environment; use Exception; -use function array_key_exists; -use function sprintf; -use function trigger_error; -use const E_USER_DEPRECATED; -use function get_class; /** * Class ColumnBuilder @@ -90,7 +85,7 @@ class ColumnBuilder /** * Column services * - * @var \Symfony\Component\DependencyInjection\Argument\RewindableGenerator + * @var iterable */ private $columnTypes; From fb2b2bd111f9511a187795b6f4b37af3302ba77c Mon Sep 17 00:00:00 2001 From: stephanvierkant Date: Thu, 22 Aug 2019 15:35:21 +0200 Subject: [PATCH 07/15] DatatableFactory can be autowired --- Resources/config/services.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 8aa87dee..9e6230cc 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -28,13 +28,6 @@ services: Sg\DatatablesBundle\Datatable\DatatableFactory: public: true - arguments: - - '@security.authorization_checker' - - '@security.token_storage' - - '@translator' - - '@router' - - '@doctrine.orm.entity_manager' - - '@twig' Sg\DatatablesBundle\Twig\DatatableTwigExtension: ~ From 547528d0b0f0a0a1ee1ee706fbd2a52e277fbe9f Mon Sep 17 00:00:00 2001 From: stephanvierkant Date: Thu, 22 Aug 2019 15:37:58 +0200 Subject: [PATCH 08/15] LinkColumn fixed --- Datatable/Column/AbstractColumn.php | 32 ----------------------------- Datatable/Column/LinkColumn.php | 11 ++++++++++ 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/Datatable/Column/AbstractColumn.php b/Datatable/Column/AbstractColumn.php index 00497fb4..681cdac0 100644 --- a/Datatable/Column/AbstractColumn.php +++ b/Datatable/Column/AbstractColumn.php @@ -251,14 +251,6 @@ abstract class AbstractColumn implements ColumnInterface */ protected $twig; - /** - * The Router. - * Is set in the ColumnBuilder. - * - * @var RouterInterface - */ - protected $router; - /** * The position in the Columns array. * Is set in the ColumnBuilder. @@ -961,30 +953,6 @@ public function setTwig(Twig_Environment $twig) return $this; } - /** - * Get Router. - * - * @return RouterInterface - */ - public function getRouter() - { - return $this->router; - } - - /** - * Set Router. - * - * @param RouterInterface $router - * - * @return $this - */ - public function setRouter(RouterInterface $router) - { - $this->router = $router; - - return $this; - } - /** * Get index. * diff --git a/Datatable/Column/LinkColumn.php b/Datatable/Column/LinkColumn.php index d1a4d1ee..22a0be52 100644 --- a/Datatable/Column/LinkColumn.php +++ b/Datatable/Column/LinkColumn.php @@ -15,6 +15,7 @@ use Sg\DatatablesBundle\Datatable\Filter\TextFilter; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Routing\RouterInterface; /** * Class LinkColumn @@ -76,6 +77,16 @@ class LinkColumn extends AbstractColumn */ protected $email; + /** + * @var RouterInterface + */ + private $router; + + public function __construct (RouterInterface $router) + { + $this->router = $router; + } + //------------------------------------------------- // ColumnInterface //------------------------------------------------- From ab5220ab077de365243642b60e590461a24f1a4d Mon Sep 17 00:00:00 2001 From: stephanvierkant Date: Mon, 26 Aug 2019 15:55:46 +0200 Subject: [PATCH 09/15] php-cs-fixer --- Datatable/Column/AbstractColumn.php | 1 - Datatable/Column/ColumnBuilder.php | 9 +++------ Datatable/Column/LinkColumn.php | 2 +- DependencyInjection/SgDatatablesExtension.php | 3 +-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Datatable/Column/AbstractColumn.php b/Datatable/Column/AbstractColumn.php index 133b814d..4ec13985 100644 --- a/Datatable/Column/AbstractColumn.php +++ b/Datatable/Column/AbstractColumn.php @@ -18,7 +18,6 @@ use Sg\DatatablesBundle\Datatable\Editable\EditableInterface; use Sg\DatatablesBundle\Datatable\OptionsTrait; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\Routing\RouterInterface; use Twig_Environment; abstract class AbstractColumn implements ColumnInterface diff --git a/Datatable/Column/ColumnBuilder.php b/Datatable/Column/ColumnBuilder.php index 6b1bdbb4..5cd884fe 100644 --- a/Datatable/Column/ColumnBuilder.php +++ b/Datatable/Column/ColumnBuilder.php @@ -14,11 +14,8 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\MappingException; -use Doctrine\ORM\EntityManagerInterface; -use Sg\DatatablesBundle\Datatable\Factory; use Exception; use Sg\DatatablesBundle\Datatable\Factory; -use Symfony\Component\Routing\RouterInterface; use Twig_Environment; class ColumnBuilder @@ -118,16 +115,16 @@ public function __construct(ClassMetadata $metadata, Twig_Environment $twig, $da */ public function add($dql, $class, array $options = []) { - if (is_object($class)) { + if (\is_object($class)) { $column = Factory::create($class, ColumnInterface::class); @trigger_error(sprintf('Using an object as column type is deprecated since 1.3 and will be removed in 2.0. Use a class name (FQCN) instead.'), E_USER_DEPRECATED); } else { $columns = []; foreach ($this->columnTypes as $column) { - $columns[get_class($column)] = $column; + $columns[\get_class($column)] = $column; } - if (! array_key_exists($class, $columns)) { + if (! \array_key_exists($class, $columns)) { throw new \RuntimeException(sprintf('Column %s is not a service', $class)); } diff --git a/Datatable/Column/LinkColumn.php b/Datatable/Column/LinkColumn.php index 7fcf47d2..2510ce48 100644 --- a/Datatable/Column/LinkColumn.php +++ b/Datatable/Column/LinkColumn.php @@ -74,7 +74,7 @@ class LinkColumn extends AbstractColumn */ private $router; - public function __construct (RouterInterface $router) + public function __construct(RouterInterface $router) { $this->router = $router; } diff --git a/DependencyInjection/SgDatatablesExtension.php b/DependencyInjection/SgDatatablesExtension.php index 1d949454..ad23cd40 100644 --- a/DependencyInjection/SgDatatablesExtension.php +++ b/DependencyInjection/SgDatatablesExtension.php @@ -12,7 +12,6 @@ namespace Sg\DatatablesBundle\DependencyInjection; use Sg\DatatablesBundle\Datatable\Column\ColumnInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; @@ -34,7 +33,7 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('sg_datatables.datatable.query', $config['datatable']['query']); $container->registerForAutoconfiguration(ColumnInterface::class) - ->addTag('sg_datatables.column') + ->addTag('sg_datatables.column') ; } From 1d665756098583df72193e4fc3d40586a4758108 Mon Sep 17 00:00:00 2001 From: Stephan Vierkant Date: Mon, 6 Apr 2020 15:31:22 +0200 Subject: [PATCH 10/15] fix --- Datatable/AbstractDatatable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Datatable/AbstractDatatable.php b/Datatable/AbstractDatatable.php index 11c86241..88457653 100755 --- a/Datatable/AbstractDatatable.php +++ b/Datatable/AbstractDatatable.php @@ -178,7 +178,7 @@ public function __construct( $this->twig = $twig; $metadata = $em->getClassMetadata($this->getEntity()); - $this->columnBuilder = new ColumnBuilder($metadata, $twig, $router, $this->getName(), $em, $columnTypes); + $this->columnBuilder = new ColumnBuilder($metadata, $twig, $this->getName(), $em, $columnTypes); $this->ajax = new Ajax(); $this->options = new Options(); From 44cfe0aed19a7e92e3ffd0f2f5b240dacaee2da9 Mon Sep 17 00:00:00 2001 From: Stephan Vierkant Date: Tue, 30 Nov 2021 21:05:12 +0100 Subject: [PATCH 11/15] php 8.1 fix --- Datatable/Column/NumberColumn.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Datatable/Column/NumberColumn.php b/Datatable/Column/NumberColumn.php index f03396f5..97604527 100644 --- a/Datatable/Column/NumberColumn.php +++ b/Datatable/Column/NumberColumn.php @@ -221,6 +221,8 @@ private function renderTemplate($data, $pk = null, $path = null) } $data = $this->formatter->formatCurrency($data, $this->currency); + } elseif ($data === null) { + $data = null; } else { // expected number (int or float), other values will be converted to a numeric value $data = $this->formatter->format($data); From b9df98e526ac7582f12bb7636f775820acbdf533 Mon Sep 17 00:00:00 2001 From: Stephan Vierkant Date: Sat, 15 Jan 2022 15:15:43 +0100 Subject: [PATCH 12/15] Update composer.json --- composer.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index d43dba8e..5fd5765c 100755 --- a/composer.json +++ b/composer.json @@ -21,16 +21,16 @@ "php": ">=7.1", "doctrine/orm": "^2.5", "friendsofsymfony/jsrouting-bundle": "^1.6|^2.0|^3.0", - "symfony/config": "^3.4|^4.1|^5.0", - "symfony/dependency-injection": "^3.4|^4.1|^5.0", - "symfony/http-foundation": "^3.4|^4.1|^5.0", - "symfony/http-kernel": "^3.4|^4.1|^5.0", - "symfony/framework-bundle": "^3.4|^4.1|^5.0", - "symfony/options-resolver": "^3.4|^4.1|^5.0", - "symfony/property-access": "^3.4|^4.1|^5.0", - "symfony/routing": "^3.4|^4.1|^5.0", - "symfony/security-core": "^3.4|^4.1|^5.0", - "symfony/translation": "^3.4|^4.1|^5.0", + "symfony/config": "^4.4 || ^5.3 || ^6.0", + "symfony/dependency-injection": "^4.4 || ^5.3 || ^6.0", + "symfony/http-foundation": "^4.4 || ^5.3 || ^6.0", + "symfony/http-kernel": "^4.4 || ^5.3 || ^6.0", + "symfony/framework-bundle": "^4.4 || ^5.3 || ^6.0", + "symfony/options-resolver": "^4.4 || ^5.3 || ^6.0", + "symfony/property-access": "^4.4 || ^5.3 || ^6.0", + "symfony/routing": "^4.4 || ^5.3 || ^6.0", + "symfony/security-core": "^4.4 || ^5.3 || ^6.0", + "symfony/translation": "^4.4 || ^5.3 || ^6.0", "twig/twig": "^2.9|^3.0" }, "require-dev": { From 8f16674caff09d0d194963e170e7a4843ff42084 Mon Sep 17 00:00:00 2001 From: Stephan Vierkant Date: Fri, 17 Feb 2023 10:35:51 +0100 Subject: [PATCH 13/15] PHP Deprecated: Creation of dynamic property Sg\DatatablesBundle\Response\DatatableQueryBuilder::$columnNames is deprecated --- Response/DatatableQueryBuilder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Response/DatatableQueryBuilder.php b/Response/DatatableQueryBuilder.php index f7aa60be..6a338986 100644 --- a/Response/DatatableQueryBuilder.php +++ b/Response/DatatableQueryBuilder.php @@ -188,6 +188,7 @@ class DatatableQueryBuilder //------------------------------------------------- // Ctor. && Init column arrays //------------------------------------------------- + private $columnNames; /** * @throws Exception From bba15cd36294d304ec8d60656db900434fb7cf59 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 19 Dec 2023 09:56:57 +0100 Subject: [PATCH 14/15] allow symfony 7 --- composer.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 27d1e1cf..8494161a 100755 --- a/composer.json +++ b/composer.json @@ -21,16 +21,16 @@ "php": ">=7.2|>=8.0", "doctrine/orm": "^2.5", "friendsofsymfony/jsrouting-bundle": "^2.0|^3.0", - "symfony/config": "^4.4|^5.4|^6.0", - "symfony/dependency-injection": "^4.4|^5.4|^6.0", - "symfony/http-foundation": "^4.4|^5.4|^6.0", - "symfony/http-kernel": "^4.4|^5.4|^6.0", - "symfony/framework-bundle": "^4.4|^5.4|^6.0", - "symfony/options-resolver": "^4.4|^5.4|^6.0", - "symfony/property-access": "^4.4|^5.4|^6.0", - "symfony/routing": "^4.4|^5.4|^6.0", - "symfony/security-core": "^4.4|^5.4|^6.0", - "symfony/translation": "^4.4|^5.4|^6.0", + "symfony/config": "^4.4|^5.4|^6.0|^7.0", + "symfony/dependency-injection": "^4.4|^5.4|^6.0|^7.0", + "symfony/http-foundation": "^4.4|^5.4|^6.0|^7.0", + "symfony/http-kernel": "^4.4|^5.4|^6.0|^7.0", + "symfony/framework-bundle": "^4.4|^5.4|^6.0|^7.0", + "symfony/options-resolver": "^4.4|^5.4|^6.0|^7.0", + "symfony/property-access": "^4.4|^5.4|^6.0|^7.0", + "symfony/routing": "^4.4|^5.4|^6.0|^7.0", + "symfony/security-core": "^4.4|^5.4|^6.0|^7.0", + "symfony/translation": "^4.4|^5.4|^6.0|^7.0", "twig/twig": "^2.9|^3.0" }, "require-dev": { From 661d4fefe8a3f5cccdace3b4eec192ee3b67564f Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 1 Feb 2024 15:16:28 +0100 Subject: [PATCH 15/15] TreeBuilder as return type --- DependencyInjection/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a0fea356..b2d82740 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -20,7 +20,7 @@ class Configuration implements ConfigurationInterface /** * {@inheritdoc} */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('sg_datatables'); if (method_exists($treeBuilder, 'getRootNode')) {