You are here

function mailsystem_get_classes in Mail System 7.3

Same name and namespace in other branches
  1. 8 mailsystem.admin.inc \mailsystem_get_classes()
  2. 8.2 mailsystem.module \mailsystem_get_classes()
  3. 6.2 mailsystem.module \mailsystem_get_classes()
  4. 6 mailsystem.admin.inc \mailsystem_get_classes()
  5. 7 mailsystem.admin.inc \mailsystem_get_classes()
  6. 7.2 mailsystem.module \mailsystem_get_classes()

Returns a list of classes which implement MailSystemInterface.

This method assumes that all classes which implement MailSystemInterface have filenames containing '.mail.' or class names containing 'MailSystem'.

If necessary you may override the default discovery whitelist by setting the mailsystem_get_classes_whitelist and mailsystem_get_classes_blacklist variables. The default value is as follows:

variable_set('mailsystem_get_classes_whitelist', array(
  array(
    'field' => 'name',
    'value' => '%MailSystem',
    'operator' => 'LIKE',
  ),
  array(
    'field' => 'filename',
    'value' => '%.mail.%',
    'operator' => 'LIKE',
  ),
));
variable_set('mailsystem_get_classes_blacklist', array(
  array(
    'field' => 'filename',
    'value' => '%.test',
    'operator' => 'NOT LIKE',
  ),
));

The 'field' value specifies in which database-field of the registry table the lookup for 'value' should take place. Typical values for 'field' are either 'name' for the classname or 'filename' for the name of the file the class is contained in.

For example, if your own mail system implementation called 'MyMailer' should be available in the mailsystem module you may add the following record to the whitelist:

array(
  'field' => 'name',
  'value' => 'MyMailer',
);

Note that if you set the blacklist, you need to negate the operator. Use 'NOT Like' or the not-equal operator '<>'.

2 calls to mailsystem_get_classes()
mailsystem_admin_get_delivery_classes in ./mailsystem.admin.inc
Returns a list of classes suitable for sending mail.
mailsystem_requirements in ./mailsystem.install
Implements hook_requirements().

File

./mailsystem.module, line 293
Provide UI for controlling the mail_system variable.

Code

function mailsystem_get_classes() {
  $mailsystem_classes =& drupal_static(__FUNCTION__);
  if (!isset($mailsystem_classes)) {
    $query = db_select('registry', 'registry')
      ->fields('registry', array(
      'name',
      'filename',
    ))
      ->condition('type', 'class');
    if ($whitelist = _mailsystem_get_registry_whitelist_condition()) {
      $query
        ->condition($whitelist);
    }
    if ($blacklist = _mailsystem_get_registry_blacklist_condition()) {
      $query
        ->condition($blacklist);
    }
    $mail_classes = $query
      ->execute()
      ->fetchAllKeyed();
    $mailsystem_classes = array();
    foreach ($mail_classes as $classname => $classfile) {
      if (file_exists($classfile)) {
        $interfaces = class_implements($classname);
        if (isset($interfaces['MailSystemInterface'])) {
          $mailsystem_classes[$classname] = $classname;
        }
      }
    }
    ksort($mailsystem_classes);
  }
  return $mailsystem_classes;
}