/**
  *
  * @param MessageCatalogueInterface $source        	
  * @param MessageCatalogueInterface $target        	
  *
  * @throws \LogicException
  */
 public function __construct(MessageCatalogueInterface $source, MessageCatalogueInterface $target)
 {
     if ($source->getLocale() !== $target->getLocale()) {
         throw new \LogicException('Operated catalogues must belong to the same locale.');
     }
     $this->source = $source;
     $this->target = $target;
     $this->result = new MessageCatalogue($source->getLocale());
     $this->domains = null;
     $this->messages = array();
 }
 /**
  * @param string                    $bundle
  * @param string                    $path
  * @param MessageCatalogueInterface $catalogue
  * @return $this
  */
 public function addCatalogue($bundle, $path, MessageCatalogueInterface $catalogue)
 {
     $locale = $catalogue->getLocale();
     $domains = $catalogue->getDomains();
     foreach ($domains as $domain) {
         $messages = $catalogue->all($domain);
         foreach ($messages as $key => $translation) {
             $this->addTranslation($bundle, $domain, $locale, $key, $translation);
         }
     }
     /** @var ResourceInterface $resource */
     foreach ($catalogue->getResources() as $resource) {
         $fileName = basename($resource->getResource());
         $this->addFile($bundle, $path, $fileName);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addCatalogue(MessageCatalogueInterface $catalogue)
 {
     if ($catalogue->getLocale() !== $this->locale) {
         throw new \LogicException(sprintf('Cannot add a catalogue for locale "%s" as the current locale for this catalogue is "%s"', $catalogue->getLocale(), $this->locale));
     }
     foreach ($catalogue->all() as $domain => $messages) {
         $this->add($messages, $domain);
     }
     foreach ($catalogue->getResources() as $resource) {
         $this->addResource($resource);
     }
 }
 /**
  *
  * {@inheritdoc} @api
  */
 public function addFallbackCatalogue(MessageCatalogueInterface $catalogue)
 {
     // detect circular references
     $c = $catalogue;
     while ($c = $c->getFallbackCatalogue()) {
         if ($c->getLocale() === $this->getLocale()) {
             throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
         }
     }
     $c = $this;
     do {
         if ($c->getLocale() === $catalogue->getLocale()) {
             throw new \LogicException(sprintf('Circular reference detected when adding a fallback catalogue for locale "%s".', $catalogue->getLocale()));
         }
     } while ($c = $c->parent);
     $catalogue->parent = $this;
     $this->fallbackCatalogue = $catalogue;
     foreach ($catalogue->getResources() as $resource) {
         $this->addResource($resource);
     }
 }