1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2015-2017 Libre Informatique |
6
|
|
|
* |
7
|
|
|
* This file is licenced under the GNU LGPL v3. |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Blast\Bundle\CoreBundle\DataSource; |
13
|
|
|
|
14
|
|
|
use Exporter\Source\DoctrineORMQuerySourceIterator; |
15
|
|
|
use Doctrine\ORM\PersistentCollection; |
16
|
|
|
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; |
17
|
|
|
|
18
|
|
|
class Iterator extends DoctrineORMQuerySourceIterator |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
* Allows to get back embedded arrays, in 2 dimensions max. |
23
|
|
|
* e.g.: fields positions.name & positions.organism.name will be returned as : |
24
|
|
|
* [ |
25
|
|
|
* 'name' => 'myEntity', |
26
|
|
|
* 'positions' => [ |
27
|
|
|
* ['name' => 'XXX', 'organism.name' => 'YYY'], |
28
|
|
|
* ['name' => 'AAA', 'organism.name' => 'BBB'], |
29
|
|
|
* ] |
30
|
|
|
* ];. |
31
|
|
|
*/ |
32
|
|
|
public function current() |
33
|
|
|
{ |
34
|
|
|
$data = []; |
35
|
|
|
$propertyPaths = $this->propertyPaths; |
36
|
|
|
|
37
|
|
|
// then complete it for "fields" representing a collection of sub-entities |
38
|
|
|
foreach ($this->propertyPaths as $i => $propertyPath) { |
39
|
|
|
try { |
40
|
|
|
if (($property = $this->propertyAccessor->getValue($this->iterator->current()[0], $propertyPath)) instanceof PersistentCollection) { |
|
|
|
|
41
|
|
View Code Duplication |
if (!(isset($data[(string) $propertyPath]) && is_array($data[(string) $propertyPath]))) { |
|
|
|
|
42
|
|
|
$data[(string) $propertyPath] = []; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
foreach ($property as $subEntity) { |
46
|
|
|
$data[(string) $propertyPath][] = (string) $subEntity; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
unset($this->propertyPaths[$i]); |
50
|
|
|
} |
51
|
|
|
} catch (NoSuchPropertyException $e) { |
52
|
|
|
$collection = preg_replace('/\..+$/', '', $propertyPath); |
53
|
|
|
$subProperty = preg_replace('/^.+\./U', '', $propertyPath); |
54
|
|
|
if ($collection != (string) $propertyPath && $subProperty) { |
55
|
|
|
if (($property = $this->propertyAccessor->getValue($this->iterator->current()[0], $collection)) instanceof PersistentCollection) { |
|
|
|
|
56
|
|
View Code Duplication |
if (!(isset($data[$collection]) && is_array($data[$collection]))) { |
|
|
|
|
57
|
|
|
$data[$collection] = []; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
foreach ($property as $subEntity) { |
61
|
|
|
$data[$collection][spl_object_hash($subEntity)][$subProperty] = (string) $this->propertyAccessor->getValue($subEntity, $subProperty); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
unset($this->propertyPaths[$i]); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
// first do the "normal" stuff |
70
|
|
|
$data = array_merge($data, parent::current()); |
71
|
|
|
|
72
|
|
|
$this->propertyPaths = $propertyPaths; |
73
|
|
|
|
74
|
|
|
return $data; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* getQuery(). |
79
|
|
|
* |
80
|
|
|
* @return Doctrine\ORM\Query |
81
|
|
|
**/ |
82
|
|
|
public function getQuery() |
83
|
|
|
{ |
84
|
|
|
return $this->query; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.