wppaste
WordPress

DSNConfigurator

Source
wp-includes/PHPMailer/DSNConfigurator.php:31
Configure PHPMailer with DSN string.

Compatibility

WordPress
core
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 3 of the 5 tracked releases.

Methods · 7

Source code

class DSNConfigurator{    /**     * Create new PHPMailer instance configured by DSN.     *     * @param string $dsn        DSN     * @param bool   $exceptions Should we throw external exceptions?     *     * @return PHPMailer     */    public static function mailer($dsn, $exceptions = null)    {        static $configurator = null;         if (null === $configurator) {            $configurator = new DSNConfigurator();        }         return $configurator->configure(new PHPMailer($exceptions), $dsn);    }     /**     * Configure PHPMailer instance with DSN string.     *     * @param PHPMailer $mailer PHPMailer instance     * @param string    $dsn    DSN     *     * @return PHPMailer     */    public function configure(PHPMailer $mailer, $dsn)    {        $config = $this->parseDSN($dsn);         $this->applyConfig($mailer, $config);         return $mailer;    }     /**     * Parse DSN string.     *     * @param string $dsn DSN     *     * @throws Exception If DSN is malformed     *     * @return array Configuration     */    private function parseDSN($dsn)    {        $config = $this->parseUrl($dsn);         if (false === $config || !isset($config['scheme']) || !isset($config['host'])) {            throw new Exception('Malformed DSN');        }         if (isset($config['query'])) {            parse_str($config['query'], $config['query']);        }         return $config;    }     /**     * Apply configuration to mailer.     *     * @param PHPMailer $mailer PHPMailer instance     * @param array     $config Configuration     *     * @throws Exception If scheme is invalid     */    private function applyConfig(PHPMailer $mailer, $config)    {        switch ($config['scheme']) {            case 'mail':                $mailer->isMail();                break;            case 'sendmail':                $mailer->isSendmail();                break;            case 'qmail':

Changelog

Unchanged from 6.9.7 through 7.1.0.

  1. 6.9.7
  2. 7.0.4
  3. 7.1.0

Signature, return type and hooks compared across 3 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/PHPMailer/DSNConfigurator.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.