blob: 87db2fb031d96a904b9946456dfa6f605f02d140 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?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
12namespace Symfony\Component\Translation\Catalogue;
13
14use Symfony\Component\Translation\MessageCatalogueInterface;
15
16/**
17 * Merge operation between two catalogues as follows:
18 * all = source ∪ target = {x: x ∈ source ∨ x ∈ target}
19 * new = all ∖ source = {x: x ∈ target ∧ x ∉ source}
20 * obsolete = source ∖ all = {x: x ∈ source ∧ x ∉ source ∧ x ∉ target} = ∅
21 * Basically, the result contains messages from both catalogues.
22 *
23 * @author Jean-François Simon <contact@jfsimon.fr>
24 */
25class MergeOperation extends AbstractOperation
26{
27 /**
28 * {@inheritdoc}
29 */
30 protected function processDomain(string $domain)
31 {
32 $this->messages[$domain] = [
33 'all' => [],
34 'new' => [],
35 'obsolete' => [],
36 ];
37 $intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
38
39 foreach ($this->source->all($domain) as $id => $message) {
40 $this->messages[$domain]['all'][$id] = $message;
41 $d = $this->source->defines($id, $intlDomain) ? $intlDomain : $domain;
42 $this->result->add([$id => $message], $d);
43 if (null !== $keyMetadata = $this->source->getMetadata($id, $d)) {
44 $this->result->setMetadata($id, $keyMetadata, $d);
45 }
46 }
47
48 foreach ($this->target->all($domain) as $id => $message) {
49 if (!$this->source->has($id, $domain)) {
50 $this->messages[$domain]['all'][$id] = $message;
51 $this->messages[$domain]['new'][$id] = $message;
52 $d = $this->target->defines($id, $intlDomain) ? $intlDomain : $domain;
53 $this->result->add([$id => $message], $d);
54 if (null !== $keyMetadata = $this->target->getMetadata($id, $d)) {
55 $this->result->setMetadata($id, $keyMetadata, $d);
56 }
57 }
58 }
59 }
60}