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