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 * Target operation between two catalogues:
|
Chris@0
|
16 * intersection = source ∩ target = {x: x ∈ source ∧ x ∈ target}
|
Chris@0
|
17 * all = intersection ∪ (target ∖ intersection) = target
|
Chris@0
|
18 * new = all ∖ source = {x: x ∈ target ∧ x ∉ source}
|
Chris@0
|
19 * obsolete = source ∖ all = source ∖ target = {x: x ∈ source ∧ x ∉ target}
|
Chris@0
|
20 * Basically, the result contains messages from the target catalogue.
|
Chris@0
|
21 *
|
Chris@0
|
22 * @author Michael Lee <michael.lee@zerustech.com>
|
Chris@0
|
23 */
|
Chris@0
|
24 class TargetOperation extends AbstractOperation
|
Chris@0
|
25 {
|
Chris@0
|
26 /**
|
Chris@0
|
27 * {@inheritdoc}
|
Chris@0
|
28 */
|
Chris@0
|
29 protected function processDomain($domain)
|
Chris@0
|
30 {
|
Chris@17
|
31 $this->messages[$domain] = [
|
Chris@17
|
32 'all' => [],
|
Chris@17
|
33 'new' => [],
|
Chris@17
|
34 'obsolete' => [],
|
Chris@17
|
35 ];
|
Chris@0
|
36
|
Chris@0
|
37 // For 'all' messages, the code can't be simplified as ``$this->messages[$domain]['all'] = $target->all($domain);``,
|
Chris@0
|
38 // because doing so will drop messages like {x: x ∈ source ∧ x ∉ target.all ∧ x ∈ target.fallback}
|
Chris@0
|
39 //
|
Chris@17
|
40 // For 'new' messages, the code can't be simplified as ``array_diff_assoc($this->target->all($domain), $this->source->all($domain));``
|
Chris@0
|
41 // because doing so will not exclude messages like {x: x ∈ target ∧ x ∉ source.all ∧ x ∈ source.fallback}
|
Chris@0
|
42 //
|
Chris@17
|
43 // For 'obsolete' messages, the code can't be simplified as ``array_diff_assoc($this->source->all($domain), $this->target->all($domain))``
|
Chris@0
|
44 // because doing so will not exclude messages like {x: x ∈ source ∧ x ∉ target.all ∧ x ∈ target.fallback}
|
Chris@0
|
45
|
Chris@0
|
46 foreach ($this->source->all($domain) as $id => $message) {
|
Chris@0
|
47 if ($this->target->has($id, $domain)) {
|
Chris@0
|
48 $this->messages[$domain]['all'][$id] = $message;
|
Chris@17
|
49 $this->result->add([$id => $message], $domain);
|
Chris@0
|
50 if (null !== $keyMetadata = $this->source->getMetadata($id, $domain)) {
|
Chris@0
|
51 $this->result->setMetadata($id, $keyMetadata, $domain);
|
Chris@0
|
52 }
|
Chris@0
|
53 } else {
|
Chris@0
|
54 $this->messages[$domain]['obsolete'][$id] = $message;
|
Chris@0
|
55 }
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 foreach ($this->target->all($domain) as $id => $message) {
|
Chris@0
|
59 if (!$this->source->has($id, $domain)) {
|
Chris@0
|
60 $this->messages[$domain]['all'][$id] = $message;
|
Chris@0
|
61 $this->messages[$domain]['new'][$id] = $message;
|
Chris@17
|
62 $this->result->add([$id => $message], $domain);
|
Chris@0
|
63 if (null !== $keyMetadata = $this->target->getMetadata($id, $domain)) {
|
Chris@0
|
64 $this->result->setMetadata($id, $keyMetadata, $domain);
|
Chris@0
|
65 }
|
Chris@0
|
66 }
|
Chris@0
|
67 }
|
Chris@0
|
68 }
|
Chris@0
|
69 }
|