<commit_before><?php
use Milkyway\SS\EventDispatcher;

/**
 * Milkyway Multimedia
 * SendThis.php
 *
 * This class throws exceptions, but can be set to not do so, in order to
 * work like the SS Mailer class which does not throw exceptions
 *
 * @package milkyway-multimedia/silverstripe-send-this
 * @author <NAME> <<EMAIL>>
 */

class SendThis extends Mailer {
    /** @var array A map for the transports you can use with SendThis */
    private static $transports = [
        'smtp' => '\Milkyway\SS\SendThis\Transports\SMTP',
        'ses' => '\Milkyway\SS\SendThis\Transports\AmazonSES',
        'mandrill' => '\Milkyway\SS\SendThis\Transports\Mandrill',
    ];

    /** @var bool Whether to enabled logging for this application */
    private static $logging = true;

    /** @var bool Whether to enable api tracking for this application */
    private static $api_tracking = true;

    /** @var bool|string Only allow emails from a certain domain
     * (you can also enter an email here to override the From Address) */
    private static $from_same_domain_only = true;

    /** @var int After how many soft bounces do we blacklist */
    private static $blacklist_after_bounced = 2;

    /** @var array These are the registered listeners for SendThis */
    protected static $listeners = [];

    /** @var array These are the registered listeners for SendThis that will be only called once and then removed (callbacks if you will) */
    protected static $callbacks = [];

    /** @var bool Whether or not to throw exceptions */
	protected static $throw_exceptions = true;

	public static function get_throw_exceptions() {
		return self::$throw_exceptions;
	}

	public static function throw_exceptions($flag = true) {
		self::$throw_exceptions = $flag;
	}

    /**
     * Send an email immediately, with ability to provide a callback and alternate transport
     *
     * @param Email|array      $email
     * @param Callable  $callback
     * @param array $transport
     */
    public static function now($email, $callback = null, $transport = []) {
        //@todo implement a quick send function
        if($callback)
            static::listen('sent', $callback, true);
    }

    /**
     * Push an email to a queue, with ability to provide a time, callback, alternate transport
     *
     * @param Email|array      $email
     * @param string $time
     * @param Callable  $callback
     * @param array $transport
     */
    public static function later($email, $time = '', $callback = null, $transport = []) {
        //@todo implement a quick queue function
        if($callback)
            static::listen(['sent'], $callback, true);
    }

    public static function listen($hooks, $callable, $once = false) {
        EventDispatcher::inst()->listen('SendThis', $hooks, $callable, $once);
    }

    public static function fire() {
        $args = func_get_args();
        array_unshift($args, 'SendThis');
        call_user_func_array([EventDispatcher::inst(), 'fire'], $args);
    }

    /** @var \Milkyway\SS\SendThis\Contracts\Transport The mail transport */
    protected $transport;

    /** @var PHPMailer  The PHP Mailer instance */
    protected $messenger;
<commit_msg>Changed events handler to use league/events<commit_after><?php

/**
 * Milkyway Multimedia
 * SendThis.php
 *
 * This class throws exceptions, but can be set to not do so, in order to
 * work like the SS Mailer class which does not throw exceptions
 *
 * @package milkyway-multimedia/silverstripe-send-this
 * @author <NAME> <<EMAIL>>
 */

class SendThis extends Mailer {
    /** @var array A map for the transports you can use with SendThis */
    private static $transports = [
        'smtp' => '\Milkyway\SS\SendThis\Transports\SMTP',
        'ses' => '\Milkyway\SS\SendThis\Transports\AmazonSES',
        'mandrill' => '\Milkyway\SS\SendThis\Transports\Mandrill',
    ];

    /** @var bool Whether to enabled logging for this application */
    private static $logging = true;

    /** @var bool Whether to enable api tracking for this application */
    private static $api_tracking = true;

    /** @var bool|string Only allow emails from a certain domain
     * (you can also enter an email here to override the From Address) */
    private static $from_same_domain_only = true;

    /** @var int After how many soft bounces do we blacklist */
    private static $blacklist_after_bounced = 2;

    /** @var array These are the registered listeners for SendThis */
    protected static $listeners = [];

    /** @var array These are the registered listeners for SendThis that will be only called once and then removed (callbacks if you will) */
    protected static $callbacks = [];

    /** @var bool Whether or not to throw exceptions */
	protected static $throw_exceptions = true;

	public static function get_throw_exceptions() {
		return self::$throw_exceptions;
	}

	public static function throw_exceptions($flag = true) {
		self::$throw_exceptions = $flag;
	}

    /**
     * Send an email immediately, with ability to provide a callback and alternate transport
     *
     * @param Email|array      $email
     * @param Callable  $callback
     * @param array $transport
     */
    public static function now($email, $callback = null, $transport = []) {
        //@todo implement a quick send function
        if($callback)
            static::listen('sent', $callback, true);
    }

    /**
     * Push an email to a queue, with ability to provide a time, callback, alternate transport
     *
     * @param Email|array      $email
     * @param string $time
     * @param Callable  $callback
     * @param array $transport
     */
    public static function later($email, $time = '', $callback = null, $transport = []) {
        //@todo implement a quick queue function
        if($callback)
            static::listen(['sent'], $callback, true);
    }

    public static function listen($hooks, $callable, $once = false) {
	    Injector::inst()->get('Milkyway\SS\Events\Dispatcher')->listen('SendThis', $hooks, $callable, $once);
    }

    public static function fire() {
        $args = func_get_args();
        array_unshift($args, 'SendThis');
        call_user_func_array([Injector::inst()->get('Milkyway\SS\Events\Dispatcher'), 'fire'], $args);
    }

    /** @var \Milkyway\SS\SendThis\Contracts\Transport The mail transport */
    protected $transport;

    /** @var PHPMailer  The PHP Mailer instance */
    protected $messenger;

{'fraction_non_alphanumeric': 0.11427686590275628, 'fraction_numerical': 0.0003096934035305048, 'mean_word_length': 2.991965389369592, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3694553', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1777, 'n_words': 625}