1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSElasticaBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
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 FOS\ElasticaBundle\Doctrine; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
15
|
|
|
use FOS\ElasticaBundle\Provider\PagerfantaPager; |
16
|
|
|
use FOS\ElasticaBundle\Provider\PagerProviderInterface; |
17
|
|
|
use Pagerfanta\Adapter\DoctrineODMPhpcrAdapter; |
18
|
|
|
use Pagerfanta\Pagerfanta; |
19
|
|
|
|
20
|
|
|
final class PHPCRPagerProvider implements PagerProviderInterface |
21
|
|
|
{ |
22
|
|
|
const ENTITY_ALIAS = 'a'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $objectClass; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ManagerRegistry |
31
|
|
|
*/ |
32
|
|
|
private $doctrine; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private $baseOptions; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var RegisterListenersService |
41
|
|
|
*/ |
42
|
|
|
private $registerListenersService; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param ManagerRegistry $doctrine |
46
|
|
|
* @param RegisterListenersService $registerListenersService |
47
|
|
|
* @param string $objectClass |
48
|
|
|
* @param array $baseOptions |
49
|
|
|
*/ |
50
|
|
View Code Duplication |
public function __construct(ManagerRegistry $doctrine, RegisterListenersService $registerListenersService, $objectClass, array $baseOptions) |
51
|
|
|
{ |
52
|
|
|
$this->doctrine = $doctrine; |
53
|
|
|
$this->objectClass = $objectClass; |
54
|
|
|
$this->baseOptions = $baseOptions; |
55
|
|
|
$this->registerListenersService = $registerListenersService; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function provide(array $options = array()) |
62
|
|
|
{ |
63
|
|
|
$options = array_replace($this->baseOptions, $options); |
64
|
|
|
|
65
|
|
|
$manager = $this->doctrine->getManagerForClass($this->objectClass); |
66
|
|
|
$repository = $manager->getRepository($this->objectClass); |
67
|
|
|
|
68
|
|
|
$adapter = new DoctrineODMPhpcrAdapter( |
69
|
|
|
call_user_func([$repository, $options['query_builder_method']], static::ENTITY_ALIAS) |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$pager = new PagerfantaPager(new Pagerfanta($adapter)); |
73
|
|
|
|
74
|
|
|
$this->registerListenersService->register($manager, $pager, $options); |
|
|
|
|
75
|
|
|
|
76
|
|
|
return $pager; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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: