/** * Load message for specified domain & id. * @param string $id * @param string $domain * @param string $locale * @return \AO\TranslationBundle\Translation\Message */ public function loadMessage($id, $domain, $locale) { $qb = $this->em->createQueryBuilder(); $qb->select('m, t')->from('\\AO\\TranslationBundle\\Entity\\Message', 'm')->join('m.domain', 'd')->leftJoin('m.translations', 't', 'WITH', 't.locale = :locale')->where('m.identification = :id AND d.name=:domain')->setParameters(array('id' => $id, 'domain' => $domain, 'locale' => $locale)); $m = $qb->getQuery()->getOneOrNullResult(); $message = new Message($id, null, $domain); if ($m) { $message->setParameters($m->getParameters()); $message->setStatus('not_cached'); $message->setEntity($m); if ($translation = $m->getLocaleTranslation($locale)) { $message->setContent($translation->getContent()); } } return $message; }
public function testMessage() { $message = new Message('foo', 'bar', 'baz'); $message->setParameters(array('foo' => 'bar')); $message->setCache('foo', 'bar', 'baz'); $this->assertTrue($message->isNew()); $this->assertFalse($message->isCached()); $this->assertEquals('foo:bar:baz', $message->getCacheKey()); $this->assertFalse($message->getUpdateParameters()); $message->updateParameters(array('foo' => 'bar')); $this->assertFalse($message->getUpdateParameters()); $message->updateParameters(array('bar' => 'baz')); $this->assertTrue($message->getUpdateParameters()); }
/** * Add message object to catalogue. * @param Message $message */ public function addMessage(Message $message) { $this->msg_objs[$message->getDomain()][$message->getIdentification()] = $message; return $this->set($message->getIdentification(), (string) $message->getContent(), $message->getDomain()); }