Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Translation\Catalogue; Chris@0: Chris@0: /** Chris@0: * Target operation between two catalogues: Chris@0: * intersection = source ∩ target = {x: x ∈ source ∧ x ∈ target} Chris@0: * all = intersection ∪ (target ∖ intersection) = target Chris@0: * new = all ∖ source = {x: x ∈ target ∧ x ∉ source} Chris@0: * obsolete = source ∖ all = source ∖ target = {x: x ∈ source ∧ x ∉ target} Chris@0: * Basically, the result contains messages from the target catalogue. Chris@0: * Chris@0: * @author Michael Lee Chris@0: */ Chris@0: class TargetOperation extends AbstractOperation Chris@0: { Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function processDomain($domain) Chris@0: { Chris@17: $this->messages[$domain] = [ Chris@17: 'all' => [], Chris@17: 'new' => [], Chris@17: 'obsolete' => [], Chris@17: ]; Chris@0: Chris@0: // For 'all' messages, the code can't be simplified as ``$this->messages[$domain]['all'] = $target->all($domain);``, Chris@0: // because doing so will drop messages like {x: x ∈ source ∧ x ∉ target.all ∧ x ∈ target.fallback} Chris@0: // Chris@17: // For 'new' messages, the code can't be simplified as ``array_diff_assoc($this->target->all($domain), $this->source->all($domain));`` Chris@0: // because doing so will not exclude messages like {x: x ∈ target ∧ x ∉ source.all ∧ x ∈ source.fallback} Chris@0: // Chris@17: // For 'obsolete' messages, the code can't be simplified as ``array_diff_assoc($this->source->all($domain), $this->target->all($domain))`` Chris@0: // because doing so will not exclude messages like {x: x ∈ source ∧ x ∉ target.all ∧ x ∈ target.fallback} Chris@0: Chris@0: foreach ($this->source->all($domain) as $id => $message) { Chris@0: if ($this->target->has($id, $domain)) { Chris@0: $this->messages[$domain]['all'][$id] = $message; Chris@17: $this->result->add([$id => $message], $domain); Chris@0: if (null !== $keyMetadata = $this->source->getMetadata($id, $domain)) { Chris@0: $this->result->setMetadata($id, $keyMetadata, $domain); Chris@0: } Chris@0: } else { Chris@0: $this->messages[$domain]['obsolete'][$id] = $message; Chris@0: } Chris@0: } Chris@0: Chris@0: foreach ($this->target->all($domain) as $id => $message) { Chris@0: if (!$this->source->has($id, $domain)) { Chris@0: $this->messages[$domain]['all'][$id] = $message; Chris@0: $this->messages[$domain]['new'][$id] = $message; Chris@17: $this->result->add([$id => $message], $domain); Chris@0: if (null !== $keyMetadata = $this->target->getMetadata($id, $domain)) { Chris@0: $this->result->setMetadata($id, $keyMetadata, $domain); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: }