Пример #1
0
 /**
  * Send an email with a static (supplied) subject and message body.
  *
  * @param string $subject Subject line for the message.
  * @param array[] $addresses Map of recipients, with type keys (like "from", "to", "bcc", etc) mapped to email
  *   address values.  Each address may be either a string or an array mapping email addresses to display names
  *   and/or strings which are email addresses.
  * @param string $body Body of the message.
  * @param string|null $contentType
  * @param string|null $charset
  *
  * @return boolean
  *
  * @throws \DomainException
  * @throws \InvalidArgumentException
  */
 public function send($subject, $addresses, $body, $contentType = null, $charset = null)
 {
     LoggerRegistry::debug('SwiftMailerModule::send({subject}, {addresses}, body[{bodyCount} characters], {contentType}, {charset}', array('subject' => TypeUtilities::describe($subject), 'addresses' => TypeUtilities::describe($addresses), 'bodyCount' => strlen($body), 'contentType' => TypeUtilities::describe($contentType), 'charset' => TypeUtilities::describe($charset)));
     $message = \Swift_Message::newInstance($subject);
     if (!isset($addresses['sender']) && !isset($addresses['from'])) {
         throw new \DomainException('SwiftMailer module cannot send without specifying a sender or from address.');
     }
     if (!isset($addresses['sender'])) {
         $addresses['sender'] = $addresses['from'];
     }
     foreach ($addresses as $type => $typeAddresses) {
         if (!is_array($typeAddresses)) {
             $typeAddresses = array($typeAddresses);
         }
         // Get the setter method, do it now so we don't determine arguments when the method doesn't even exist.
         $setter = new \ReflectionMethod($message, sprintf('set%s', NameUtilities::convertToStudlyCaps($type)));
         // Determine the arguments to the setter.  This converts an array of strings or maps, where each map has
         // "name" and "address" keys (name is optional), to a single array as accepted by the `setXxx()` methods.
         $setterAddressesArg = array();
         foreach ($typeAddresses as $typeAddress) {
             if (is_string($typeAddress)) {
                 $setterAddressesArg[] = $typeAddress;
             } elseif (is_array($typeAddress) && isset($typeAddress['address'])) {
                 if (isset($typeAddress['name'])) {
                     $setterAddressesArg[$typeAddress['address']] = $typeAddress['name'];
                 } else {
                     $setterAddressesArg[] = $typeAddress['address'];
                 }
             } else {
                 throw new \InvalidArgumentException(sprintf('SwiftMailer module received invalid %s address specification: [%s]', $type, TypeUtilities::describe($typeAddress)));
             }
         }
         // Call the setter method.
         $setter->invoke($message, $setterAddressesArg);
     }
     $message->setBody($body, $contentType, $charset);
     return $this->mailer->send($message) > 0;
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function getModule($name)
 {
     $name = NameUtilities::convertToStudlyCaps($name);
     if (!isset($this->modules[$name])) {
         $module = $this->createModule($name);
         $module->start();
         $this->getViewFactory()->getResourcesManager()->registerMap($this->normaliseResourceMap($module->getResourceMap()));
         $this->modules[$name] = $module;
     }
     return $this->modules[$name];
 }
Пример #3
0
 public function testConvertToStudlyCaps()
 {
     $this->assertEquals('FromCamelCase', NameUtilities::convertToStudlyCaps('fromCamelCase'));
     $this->assertEquals('FromStudlyCaps', NameUtilities::convertToStudlyCaps('FromStudlyCaps'));
     $this->assertEquals('FromDashedLower', NameUtilities::convertToStudlyCaps('from-dashed-lower'));
     $this->assertEquals('FromUnderscoreLower', NameUtilities::convertToStudlyCaps('from-underscore-lower'));
     $this->assertEquals('FromUnderscoreCaps', NameUtilities::convertToStudlyCaps('From_Underscore_Caps'));
     $this->assertEquals('FromLowerCase', NameUtilities::convertToStudlyCaps('from lower case'));
     $this->assertEquals('FromTitleCase', NameUtilities::convertToStudlyCaps('From Title Case'));
     $this->assertEquals('ThisOneIsntEasyATestCaseSitegearOrg', NameUtilities::convertToStudlyCaps('This One Isn\'t Easy - A Test Case @ sitegear.org'));
 }
Пример #4
0
 /**
  * Convert the given input (string) selector into an associative array with the relevant keys for internal use.
  *
  * @param string $selector Selector as passed to a DiscreteDataModuleInterface method.
  *
  * @return array Array containing 'entity-alias', 'entity-name', 'match-field-name', 'match-field-value' and
  *   'value-field-name'.
  *
  * @throws \InvalidArgumentException If the selector has invalid syntax.
  */
 protected function parseSelector($selector)
 {
     $result = null;
     $matches = array();
     if (preg_match(self::REGEX_PARSE_SELECTOR, $selector, $matches) && sizeof($matches) > 3) {
         $entityMatches = array();
         if (preg_match(self::REGEX_PARSE_ENTITY_NAME, $matches[1], $entityMatches) && sizeof($entityMatches) > 1) {
             $result = array('entity-alias' => sizeof($entityMatches) > 2 ? sprintf('%s:', NameUtilities::convertToStudlyCaps($entityMatches[1])) : '', 'entity-name' => NameUtilities::convertToStudlyCaps(sizeof($entityMatches) > 2 ? $entityMatches[2] : $entityMatches[1]), 'match-field-name' => is_numeric($matches[2]) ? 'id' : 'urlPath', 'match-field-value' => $matches[2], 'value-field-name' => $matches[3]);
         } else {
             throw new \InvalidArgumentException(sprintf('DoctrineModule got invalid entity name format; required format is "entity" or "alias:entity", got "%s"', $matches[1]));
         }
     } else {
         throw new \InvalidArgumentException(sprintf('DoctrineModule got invalid selector format; required format is "entity/identifier/field", got "%s"', $selector));
     }
     return $result;
 }
Пример #5
0
 /**
  * Create a single condition for a single processor.
  *
  * @param array $conditionDefinition
  *
  * @return ConditionInterface
  *
  * @throws \InvalidArgumentException
  */
 public function buildCondition(array $conditionDefinition)
 {
     $conditionClass = TypeUtilities::firstExistingClass($this->getFormsModule()->registry()->getConditionNamespaces(), NameUtilities::convertToStudlyCaps($conditionDefinition['condition']) . 'Condition');
     if (is_null($conditionClass)) {
         throw new \InvalidArgumentException(sprintf('FormBuilder could not find a condition class for the name "%s"', $conditionDefinition['condition']));
     }
     return $conditionClass->newInstance($conditionDefinition['options']);
 }
Пример #6
0
 /**
  * @inheritdoc
  */
 public function getModuleClassName($name)
 {
     $name = NameUtilities::convertToStudlyCaps($name);
     $classMap = $this->config('engine.modules.class-map', array());
     if (isset($classMap[$name])) {
         return $classMap[$name];
     } else {
         foreach ($this->config('engine.modules.namespaces', array()) as $namespace) {
             $prefix = $this->config('engine.modules.class-name-prefix');
             $suffix = $this->config('engine.modules.class-name-suffix');
             $className = sprintf('%s\\%s\\%s%s%s', $namespace, $name, $prefix, $name, $suffix);
             if (class_exists($className)) {
                 return $className;
             }
         }
     }
     return null;
 }