4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Catalogue;
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.
22 * @author Michael Lee <michael.lee@zerustech.com>
24 class TargetOperation extends AbstractOperation
29 protected function processDomain($domain)
31 $this->messages[$domain] = array(
34 'obsolete' => array(),
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}
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}
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}
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);
54 $this->messages[$domain]['obsolete'][$id] = $message;
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);