Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Catalogue/MergeOperation.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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 use 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 <[email protected]>
24 */
25 class MergeOperation extends AbstractOperation
26 {
27 protected function processDomain(string $domain): void
28 {
29 $this->messages[$domain] = [
30 'all' => [],
31 'new' => [],
32 'obsolete' => [],
33 ];
34 $intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
35
36 foreach ($this->target->getCatalogueMetadata('', $domain) ?? [] as $key => $value) {
37 if (null === $this->result->getCatalogueMetadata($key, $domain)) {
38 $this->result->setCatalogueMetadata($key, $value, $domain);
39 }
40 }
41
42 foreach ($this->target->getCatalogueMetadata('', $intlDomain) ?? [] as $key => $value) {
43 if (null === $this->result->getCatalogueMetadata($key, $intlDomain)) {
44 $this->result->setCatalogueMetadata($key, $value, $intlDomain);
45 }
46 }
47
48 foreach ($this->source->all($domain) as $id => $message) {
49 $this->messages[$domain]['all'][$id] = $message;
50 $d = $this->source->defines($id, $intlDomain) ? $intlDomain : $domain;
51 $this->result->add([$id => $message], $d);
52 if (null !== $keyMetadata = $this->source->getMetadata($id, $d)) {
53 $this->result->setMetadata($id, $keyMetadata, $d);
54 }
55 }
56
57 foreach ($this->target->all($domain) as $id => $message) {
58 if (!$this->source->has($id, $domain)) {
59 $this->messages[$domain]['all'][$id] = $message;
60 $this->messages[$domain]['new'][$id] = $message;
61 $d = $this->target->defines($id, $intlDomain) ? $intlDomain : $domain;
62 $this->result->add([$id => $message], $d);
63 if (null !== $keyMetadata = $this->target->getMetadata($id, $d)) {
64 $this->result->setMetadata($id, $keyMetadata, $d);
65 }
66 }
67 }
68 }
69 }