<commit_before><?php

namespace Theodo\SendGridMailerBundle\Mailer;

use SendGrid as SendGridService;
use SendGrid\Email;

use Theodo\SendGridMailerBundle\Factory\SendGridEmailFactory;

/**
 * Send emails via the sendGridMailer API
 * Different methods can be used depending on the use case
 *
 * @author <NAME> <<EMAIL>>
 */
class SendGridMailer
{
    /**
     * @var SendGridService
     */
    protected $sendGridService;

    /**
     * @var SendGridEmailFactory
     */
    protected $sendGridEmailFactory;

    /**
     * @param string                $sendGridUserLogin     the send grid user's account login
     * @param string                $sendGridUserPassword  the send grid user's account password
     * @param SendGridEmailFactory  $sendGridEmailFactory  the factory to generate send grid specific emails
     */
    public function __construct($sendGridUserLogin, $sendGridUserPassword, SendGridEmailFactory $sendGridEmailFactory)
    {
        $this->sendGridService = new SendGridService($sendGridUserLogin, $sendGridUserPassword, array("turn_off_ssl_verification" => true));
        $this->sendGridEmailFactory = $sendGridEmailFactory;
    }

    /**
     * Send an already fully prepared email
     * Return true if the mail has been effectively sent, false otherwise
     *
     * @param Email $email
     * @return bool
     */
    public function sendSendGridEmail(Email $email)
    {
        $response = $this->sendGridService->send($email);

        return $response->message == 'success';
    }

    /**
     * @param $from
     * @param $from_name
     * @param $to
     * @param $subject
     * @param $html
     * @return bool
     */
    public function sendEmail($from, $from_name, $to, $subject, $html)
    {
        $options = compact('from', 'from_name', 'to', 'subject', 'html');
        $sendGridEmail = $this->sendGridEmailFactory->createFromParameters($options);

        return $this->sendSendGridEmail($sendGridEmail);
    }
}<commit_msg>[master] Adds possibility to set attachments<commit_after><?php

namespace Theodo\SendGridMailerBundle\Mailer;

use SendGrid as SendGridService;
use SendGrid\Email;

use Theodo\SendGridMailerBundle\Factory\SendGridEmailFactory;

/**
 * Send emails via the sendGridMailer API
 * Different methods can be used depending on the use case
 *
 * @author <NAME> <<EMAIL>>
 */
class SendGridMailer
{
    /**
     * @var SendGridService
     */
    protected $sendGridService;

    /**
     * @var SendGridEmailFactory
     */
    protected $sendGridEmailFactory;

    /**
     * @param string                $sendGridUserLogin     the send grid user's account login
     * @param string                $sendGridUserPassword  the send grid user's account password
     * @param SendGridEmailFactory  $sendGridEmailFactory  the factory to generate send grid specific emails
     */
    public function __construct($sendGridUserLogin, $sendGridUserPassword, SendGridEmailFactory $sendGridEmailFactory)
    {
        $this->sendGridService = new SendGridService($sendGridUserLogin, $sendGridUserPassword, array("turn_off_ssl_verification" => true));
        $this->sendGridEmailFactory = $sendGridEmailFactory;
    }

    /**
     * Send an already fully prepared email
     * Return true if the mail has been effectively sent, false otherwise
     *
     * @param Email $email
     * @return bool
     */
    public function sendSendGridEmail(Email $email)
    {
        $response = $this->sendGridService->send($email);

        return $response->message == 'success';
    }

    /**
     * @param $from
     * @param $from_name
     * @param $to
     * @param $subject
     * @param $html
     * @param $attachments
     * @return bool
     */
    public function sendEmail($from, $from_name, $to, $subject, $html, $attachments)
    {
        $options = compact('from', 'from_name', 'to', 'subject', 'html');
        $sendGridEmail = $this->sendGridEmailFactory->createFromParameters($options);
        $sendGridEmail->setAttachments($attachments);

        return $this->sendSendGridEmail($sendGridEmail);
    }
}
{'fraction_non_alphanumeric': 0.10577864838393732, 'fraction_numerical': 0.0, 'mean_word_length': 3.0485629335976214, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 28, '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': '6478722', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1127, 'n_words': 295}