comparison vendor/symfony/translation/Catalogue/MergeOperation.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Translation\Catalogue;
13
14 /**
15 * Merge operation between two catalogues as follows:
16 * all = source ∪ target = {x: x ∈ source ∨ x ∈ target}
17 * new = all ∖ source = {x: x ∈ target ∧ x ∉ source}
18 * obsolete = source ∖ all = {x: x ∈ source ∧ x ∉ source ∧ x ∉ target} = ∅
19 * Basically, the result contains messages from both catalogues.
20 *
21 * @author Jean-François Simon <contact@jfsimon.fr>
22 */
23 class MergeOperation extends AbstractOperation
24 {
25 /**
26 * {@inheritdoc}
27 */
28 protected function processDomain($domain)
29 {
30 $this->messages[$domain] = array(
31 'all' => array(),
32 'new' => array(),
33 'obsolete' => array(),
34 );
35
36 foreach ($this->source->all($domain) as $id => $message) {
37 $this->messages[$domain]['all'][$id] = $message;
38 $this->result->add(array($id => $message), $domain);
39 if (null !== $keyMetadata = $this->source->getMetadata($id, $domain)) {
40 $this->result->setMetadata($id, $keyMetadata, $domain);
41 }
42 }
43
44 foreach ($this->target->all($domain) as $id => $message) {
45 if (!$this->source->has($id, $domain)) {
46 $this->messages[$domain]['all'][$id] = $message;
47 $this->messages[$domain]['new'][$id] = $message;
48 $this->result->add(array($id => $message), $domain);
49 if (null !== $keyMetadata = $this->target->getMetadata($id, $domain)) {
50 $this->result->setMetadata($id, $keyMetadata, $domain);
51 }
52 }
53 }
54 }
55 }