|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\SeoBundle\Sitemap; |
|
15
|
|
|
|
|
16
|
|
|
use ArrayIterator; |
|
17
|
|
|
use Sonata\Exporter\Source\ChainSourceIterator; |
|
18
|
|
|
use Sonata\Exporter\Source\SourceIteratorInterface; |
|
19
|
|
|
use stdClass; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Manager several chain source iterator grouped. |
|
23
|
|
|
*/ |
|
24
|
|
|
final class SourceManager implements SourceIteratorInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var \ArrayIterator |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $sources; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->sources = new ArrayIterator(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Adding source with his group. |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $group |
|
40
|
|
|
*/ |
|
41
|
|
|
public function addSource($group, SourceIteratorInterface $source, array $types = []): void |
|
42
|
|
|
{ |
|
43
|
|
|
if (!isset($this->sources[$group])) { |
|
44
|
|
|
$this->sources[$group] = new stdClass(); |
|
45
|
|
|
|
|
46
|
|
|
$this->sources[$group]->sources = new ChainSourceIterator(); |
|
47
|
|
|
$this->sources[$group]->types = []; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->sources[$group]->sources->addSource($source); |
|
51
|
|
|
|
|
52
|
|
|
if ($types) { |
|
|
|
|
|
|
53
|
|
|
$this->sources[$group]->types += array_diff($types, $this->sources[$group]->types); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function current() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->sources->current(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function next(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->sources->next(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function key() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->sources->key(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function valid() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->sources->valid(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function rewind(): void |
|
78
|
|
|
{ |
|
79
|
|
|
$this->sources->rewind(); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.