1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pagination; |
4
|
|
|
|
5
|
|
|
use Pimple\Container; |
6
|
|
|
use Pimple\ServiceProviderInterface; |
7
|
|
|
use Silex\Application; |
8
|
|
|
use Symfony\Component\Translation\Translator; |
9
|
|
|
|
10
|
|
|
class PaginationServiceProvider implements ServiceProviderInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* |
14
|
|
|
* @param Container $app |
15
|
|
|
*/ |
16
|
5 |
|
public function register(Container $app) |
17
|
|
|
{ |
18
|
5 |
|
$app['paginator.options'] = [ |
19
|
5 |
|
'offset_page' => 2, |
20
|
5 |
|
'page_param' => 'page', |
21
|
5 |
|
'items_per_page' => 10, |
22
|
5 |
|
'hide_prev_next' => true, |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
$app['paginator'] = $app->factory(function ($app) { |
26
|
3 |
|
$app['paginator.options'] = array_replace([ |
27
|
3 |
|
'offset_page' => 2, |
28
|
3 |
|
'page_param' => 'page', |
29
|
3 |
|
'items_per_page' => 10, |
30
|
3 |
|
'hide_prev_next' => true, |
31
|
3 |
|
], $app['paginator.options']); |
32
|
|
|
|
33
|
3 |
|
return new \Pagination\Util\Paginator($app); |
|
|
|
|
34
|
5 |
|
}); |
35
|
|
|
|
36
|
5 |
|
if (!$app->offsetExists('twig')) { |
37
|
5 |
|
$app->register(new \Silex\Provider\TwigServiceProvider()); |
38
|
5 |
|
} |
39
|
|
|
|
40
|
5 |
|
if (!$app->offsetExists('translator')) { |
41
|
5 |
|
$app->register(new \Silex\Provider\TranslationServiceProvider()); |
42
|
5 |
|
} |
43
|
|
|
|
44
|
|
|
$app['twig'] = $app->extend('twig', function (\Twig_Environment $twig) { |
45
|
|
|
$twig->addExtension(new Twig\TwigExtension()); |
46
|
|
|
|
47
|
|
|
return $twig; |
48
|
5 |
|
}); |
49
|
|
|
|
50
|
5 |
|
if (isset($app['twig.path']) && !is_array($app['twig.path'])) { |
51
|
|
|
$app['twig.path'] = [$app['twig.path']]; |
52
|
|
|
} |
53
|
|
|
|
54
|
5 |
|
$app['twig.path'] = array_merge_recursive($app['twig.path'], [ |
55
|
5 |
|
__DIR__.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'views', |
56
|
5 |
|
]); |
57
|
|
|
|
58
|
5 |
|
$app['translator'] = $app->extend('translator', function (Translator $translator, Application $app) { |
|
|
|
|
59
|
|
|
$translationDirectory = __DIR__.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'translations'; |
60
|
|
|
$translator->addResource('yaml', $translationDirectory.DIRECTORY_SEPARATOR.'messages.bg.yml', 'bg'); |
61
|
|
|
$translator->addResource('yaml', $translationDirectory.DIRECTORY_SEPARATOR.'messages.en.yml', 'en'); |
62
|
|
|
|
63
|
|
|
return $translator; |
64
|
5 |
|
}); |
65
|
5 |
|
} |
66
|
|
|
} |
67
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: