Exemple #1
0
 /**
  * Test template
  */
 public function testTemplate()
 {
     $this->assertEquals('foovaluebar', String::template('foo[VAR]bar', array('var' => 'value')));
     $this->assertEquals('foovaluebar', String::template('foo(VAR)bar', array('var' => 'value'), '(%s)'));
 }
Exemple #2
0
 /**
  * @param array|\Traversable $variables
  * @param array|\Traversable|string $to
  * @param null|array|\Traversable|string $cc
  * @param null|array|\Traversable|string $bcc
  * @throws Exception\InvalidArgumentException
  * @return void|mixed based on the transport's response
  */
 public function send($variables, $to, $cc = null, $bcc = null)
 {
     if ($variables instanceof Traversable) {
         $variables = ArrayUtils::iteratorToArray($variables);
     }
     if (!is_array($variables)) {
         throw new Exception\InvalidArgumentException('$variables need to be an array ' . '(or instance of \\Traversable) in ' . __METHOD__);
     }
     $html = $this->getTemplateHtml();
     $text = $this->getTemplateText();
     $options = $this->getOptions();
     $options = array_combine(array_keys($options), array_values($options));
     if (empty($variables['site_domain'])) {
         $variables['site_domain'] = $this->getSiteInfo()->getDomain();
     }
     if (empty($variables['site_url'])) {
         $variables['site_url'] = 'http://' . $variables['site_domain'];
     }
     foreach ($variables as $key => &$value) {
         $value = (string) $value;
         if (!empty($value) && $value[0] === '/' && strtolower(substr($key, -4)) === '_url') {
             $value = $variables['site_url'] . $value;
         }
     }
     $options['body'] = array('text/html' => String::template($html, $variables));
     if (!empty($text)) {
         $options['body']['text/plain'] = String::template($text, $variables);
     }
     $options['to'] = $to;
     if (null !== $cc) {
         $options['cc'] = $cc;
     }
     if (null !== $bcc) {
         $options['bcc'] = $bcc;
     }
     return $this->getService()->send($options);
 }