Пример #1
0
 public function testTransChoiceFallbackIsLogged()
 {
     $logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $logger->expects($this->once())->method('debug')->with('Translation use fallback catalogue.');
     $translator = new Translator('ar');
     $translator->setFallbackLocales(array('en'));
     $translator->addLoader('array', new ArrayLoader());
     $translator->addResource('array', array('some_message2' => 'one thing|%count% things'), 'en');
     $loggableTranslator = new LoggingTranslator($translator, $logger);
     $loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
 }
Пример #2
0
 public function validate($value, Constraint $constraint)
 {
     /**
      * @var Query $constraint
      */
     if (strlen(trim($value)) === 0) {
         $this->context->addViolation($this->translator->trans($constraint->nonEmptyViolation, [], 'messages'));
     }
     $checklist = [['method' => 'deleteData'], ['method' => 'truncateTable'], ['method' => 'dropData'], ['method' => 'alterSchema'], ['method' => 'grantPrivilege']];
     if ($this->context->getGroup() === $constraint::GROUP_PUBLIC_QUERIES) {
         $checklist[] = ['method' => 'updateData'];
     }
     foreach ($checklist as $checkpoint) {
         $breakConstraint = $checkpoint['method'];
         if ($this->{$breakConstraint}($value)) {
             $translationKey = $constraint->{$breakConstraint . 'Violation'};
             $message = $this->translator->trans($translationKey, [], 'messages');
             $this->context->addViolation($message);
         }
     }
 }
 /**
  * @param $context
  * @param $entity
  * @return bool
  */
 public function sendToEmails($context, $entity)
 {
     if (!isset($this->contextsConfig[$context])) {
         throw new \RuntimeException(sprintf('Context "%s" not found', $context));
     }
     $contextConfig = $this->contextsConfig[$context];
     $body = $this->templating->render($contextConfig['templates']['email_event'], array('entity' => $entity));
     $toEmails = $this->getNotSentEmails($context, $entity);
     $success = (bool) count($toEmails);
     if ($success) {
         $from = $contextConfig['from_email'];
         if ($contextConfig['from_name']) {
             $from = array($from => $contextConfig['from_name']);
         }
         $message = \Swift_Message::newInstance()->setSubject($this->translator->trans($contextConfig['subject']))->setFrom($from)->setTo($toEmails)->setBody($body, 'text/html');
         $success = (bool) $this->mailer->send($message);
         if ($success) {
             $this->createSubscriptionHistory($context, $entity, $toEmails);
         }
     }
     return $success;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
 {
     $parentValue = parent::transChoice($id, $number, $parameters, $domain, $locale);
     return $parentValue;
 }