Skip to content
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 .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// see https://github.com/FriendsOfPHP/PHP-CS-Fixer

$finder = PhpCsFixer\Finder::create()
->in([__DIR__.'/src', __DIR__.'/tests'])
->in([__DIR__.'/config', __DIR__.'/src', __DIR__.'/tests'])
;

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP80Migration:risky' => true,
'@PHP81Migration' => true,
'@PHPUnit100Migration:risky' => true,
'@PHP8x0Migration:risky' => true,
'@PHP8x1Migration' => true,
'@PHPUnit10x0Migration:risky' => true,
'ordered_imports' => true,
'declare_strict_types' => false,
'native_function_invocation' => ['include' => ['@all']],
'native_function_invocation' => ['include' => ['@all'], 'exclude' => ['param', 'service']],
'final_class' => true,
'php_unit_mock_short_will_return' => true,
])
Expand Down
91 changes: 91 additions & 0 deletions config/paginator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Knp\Bundle\PaginatorBundle\Helper\Processor;
use Knp\Bundle\PaginatorBundle\Subscriber\SlidingPaginationSubscriber;
use Knp\Bundle\PaginatorBundle\Twig\Extension\PaginationExtension;
use Knp\Bundle\PaginatorBundle\Twig\Extension\PaginationRuntime;
use Knp\Component\Pager\ArgumentAccess\ArgumentAccessInterface;
use Knp\Component\Pager\ArgumentAccess\RequestArgumentAccess;
use Knp\Component\Pager\Event\Subscriber\Filtration\FiltrationSubscriber;
use Knp\Component\Pager\Event\Subscriber\Paginate\PaginationSubscriber;
use Knp\Component\Pager\Event\Subscriber\Sortable\SortableSubscriber;
use Knp\Component\Pager\Paginator;
use Knp\Component\Pager\PaginatorInterface;

return static function (ContainerConfigurator $configurator): void {
$services = $configurator->services();

$services
->set('knp_paginator', Paginator::class)
->public()
->lazy()
->args([
service('event_dispatcher'),
service(ArgumentAccessInterface::class),
service('database_connection')->nullOnInvalid(),
])
->tag('proxy', ['interface' => PaginatorInterface::class])
;

$services->alias(PaginatorInterface::class, 'knp_paginator');

$services
->set(RequestArgumentAccess::class)
->args([service('request_stack')])
;

$services->alias(ArgumentAccessInterface::class, RequestArgumentAccess::class);

$services
->set('knp_paginator.subscriber.paginate', PaginationSubscriber::class)
->tag('kernel.event_subscriber')
;

$services
->set('knp_paginator.subscriber.sortable', SortableSubscriber::class)
->tag('kernel.event_subscriber')
;

$services
->set('knp_paginator.subscriber.filtration', FiltrationSubscriber::class)
->tag('kernel.event_subscriber')
;

$services->set('knp_paginator.subscriber.sliding_pagination', SlidingPaginationSubscriber::class)
->arg(0, [
'defaultPaginationTemplate' => '%knp_paginator.template.pagination%',
'defaultRelLinksTemplate' => '%knp_paginator.template.rel_links%',
'defaultSortableTemplate' => '%knp_paginator.template.sortable%',
'defaultFiltrationTemplate' => '%knp_paginator.template.filtration%',
'defaultPageRange' => '%knp_paginator.page_range%',
'defaultPageLimit' => '%knp_paginator.page_limit%',
])
->tag('kernel.event_subscriber')
->tag('kernel.event_listener', ['event' => 'kernel.request', 'method' => 'onKernelRequest'])
;

$services
->set('knp_paginator.helper.processor', Processor::class)
->args([
service('router'),
service('translator')->nullOnInvalid(),
])
;

$services
->set('knp_paginator.twig.extension.pagination', PaginationExtension::class)
->tag('twig.extension')
;

$services
->set(PaginationRuntime::class)
->args([
service('knp_paginator.helper.processor'),
param('knp_paginator.page_name'),
param('knp_paginator.remove_first_page_param'),
])
->tag('twig.runtime')
;
};
64 changes: 0 additions & 64 deletions config/paginator.xml

This file was deleted.

20 changes: 20 additions & 0 deletions config/templating_php.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Knp\Bundle\PaginatorBundle\Templating\PaginationHelper;

return static function (ContainerConfigurator $configurator): void {
$configurator
->parameters()
->set('knp_paginator.templating.helper.pagination.class', PaginationHelper::class)
;

$configurator
->services()
->set('knp_paginator.templating.helper.pagination', param('knp_paginator.templating.helper.pagination.class'))
->arg(0, service('knp_paginator.helper.processor'))
->arg(1, service('templating.engine.php'))
->tag('templating.helper', ['alias' => 'knp_pagination'])
;
};
18 changes: 0 additions & 18 deletions config/templating_php.xml

This file was deleted.

13 changes: 4 additions & 9 deletions src/DependencyInjection/KnpPaginatorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,22 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;

final class KnpPaginatorExtension extends Extension
{
/**
* Build the extension services.
*
* @param array<string, array<string, mixed>> $configs
*/
public function load(array $configs, ContainerBuilder $container): void
{
$processor = new Processor();

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('paginator.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('paginator.php');

if ($container->hasParameter('templating.engines')) {
/** @var array<string> $engines */
$engines = $container->getParameter('templating.engines');
if (\in_array('php', $engines, true)) {
$loader->load('templating_php.xml');
$loader->load('templating_php.php');
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/DependencyInjection/Compiler/PaginatorAwarePassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;

final class PaginatorAwarePassTest extends TestCase
Expand Down Expand Up @@ -57,8 +57,8 @@ public function testExceptionNoPaginator(): void
public function testProxyAndLazy(): void
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../config'));
$loader->load('paginator.xml');
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../../config'));
$loader->load('paginator.php');
$container->register('knp.paginator');

$definition = $container->getDefinition('knp_paginator');
Expand Down