|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Pagerfanta package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Pablo Díez <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WhiteOctober\PagerfantaBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\FileLocator; |
|
15
|
|
|
use Symfony\Component\Config\Definition\Processor; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
19
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* WhiteOctoberPagerfantaExtension. |
|
23
|
|
|
* |
|
24
|
|
|
* @author Pablo Díez <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class WhiteOctoberPagerfantaExtension extends Extension |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Responds to the "white_october_pagerfanta" configuration parameter. |
|
30
|
|
|
* |
|
31
|
|
|
* @param array $configs |
|
32
|
|
|
* @param ContainerBuilder $container |
|
33
|
|
|
*/ |
|
34
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
35
|
|
|
{ |
|
36
|
|
|
$configuration = new Configuration(); |
|
37
|
|
|
$processor = new Processor(); |
|
38
|
|
|
|
|
39
|
|
|
$config = $processor->processConfiguration($configuration, $configs); |
|
40
|
|
|
$container->setParameter('white_october_pagerfanta.default_view', $config['default_view']); |
|
41
|
|
|
|
|
42
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
43
|
|
|
$loader->load('pagerfanta.xml'); |
|
44
|
|
|
|
|
45
|
|
|
if ($config['exceptions_strategy']['out_of_range_page'] == Configuration::EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND) { |
|
46
|
|
|
$convertListener = $container->getDefinition('pagerfanta.convert_not_valid_max_per_page_to_not_found_listener'); |
|
47
|
|
|
$convertListener->addTag('kernel.event_subscriber'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if ($config['exceptions_strategy']['not_valid_current_page'] == Configuration::EXCEPTION_STRATEGY_TO_HTTP_NOT_FOUND) { |
|
51
|
|
|
$convertListener = $container->getDefinition('pagerfanta.convert_not_valid_current_page_to_not_found_listener'); |
|
52
|
|
|
$convertListener->addTag('kernel.event_subscriber'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
// BC layer to inject the 'request' service when RequestStack is unavailable |
|
56
|
|
|
if (!class_exists('Symfony\\Component\\HttpFoundation\\RequestStack')) { |
|
57
|
|
|
$container |
|
58
|
|
|
->getDefinition('twig.extension.pagerfanta') |
|
59
|
|
|
->addMethodCall('setRequest', array( |
|
60
|
|
|
new Reference('request', ContainerInterface::NULL_ON_INVALID_REFERENCE, false), |
|
61
|
|
|
)) |
|
62
|
|
|
; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|