<commit_before><?php

/*
 * This file is part of the BrotherGuestbookBundle package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Brother\GuestbookBundle\Mailer;

use Brother\GuestbookBundle\Model\EntryInterface;
use Brother\GuestbookBundle\Event\Events;
use Brother\GuestbookBundle\Event\MailEvent;

use Symfony\Component\Form\FormInterface;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * Base class for the Mailer.
 */
abstract class BaseMailer implements MailerInterface
{
    /**
     * @var array
     */
    protected $config;

    /**
     * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
     */
    protected $dispatcher;

    /**
     * Constructor
     *
     * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface 	$dispatcher
     * @param \Symfony\Component\Templating\EngineInterface                 $templating
     * @param array                                                         $config
     */
    public function __construct(EventDispatcherInterface $dispatcher, EngineInterface $templating, $config)
    {
        $this->config = $config;
        $this->dispatcher = $dispatcher;
        $this->templating = $templating;
    }

    /**
     * @param EntryInterface $entry
     *
     * @return mixed
     */
    public function sendAdminNotification(EntryInterface $entry)
    {
        $emailTitle = str_replace(
            array('{name}','{email}'),
            array($entry->getName(), $entry->getEmail()),
            $this->config['notification']['title']
		);

        $mailOptions = array();
        $mailOptions['subject'] = $emailTitle;
        $mailOptions['from'] = $this->config['notification']['from'];
        $mailOptions['to'] = $this->config['notification']['to'];
        $mailOptions['body'] = $this->templating->render(
            $this->config['notification']['view'],
            array('entry' => $entry)
        );

        $event = new MailEvent($entry, $mailOptions);
        $this->dispatcher->dispatch(Events::ENTRY_PRE_NOTIFY, $event);

        if ($event->isPropagationStopped()) {
            return false;
        }
		
		$this->sendEmail($mailOptions);
        $this->dispatcher->dispatch(Events::ENTRY_POST_NOTIFY, $event);

		return true;
    }

    /**
     * @param \Symfony\Component\Form\FormInterface		$form
     * @param EntryInterface 							$entry
     *
     * @return boolean
     */
    public function sendReply(FormInterface $form, EntryInterface $entry)
    {
        $mailOptions = array();
        $mailOptions['from'] = $form->get('senderEmail')->getData();
        $mailOptions['to'] = $form->get('email')->getData();
        $mailOptions['body'] = $form->get('message')->getData();
        $mailOptions['subject'] = $form->get('title')->getData();

        $event = new MailEvent($entry, $mailOptions);
        $this->dispatcher->dispatch(Events::ENTRY_PRE_REPLY, $event);

        if ($event->isPropagationStopped()) {
            return false;
        }
		
		$this->sendEmail($mailOptions);
        $this->dispatcher->dispatch(Events::ENTRY_POST_REPLY, $event);
		
		return true;
    }
}
<commit_msg>Mailer<commit_after><?php

/*
 * This file is part of the BrotherGuestbookBundle package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Brother\GuestbookBundle\Mailer;

use Brother\CommonBundle\Event\Events;
use Brother\CommonBundle\Event\MailEvent;
use Brother\GuestbookBundle\Model\EntryInterface;

use Symfony\Component\Form\FormInterface;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * Base class for the Mailer.
 */
abstract class BaseMailer implements MailerInterface
{
    /**
     * @var array
     */
    protected $config;

    /**
     * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
     */
    protected $dispatcher;

    /**
     * Constructor
     *
     * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface 	$dispatcher
     * @param \Symfony\Component\Templating\EngineInterface                 $templating
     * @param array                                                         $config
     */
    public function __construct(EventDispatcherInterface $dispatcher, EngineInterface $templating, $config)
    {
        $this->config = $config;
        $this->dispatcher = $dispatcher;
        $this->templating = $templating;
    }

    /**
     * @param EntryInterface $entry
     *
     * @return mixed
     */
    public function sendAdminNotification(EntryInterface $entry)
    {
        $emailTitle = str_replace(
            array('{name}','{email}'),
            array($entry->getName(), $entry->getEmail()),
            $this->config['notification']['title']
		);

        $mailOptions = array();
        $mailOptions['subject'] = $emailTitle;
        $mailOptions['from'] = $this->config['notification']['from'];
        $mailOptions['to'] = $this->config['notification']['to'];
        $mailOptions['body'] = $this->templating->render(
            $this->config['notification']['view'],
            array('entry' => $entry)
        );

        $event = new MailEvent($entry, $mailOptions);
        $this->dispatcher->dispatch(Events::ENTRY_PRE_NOTIFY, $event);

        if ($event->isPropagationStopped()) {
            return false;
        }
		
		$this->sendEmail($mailOptions);
        $this->dispatcher->dispatch(Events::ENTRY_POST_NOTIFY, $event);

		return true;
    }

    /**
     * @param \Symfony\Component\Form\FormInterface		$form
     * @param EntryInterface 							$entry
     *
     * @return boolean
     */
    public function sendReply(FormInterface $form, EntryInterface $entry)
    {
        $mailOptions = array();
        $mailOptions['from'] = $form->get('senderEmail')->getData();
        $mailOptions['to'] = $form->get('email')->getData();
        $mailOptions['body'] = $form->get('message')->getData();
        $mailOptions['subject'] = $form->get('title')->getData();

        $event = new MailEvent($entry, $mailOptions);
        $this->dispatcher->dispatch(Events::ENTRY_PRE_REPLY, $event);

        if ($event->isPropagationStopped()) {
            return false;
        }
		
		$this->sendEmail($mailOptions);
        $this->dispatcher->dispatch(Events::ENTRY_POST_REPLY, $event);
		
		return true;
    }
}

{'fraction_non_alphanumeric': 0.14443938704293735, 'fraction_numerical': 0.0, 'mean_word_length': 2.7179921037789057, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2602234', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1825, 'n_words': 338}