No Description

MergeOperation.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\Catalogue;
  11. /**
  12. * Merge operation between two catalogues as follows:
  13. * all = source ∪ target = {x: x ∈ source ∨ x ∈ target}
  14. * new = all ∖ source = {x: x ∈ target ∧ x ∉ source}
  15. * obsolete = source ∖ all = {x: x ∈ source ∧ x ∉ source ∧ x ∉ target} = ∅
  16. * Basically, the result contains messages from both catalogues.
  17. *
  18. * @author Jean-François Simon <contact@jfsimon.fr>
  19. */
  20. class MergeOperation extends AbstractOperation
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. protected function processDomain($domain)
  26. {
  27. $this->messages[$domain] = array(
  28. 'all' => array(),
  29. 'new' => array(),
  30. 'obsolete' => array(),
  31. );
  32. foreach ($this->source->all($domain) as $id => $message) {
  33. $this->messages[$domain]['all'][$id] = $message;
  34. $this->result->add(array($id => $message), $domain);
  35. if (null !== $keyMetadata = $this->source->getMetadata($id, $domain)) {
  36. $this->result->setMetadata($id, $keyMetadata, $domain);
  37. }
  38. }
  39. foreach ($this->target->all($domain) as $id => $message) {
  40. if (!$this->source->has($id, $domain)) {
  41. $this->messages[$domain]['all'][$id] = $message;
  42. $this->messages[$domain]['new'][$id] = $message;
  43. $this->result->add(array($id => $message), $domain);
  44. if (null !== $keyMetadata = $this->target->getMetadata($id, $domain)) {
  45. $this->result->setMetadata($id, $keyMetadata, $domain);
  46. }
  47. }
  48. }
  49. }
  50. }