AbstractOperation.php
1 month ago
MergeOperation.php
2 years ago
OperationInterface.php
1 month ago
TargetOperation.php
2 years ago
MergeOperation.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace IAWPSCOPED\Symfony\Component\Translation\Catalogue; |
| 12 | |
| 13 | use IAWPSCOPED\Symfony\Component\Translation\MessageCatalogueInterface; |
| 14 | /** |
| 15 | * Merge operation between two catalogues as follows: |
| 16 | * all = source ∪ target = {x: x ∈ source ∨ x ∈ target} |
| 17 | * new = all ∖ source = {x: x ∈ target ∧ x ∉ source} |
| 18 | * obsolete = source ∖ all = {x: x ∈ source ∧ x ∉ source ∧ x ∉ target} = � |
| 19 | |
| 20 | * Basically, the result contains messages from both catalogues. |
| 21 | * |
| 22 | * @author Jean-François Simon <contact@jfsimon.fr> |
| 23 | * @internal |
| 24 | */ |
| 25 | class MergeOperation extends AbstractOperation |
| 26 | { |
| 27 | /** |
| 28 | * {@inheritdoc} |
| 29 | */ |
| 30 | protected function processDomain(string $domain) |
| 31 | { |
| 32 | $this->messages[$domain] = ['all' => [], 'new' => [], 'obsolete' => []]; |
| 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 | } |
| 55 |