Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\Translation\Catalogue;
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Merge operation between two catalogues as follows:
|
Chris@0
|
16 * all = source ∪ target = {x: x ∈ source ∨ x ∈ target}
|
Chris@0
|
17 * new = all ∖ source = {x: x ∈ target ∧ x ∉ source}
|
Chris@0
|
18 * obsolete = source ∖ all = {x: x ∈ source ∧ x ∉ source ∧ x ∉ target} = ∅
|
Chris@0
|
19 * Basically, the result contains messages from both catalogues.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @author Jean-François Simon <contact@jfsimon.fr>
|
Chris@0
|
22 */
|
Chris@0
|
23 class MergeOperation extends AbstractOperation
|
Chris@0
|
24 {
|
Chris@0
|
25 /**
|
Chris@0
|
26 * {@inheritdoc}
|
Chris@0
|
27 */
|
Chris@0
|
28 protected function processDomain($domain)
|
Chris@0
|
29 {
|
Chris@17
|
30 $this->messages[$domain] = [
|
Chris@17
|
31 'all' => [],
|
Chris@17
|
32 'new' => [],
|
Chris@17
|
33 'obsolete' => [],
|
Chris@17
|
34 ];
|
Chris@0
|
35
|
Chris@0
|
36 foreach ($this->source->all($domain) as $id => $message) {
|
Chris@0
|
37 $this->messages[$domain]['all'][$id] = $message;
|
Chris@17
|
38 $this->result->add([$id => $message], $domain);
|
Chris@0
|
39 if (null !== $keyMetadata = $this->source->getMetadata($id, $domain)) {
|
Chris@0
|
40 $this->result->setMetadata($id, $keyMetadata, $domain);
|
Chris@0
|
41 }
|
Chris@0
|
42 }
|
Chris@0
|
43
|
Chris@0
|
44 foreach ($this->target->all($domain) as $id => $message) {
|
Chris@0
|
45 if (!$this->source->has($id, $domain)) {
|
Chris@0
|
46 $this->messages[$domain]['all'][$id] = $message;
|
Chris@0
|
47 $this->messages[$domain]['new'][$id] = $message;
|
Chris@17
|
48 $this->result->add([$id => $message], $domain);
|
Chris@0
|
49 if (null !== $keyMetadata = $this->target->getMetadata($id, $domain)) {
|
Chris@0
|
50 $this->result->setMetadata($id, $keyMetadata, $domain);
|
Chris@0
|
51 }
|
Chris@0
|
52 }
|
Chris@0
|
53 }
|
Chris@0
|
54 }
|
Chris@0
|
55 }
|