Example #1
0
 protected function setUp($payload, $settings)
 {
     if (null === $payload) {
         $payload = new Settings();
     } elseif (is_array($payload)) {
         $payload = new Settings($payload);
     } elseif ($payload instanceof SettingsInterface) {
         $payload = new Settings($payload->toArray());
     }
     $this->payload = $payload;
     if (null === $settings) {
         $settings = new Settings();
     } elseif (is_array($settings)) {
         $settings = new Settings($settings);
     } elseif (!$settings instanceof SettingsInterface) {
         throw new RuntimeError('Settings must be an array or SettingsInterface implementing instance.');
     }
     $this->settings = $settings;
 }
 protected function renderEmbeddedEntity(EntityInterface $embedded_entity, $position, $is_embed_template = false)
 {
     $view_scope = $this->getOption('view_scope');
     $group_parts = array_merge((array) $this->getOption('group_parts', []), [$this->attribute->getName(), $position]);
     $default_settings = ['view_scope' => $view_scope, 'group_parts' => $group_parts, 'is_embed_template' => $is_embed_template];
     if ($this->hasOption('entity_template')) {
         $default_settings['template'] = $this->getOption('entity_template');
     }
     $renderer_config = $this->view_config_service->getRendererConfig($view_scope, $this->output_format, $embedded_entity, $default_settings);
     $renderer_settings = ['add_item_to_parent_list_allowed' => $this->isAddItemAllowed(), 'readonly' => $this->isReadonly()];
     if (static::RENDER_GLANCE) {
         $additional_config = [];
         if ($is_embed_template) {
             $additional_config['expand_by_default'] = true;
         }
         $glance_config = $this->getGlanceRenderConfig($embedded_entity, $additional_config);
         $renderer_settings['glance_config'] = $glance_config;
     }
     return $this->renderer_service->renderSubject($embedded_entity, $this->output_format, $renderer_config, [], Settings::createFromArray($renderer_settings));
 }
Example #3
0
 protected static function createTwigLoader(Settings $settings)
 {
     if (!$settings->has('template_paths')) {
         throw new RuntimeError('Missing "template_paths" settings with template lookup locations.');
     }
     $template_paths = (array) $settings->get('template_paths', []);
     $loader = new FilesystemLoader($template_paths);
     if ($settings->has('allowed_template_extensions')) {
         $loader->setAllowedExtensions((array) $settings->get('allowed_template_extensions'));
     }
     if (!$settings->has('cache_scope')) {
         $loader->setScope(spl_object_hash($loader));
         // unique scope for each new loader instance
     } else {
         $loader->setScope($settings->get('cache_scope', FilesystemLoader::SCOPE_DEFAULT));
     }
     return $loader;
 }
Example #4
0
 /**
  * Returns a string representation of the guard.
  *
  * @return string
  */
 public function __toString()
 {
     return ' if ' . $this->options->get('expression');
 }
Example #5
0
 /**
  * Returns the settings as an associative array.
  *
  * @return array with all settings
  */
 public function toArray()
 {
     return $this->settings->toArray();
 }
Example #6
0
 /**
  * Create Swift_Message instance from the given MailInterface instance.
  *
  * @param MailInterface $message instance to create Swift_Message from
  * @param string $mailer_config_name name of the mailer config to get settings from
  *
  * @return Swift_Message instance
  *
  * @throws MessageConfigurationException in case of misconfigured message
  * @throws InvalidArgumentException in case of unknown mailer name from config
  */
 public function createSwiftMessage(MailInterface $message, $mailer_config_name = null)
 {
     $settings = $this->getMailerSettings($mailer_config_name);
     $message_defaults = new Settings((array) $settings->get('address_defaults', []));
     $message_overrides = new Settings((array) $settings->get('address_overrides', []));
     Swift_Preferences::getInstance()->setCharset($settings->get('charset', 'utf-8'));
     $mail = Swift_Message::newInstance();
     $mail->setSubject($message->getSubject($settings->get('default_subject')));
     $from = $message_overrides->get('from', $message->getFrom($message_defaults->get('from')));
     if (!empty($from)) {
         $mail->setFrom($from);
     }
     $sender = $message_overrides->get('sender', $message->getSender($message_defaults->get('sender')));
     if (!empty($sender)) {
         $mail->setSender($sender);
     }
     // sender is mandatory if multiple from addresses are set
     if (is_array($from) && count($from) > 1 && empty($sender)) {
         throw new MessageConfigurationException('A single "sender" email address must be specified when multiple "from" email addresses are set.');
     }
     // we need at least a sender or a from to be honest citizens
     if (empty($from) && empty($sender)) {
         throw new MessageConfigurationException('Either "from" or "sender" must be set with a valid email address on a message.' . 'Usually "from" is considered to be mandatory with the "sender" being optional ' . 'to distinguish between writers of an email and its actual sender.');
     }
     $reply_to = $message_overrides->get('reply_to', $message->getReplyTo($message_defaults->get('reply_to')));
     if (!empty($reply_to)) {
         $mail->setReplyTo($reply_to);
     }
     $return_path = $message_overrides->get('return_path', $message->getReturnPath($message_defaults->get('return_path')));
     if (!empty($return_path)) {
         // Swift only wants a string as email on the return path (despite the behaviour on other address fields)
         if (is_array($return_path)) {
             $return_path = array_keys($return_path);
             $return_path = array_shift($return_path);
         }
         $mail->setReturnPath($return_path);
     }
     $date = $message->getDate($message_defaults->get('date'));
     if ($settings->has('default_date')) {
         $date = strtotime($settings->get('default_date'));
     }
     if (!empty($date) && is_int($date)) {
         $mail->setDate($date);
     }
     $to = $message_overrides->get('to', $message->getTo($message_defaults->get('to')));
     if (!empty($to)) {
         $mail->setTo($to);
     }
     $cc = $message_overrides->get('cc', $message->getCc($message_defaults->get('cc')));
     if (!empty($cc)) {
         $mail->setCc($cc);
     }
     $bcc = $message_overrides->get('bcc', $message->getBcc($message_defaults->get('bcc')));
     if (!empty($bcc)) {
         $mail->setBcc($bcc);
     }
     $body_html = $message->getBodyHtml($message_defaults->get('default_body_html'));
     if (!empty($body_html)) {
         $mail->addPart($body_html, "text/html");
     }
     $body_text = $message->getBodyText($message_defaults->get('default_body_text'));
     if (!empty($body_text)) {
         $mail->addPart($body_text, "text/plain");
     }
     $attachments = $message->getAttachments();
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             if (!is_array($attachment)) {
                 continue;
             }
             $mail->attach($this->createSwiftAttachment($attachment));
         }
     }
     // if to, cc or bcc are set we have to override them if a setting is set
     $override_all_recipients = $settings->get('override_all_recipients', false);
     if (false !== $override_all_recipients && !empty($override_all_recipients)) {
         if (!empty($to)) {
             $to = $override_all_recipients;
             // for later validation
             $mail->setTo($to);
         }
         if (!empty($cc)) {
             $cc = $override_all_recipients;
             // for later validation
             $mail->setCc($cc);
         }
         if (!empty($bcc)) {
             $bcc = $override_all_recipients;
             // for later validation
             $mail->setBcc($bcc);
         }
     }
     // we won't send mails without recipients
     if (empty($to) && empty($cc) && empty($bcc)) {
         throw new MessageConfigurationException('No recipients are set for this email. Set "to", "cc" and/or "bcc" email addresses on the message.');
     }
     // do not allow too long text lines
     if ($settings->has('max_line_length')) {
         $mail->setMaxLineLength((int) $settings->get('max_line_length', 78));
     }
     // add X-Priority header
     if ($settings->has('priority')) {
         $mail->setPriority((int) $settings->get('priority', 3));
     }
     // request read receipts if necessary
     if ($settings->has('read_receipt_to')) {
         $mail->setReadReceiptTo($settings->get('read_receipt_to'));
     }
     return $mail;
 }