_driver = $driver; $this->_params = $params; $this->_delegate = $mailer; } public function __destruct() { try { unset($this->_delegate); } catch (Exception $e) { Civi::log()->error($e->getMessage()); } } public function send($recipients, $headers, $body) { $filterArgs = [$this, &$recipients, &$headers, &$body]; foreach ($this->_filters as $filter) { $result = call_user_func_array($filter, $filterArgs); if ($result !== NULL) { return $result; } } return $this->_delegate->send($recipients, $headers, $body); } /** * @param string $id * Unique ID for this filter. Filters are sorted by ID. * Suggestion: '{nnnn}_{name}', where '{nnnn}' is a number. * Filters are sorted and executed in order. * @param callable $func * function(FilteredPearMailer $mailer, mixed $recipients, array $headers, string $body). * The return value should generally be null/void. However, if you wish to * short-circuit execution of the filters, then return a concrete value. * @return static */ public function addFilter($id, $func) { $this->_filters[$id] = $func; ksort($this->_filters); return $this; } /** * @return string * Ex: 'smtp', 'sendmail', 'mail'. */ public function getDriver() { return $this->_driver; } public function &__get($name) { return $this->_delegate->{$name}; } public function __set($name, $value) { return $this->_delegate->{$name} = $value; } public function __isset($name) { return isset($this->_delegate->{$name}); } public function __unset($name) { unset($this->_delegate->{$name}); } public function disconnect() { if (is_callable([$this->_delegate, 'disconnect'])) { return $this->_delegate->disconnect(); } return TRUE; } }