Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Catalogue/TargetOperation.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 * Target operation between two catalogues:
18 * intersection = source ∩ target = {x: x ∈ source ∧ x ∈ target}
19 * all = intersection ∪ (target ∖ intersection) = target
20 * new = all ∖ source = {x: x ∈ target ∧ x ∉ source}
21 * obsolete = source ∖ all = source ∖ target = {x: x ∈ source ∧ x ∉ target}
22 * Basically, the result contains messages from the target catalogue.
23 *
24 * @author Michael Lee <[email protected]>
25 */
26 class TargetOperation extends AbstractOperation
27 {
28 protected function processDomain(string $domain): void
29 {
30 $this->messages[$domain] = [
31 'all' => [],
32 'new' => [],
33 'obsolete' => [],
34 ];
35 $intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
36
37 foreach ($this->target->getCatalogueMetadata('', $domain) ?? [] as $key => $value) {
38 if (null === $this->result->getCatalogueMetadata($key, $domain)) {
39 $this->result->setCatalogueMetadata($key, $value, $domain);
40 }
41 }
42
43 foreach ($this->target->getCatalogueMetadata('', $intlDomain) ?? [] as $key => $value) {
44 if (null === $this->result->getCatalogueMetadata($key, $intlDomain)) {
45 $this->result->setCatalogueMetadata($key, $value, $intlDomain);
46 }
47 }
48
49 // For 'all' messages, the code can't be simplified as ``$this->messages[$domain]['all'] = $target->all($domain);``,
50 // because doing so will drop messages like {x: x ∈ source ∧ x ∉ target.all ∧ x ∈ target.fallback}
51 //
52 // For 'new' messages, the code can't be simplified as ``array_diff_assoc($this->target->all($domain), $this->source->all($domain));``
53 // because doing so will not exclude messages like {x: x ∈ target ∧ x ∉ source.all ∧ x ∈ source.fallback}
54 //
55 // For 'obsolete' messages, the code can't be simplified as ``array_diff_assoc($this->source->all($domain), $this->target->all($domain))``
56 // because doing so will not exclude messages like {x: x ∈ source ∧ x ∉ target.all ∧ x ∈ target.fallback}
57
58 foreach ($this->source->all($domain) as $id => $message) {
59 if ($this->target->has($id, $domain)) {
60 $this->messages[$domain]['all'][$id] = $message;
61 $d = $this->source->defines($id, $intlDomain) ? $intlDomain : $domain;
62 $this->result->add([$id => $message], $d);
63 if (null !== $keyMetadata = $this->source->getMetadata($id, $d)) {
64 $this->result->setMetadata($id, $keyMetadata, $d);
65 }
66 } else {
67 $this->messages[$domain]['obsolete'][$id] = $message;
68 }
69 }
70
71 foreach ($this->target->all($domain) as $id => $message) {
72 if (!$this->source->has($id, $domain)) {
73 $this->messages[$domain]['all'][$id] = $message;
74 $this->messages[$domain]['new'][$id] = $message;
75 $d = $this->target->defines($id, $intlDomain) ? $intlDomain : $domain;
76 $this->result->add([$id => $message], $d);
77 if (null !== $keyMetadata = $this->target->getMetadata($id, $d)) {
78 $this->result->setMetadata($id, $keyMetadata, $d);
79 }
80 }
81 }
82 }
83 }