<commit_before><?php
/*
 * Lightdatasys web site source code
 *
 * Copyright <NAME> <<EMAIL>>
 *
 * For copyright and licensing information, please view the LICENSE
 * that is distributed with this source code.
 */

namespace Lidsys\Application\Service;

use Mailgun\Mailgun;
use Silex\Application;

class MailerService
{
    private $key;
    private $domain;
    private $api_endpoint;
    private $api_ssl;

    private $substitutions;
    private $defaults;

    private $mailgun;

    public function __construct($key, $domain, array $options = [])
    {
        $substitutions = $defaults = $overrides = [];
        $api_endpoint = 'bourne.r34d.me';
        $api_ssl = false;
        extract($options, EXTR_IF_EXISTS);

        $this->key           = $key;
        $this->domain        = $domain;
        $this->api_endpoint  = $api_endpoint;
        $this->api_ssl       = $api_ssl;

        $this->substitutions = $substitutions;
        $this->defaults      = $defaults;
        $this->overrides     = $overrides;
    }

    private function getMailgun()
    {
        if ($this->mailgun) {
            return $this->mailgun;
        }

        $this->mailgun = new Mailgun(
            $this->key,
            $this->api_endpoint,
            'v2',
            $this->api_ssl
        );

        return $this->mailgun;
    }

    public function sendMessage(array $data, array $local_subs = [])
    {
        $data = array_replace_recursive(
            $this->defaults,
            $data,
            $this->overrides
        );

        $substitutions = array_replace_recursive(
            $this->substitutions,
            $local_subs
        );

        $this->substituteString($data, 'text', $substitutions);
        $this->substituteString($data, 'html', $substitutions);

        return $this->getMailgun()->sendMessage($this->domain, $data);
    }

    private function substituteString(array & $data, $field, $substitutions)
    {
        if (!empty($data[$field])) {
            $data[$field] = str_replace(
                array_keys($substitutions),
                array_values($substitutions),
                $data[$field]
            );
        }
    }
}
<commit_msg>Change default mailgun API endpoint/SSL settings<commit_after><?php
/*
 * Lightdatasys web site source code
 *
 * Copyright <NAME> <<EMAIL>>
 *
 * For copyright and licensing information, please view the LICENSE
 * that is distributed with this source code.
 */

namespace Lidsys\Application\Service;

use Mailgun\Mailgun;
use Silex\Application;

class MailerService
{
    private $key;
    private $domain;
    private $api_endpoint;
    private $api_ssl;

    private $substitutions;
    private $defaults;

    private $mailgun;

    public function __construct($key, $domain, array $options = [])
    {
        $substitutions = $defaults = $overrides = [];
        $api_endpoint = 'api.mailgun.net';
        $api_ssl = true;
        extract($options, EXTR_IF_EXISTS);

        $this->key           = $key;
        $this->domain        = $domain;
        $this->api_endpoint  = $api_endpoint;
        $this->api_ssl       = $api_ssl;

        $this->substitutions = $substitutions;
        $this->defaults      = $defaults;
        $this->overrides     = $overrides;
    }

    private function getMailgun()
    {
        if ($this->mailgun) {
            return $this->mailgun;
        }

        $this->mailgun = new Mailgun(
            $this->key,
            $this->api_endpoint,
            'v2',
            $this->api_ssl
        );

        return $this->mailgun;
    }

    public function sendMessage(array $data, array $local_subs = [])
    {
        $data = array_replace_recursive(
            $this->defaults,
            $data,
            $this->overrides
        );

        $substitutions = array_replace_recursive(
            $this->substitutions,
            $local_subs
        );

        $this->substituteString($data, 'text', $substitutions);
        $this->substituteString($data, 'html', $substitutions);

        return $this->getMailgun()->sendMessage($this->domain, $data);
    }

    private function substituteString(array & $data, $field, $substitutions)
    {
        if (!empty($data[$field])) {
            $data[$field] = str_replace(
                array_keys($substitutions),
                array_values($substitutions),
                $data[$field]
            );
        }
    }
}

{'fraction_non_alphanumeric': 0.12593262491521592, 'fraction_numerical': 0.0009043635541487678, 'mean_word_length': 2.007477906186268, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 53, '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': '3624622', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1291, 'n_words': 263}