Bez popisu

MergeOperation.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. use Symfony\Component\Translation\MessageCatalogueInterface;
  12. /**
  13. * Merge operation between two catalogues as follows:
  14. * all = source ∪ target = {x: x ∈ source ∨ x ∈ target}
  15. * new = all ∖ source = {x: x ∈ target ∧ x ∉ source}
  16. * obsolete = source ∖ all = {x: x ∈ source ∧ x ∉ source ∧ x ∉ target} = ∅
  17. * Basically, the result contains messages from both catalogues.
  18. *
  19. * @author Jean-François Simon <contact@jfsimon.fr>
  20. */
  21. class MergeOperation extends AbstractOperation
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. protected function processDomain($domain)
  27. {
  28. $this->messages[$domain] = [
  29. 'all' => [],
  30. 'new' => [],
  31. 'obsolete' => [],
  32. ];
  33. $intlDomain = $domain.MessageCatalogueInterface::INTL_DOMAIN_SUFFIX;
  34. foreach ($this->source->all($domain) as $id => $message) {
  35. $this->messages[$domain]['all'][$id] = $message;
  36. $d = $this->source->defines($id, $intlDomain) ? $intlDomain : $domain;
  37. $this->result->add([$id => $message], $d);
  38. if (null !== $keyMetadata = $this->source->getMetadata($id, $d)) {
  39. $this->result->setMetadata($id, $keyMetadata, $d);
  40. }
  41. }
  42. foreach ($this->target->all($domain) as $id => $message) {
  43. if (!$this->source->has($id, $domain)) {
  44. $this->messages[$domain]['all'][$id] = $message;
  45. $this->messages[$domain]['new'][$id] = $message;
  46. $d = $this->target->defines($id, $intlDomain) ? $intlDomain : $domain;
  47. $this->result->add([$id => $message], $d);
  48. if (null !== $keyMetadata = $this->target->getMetadata($id, $d)) {
  49. $this->result->setMetadata($id, $keyMetadata, $d);
  50. }
  51. }
  52. }
  53. }
  54. }