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: * Merge operation between two catalogues as follows: Chris@0: * all = source ∪ target = {x: x ∈ source ∨ x ∈ target} Chris@0: * new = all ∖ source = {x: x ∈ target ∧ x ∉ source} Chris@0: * obsolete = source ∖ all = {x: x ∈ source ∧ x ∉ source ∧ x ∉ target} = ∅ Chris@0: * Basically, the result contains messages from both catalogues. Chris@0: * Chris@0: * @author Jean-François Simon Chris@0: */ Chris@0: class MergeOperation 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: foreach ($this->source->all($domain) as $id => $message) { 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: } 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: }