<commit_before><?php

namespace App\Handler\Email;

use App\Command\Email\AbstractSendEmailCommand;
use App\Entity\ChangeEntry;
use App\Entity\NotificationOnlyChangeEntry;
use App\Event\CommandEvent;
use App\Event\NotificationEvent;
use App\Handler\BaseValidatedHandler;
use Qandidate\Toggle\ContextFactory;
use Qandidate\Toggle\ToggleManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;

abstract class AbstractEmailHandler extends BaseValidatedHandler implements EventSubscriberInterface
{
    /**
     * @var ToggleManager
     */
    private $manager;

    /**
     * @var ContextFactory
     */
    private $context;

    /**
     * @var \Swift_Mailer
     */
    private $mailer;

    /**
     * @var string
     */
    private $mailFromEmail;

    public function __construct(ValidatorInterface $validator, ToggleManager $manager, ContextFactory $contextFactory, \Swift_Mailer $mailer, string $mailFromEmail = null)
    {
        parent::__construct($validator);
        $this->manager = $manager;
        $this->context = $contextFactory->createContext();
        $this->mailer = $mailer;
        $this->mailFromEmail = $mailFromEmail;
    }

    public static function getSubscribedEvents()
    {
        $event = str_replace('Handler', 'Command', static::class);
        return [$event => 'handle'];
    }

    public function handle(CommandEvent $event, string $eventName, EventDispatcherInterface $dispatcher): void
    {
        /** @var AbstractSendEmailCommand $command */
        $command = $event->getCommand();

        // Only send emails if the feature is enabled
        if (!$this->manager->active('email_feature', $this->context)) {
            $this->setEmailNotSentNotification($command, 'disabled');
            return;
        }

        // Allow messages to have their own rules to keep an email from being sent<commit_msg>Add twig templating to base email handler.<commit_after><?php

namespace App\Handler\Email;

use App\Command\Email\AbstractSendEmailCommand;
use App\Entity\ChangeEntry;
use App\Entity\NotificationOnlyChangeEntry;
use App\Event\CommandEvent;
use App\Event\NotificationEvent;
use App\Handler\BaseValidatedHandler;
use Qandidate\Toggle\ContextFactory;
use Qandidate\Toggle\ToggleManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Bundle\TwigBundle\TwigEngine;

abstract class AbstractEmailHandler extends BaseValidatedHandler implements EventSubscriberInterface
{
    /**
     * @var TwigEngine
     */
    protected $templating;

    /**
     * @var ToggleManager
     */
    private $manager;

    /**
     * @var ContextFactory
     */
    private $context;

    /**
     * @var \Swift_Mailer
     */
    private $mailer;

    /**
     * @var string
     */
    private $mailFromEmail;

    public function __construct(ValidatorInterface $validator, ToggleManager $manager, ContextFactory $contextFactory, \Swift_Mailer $mailer, string $mailFromEmail = null, TwigEngine $templating)
    {
        parent::__construct($validator);
        $this->manager = $manager;
        $this->context = $contextFactory->createContext();
        $this->mailer = $mailer;
        $this->mailFromEmail = $mailFromEmail;
        $this->templating = $templating;
    }

    public static function getSubscribedEvents()
    {
        $event = str_replace('Handler', 'Command', static::class);
        return [$event => 'handle'];
    }

    public function handle(CommandEvent $event, string $eventName, EventDispatcherInterface $dispatcher): void
    {
        /** @var AbstractSendEmailCommand $command */
        $command = $event->getCommand();

        // Only send emails if the feature is enabled
        if (!$this->manager->active('email_feature', $this->context)) {
            $this->setEmailNotSentNotification($command, 'disabled');
            return;
        }

        // Allow messages to have their own rules to keep an email from being sent
{'fraction_non_alphanumeric': 0.1076959733142721, 'fraction_numerical': 0.0, 'mean_word_length': 3.37747653806048, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, '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': '2758770', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1106, 'n_words': 261}