login consent app sql
This commit is contained in:
105
vendor/symfony/twig-bridge/Mime/BodyRenderer.php
vendored
Normal file
105
vendor/symfony/twig-bridge/Mime/BodyRenderer.php
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Twig\Mime;
|
||||
|
||||
use League\HTMLToMarkdown\HtmlConverter;
|
||||
use Symfony\Component\Mime\BodyRendererInterface;
|
||||
use Symfony\Component\Mime\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Mime\Message;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
final class BodyRenderer implements BodyRendererInterface
|
||||
{
|
||||
private $twig;
|
||||
private $context;
|
||||
private $converter;
|
||||
|
||||
public function __construct(Environment $twig, array $context = [])
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->context = $context;
|
||||
if (class_exists(HtmlConverter::class)) {
|
||||
$this->converter = new HtmlConverter([
|
||||
'hard_break' => true,
|
||||
'strip_tags' => true,
|
||||
'remove_nodes' => 'head style',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function render(Message $message): void
|
||||
{
|
||||
if (!$message instanceof TemplatedEmail) {
|
||||
return;
|
||||
}
|
||||
|
||||
$messageContext = $message->getContext();
|
||||
|
||||
$previousRenderingKey = $messageContext[__CLASS__] ?? null;
|
||||
unset($messageContext[__CLASS__]);
|
||||
$currentRenderingKey = $this->getFingerPrint($message);
|
||||
if ($previousRenderingKey === $currentRenderingKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($messageContext['email'])) {
|
||||
throw new InvalidArgumentException(sprintf('A "%s" context cannot have an "email" entry as this is a reserved variable.', get_debug_type($message)));
|
||||
}
|
||||
|
||||
$vars = array_merge($this->context, $messageContext, [
|
||||
'email' => new WrappedTemplatedEmail($this->twig, $message),
|
||||
]);
|
||||
|
||||
if ($template = $message->getTextTemplate()) {
|
||||
$message->text($this->twig->render($template, $vars));
|
||||
}
|
||||
|
||||
if ($template = $message->getHtmlTemplate()) {
|
||||
$message->html($this->twig->render($template, $vars));
|
||||
}
|
||||
|
||||
// if text body is empty, compute one from the HTML body
|
||||
if (!$message->getTextBody() && null !== $html = $message->getHtmlBody()) {
|
||||
$message->text($this->convertHtmlToText(\is_resource($html) ? stream_get_contents($html) : $html));
|
||||
}
|
||||
$message->context($message->getContext() + [__CLASS__ => $currentRenderingKey]);
|
||||
}
|
||||
|
||||
private function getFingerPrint(TemplatedEmail $message): string
|
||||
{
|
||||
$messageContext = $message->getContext();
|
||||
unset($messageContext[__CLASS__]);
|
||||
|
||||
$payload = [$messageContext, $message->getTextTemplate(), $message->getHtmlTemplate()];
|
||||
try {
|
||||
$serialized = serialize($payload);
|
||||
} catch (\Exception $e) {
|
||||
// Serialization of 'Closure' is not allowed
|
||||
// Happens when context contain a closure, in that case, we assume that context always change.
|
||||
$serialized = random_bytes(8);
|
||||
}
|
||||
|
||||
return md5($serialized);
|
||||
}
|
||||
|
||||
private function convertHtmlToText(string $html): string
|
||||
{
|
||||
if (null !== $this->converter) {
|
||||
return $this->converter->convert($html);
|
||||
}
|
||||
|
||||
return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}is', '', $html));
|
||||
}
|
||||
}
|
250
vendor/symfony/twig-bridge/Mime/NotificationEmail.php
vendored
Normal file
250
vendor/symfony/twig-bridge/Mime/NotificationEmail.php
vendored
Normal file
@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Twig\Mime;
|
||||
|
||||
use Symfony\Component\ErrorHandler\Exception\FlattenException;
|
||||
use Symfony\Component\Mime\Header\Headers;
|
||||
use Symfony\Component\Mime\Part\AbstractPart;
|
||||
use Twig\Extra\CssInliner\CssInlinerExtension;
|
||||
use Twig\Extra\Inky\InkyExtension;
|
||||
use Twig\Extra\Markdown\MarkdownExtension;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class NotificationEmail extends TemplatedEmail
|
||||
{
|
||||
public const IMPORTANCE_URGENT = 'urgent';
|
||||
public const IMPORTANCE_HIGH = 'high';
|
||||
public const IMPORTANCE_MEDIUM = 'medium';
|
||||
public const IMPORTANCE_LOW = 'low';
|
||||
|
||||
private $theme = 'default';
|
||||
private $context = [
|
||||
'importance' => self::IMPORTANCE_LOW,
|
||||
'content' => '',
|
||||
'exception' => false,
|
||||
'action_text' => null,
|
||||
'action_url' => null,
|
||||
'markdown' => false,
|
||||
'raw' => false,
|
||||
'footer_text' => 'Notification e-mail sent by Symfony',
|
||||
];
|
||||
|
||||
public function __construct(Headers $headers = null, AbstractPart $body = null)
|
||||
{
|
||||
$missingPackages = [];
|
||||
if (!class_exists(CssInlinerExtension::class)) {
|
||||
$missingPackages['twig/cssinliner-extra'] = 'CSS Inliner';
|
||||
}
|
||||
|
||||
if (!class_exists(InkyExtension::class)) {
|
||||
$missingPackages['twig/inky-extra'] = 'Inky';
|
||||
}
|
||||
|
||||
if ($missingPackages) {
|
||||
throw new \LogicException(sprintf('You cannot use "%s" if the "%s" Twig extension%s not available; try running "%s".', static::class, implode('" and "', $missingPackages), \count($missingPackages) > 1 ? 's are' : ' is', 'composer require '.implode(' ', array_keys($missingPackages))));
|
||||
}
|
||||
|
||||
parent::__construct($headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a NotificationEmail instance that is appropriate to send to normal (non-admin) users.
|
||||
*/
|
||||
public static function asPublicEmail(Headers $headers = null, AbstractPart $body = null): self
|
||||
{
|
||||
$email = new static($headers, $body);
|
||||
$email->markAsPublic();
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function markAsPublic(): self
|
||||
{
|
||||
$this->context['importance'] = null;
|
||||
$this->context['footer_text'] = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function markdown(string $content)
|
||||
{
|
||||
if (!class_exists(MarkdownExtension::class)) {
|
||||
throw new \LogicException(sprintf('You cannot use "%s" if the Markdown Twig extension is not available; try running "composer require twig/markdown-extra".', __METHOD__));
|
||||
}
|
||||
|
||||
$this->context['markdown'] = true;
|
||||
|
||||
return $this->content($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function content(string $content, bool $raw = false)
|
||||
{
|
||||
$this->context['content'] = $content;
|
||||
$this->context['raw'] = $raw;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function action(string $text, string $url)
|
||||
{
|
||||
$this->context['action_text'] = $text;
|
||||
$this->context['action_url'] = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function importance(string $importance)
|
||||
{
|
||||
$this->context['importance'] = $importance;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Throwable|FlattenException $exception
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function exception($exception)
|
||||
{
|
||||
if (!$exception instanceof \Throwable && !$exception instanceof FlattenException) {
|
||||
throw new \LogicException(sprintf('"%s" accepts "%s" or "%s" instances.', __METHOD__, \Throwable::class, FlattenException::class));
|
||||
}
|
||||
|
||||
$exceptionAsString = $this->getExceptionAsString($exception);
|
||||
|
||||
$this->context['exception'] = true;
|
||||
$this->attach($exceptionAsString, 'exception.txt', 'text/plain');
|
||||
$this->importance(self::IMPORTANCE_URGENT);
|
||||
|
||||
if (!$this->getSubject()) {
|
||||
$this->subject($exception->getMessage());
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function theme(string $theme)
|
||||
{
|
||||
$this->theme = $theme;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTextTemplate(): ?string
|
||||
{
|
||||
if ($template = parent::getTextTemplate()) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
return '@email/'.$this->theme.'/notification/body.txt.twig';
|
||||
}
|
||||
|
||||
public function getHtmlTemplate(): ?string
|
||||
{
|
||||
if ($template = parent::getHtmlTemplate()) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
return '@email/'.$this->theme.'/notification/body.html.twig';
|
||||
}
|
||||
|
||||
public function getContext(): array
|
||||
{
|
||||
return array_merge($this->context, parent::getContext());
|
||||
}
|
||||
|
||||
public function getPreparedHeaders(): Headers
|
||||
{
|
||||
$headers = parent::getPreparedHeaders();
|
||||
|
||||
$importance = $this->context['importance'] ?? self::IMPORTANCE_LOW;
|
||||
$this->priority($this->determinePriority($importance));
|
||||
if ($this->context['importance']) {
|
||||
$headers->setHeaderBody('Text', 'Subject', sprintf('[%s] %s', strtoupper($importance), $this->getSubject()));
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
private function determinePriority(string $importance): int
|
||||
{
|
||||
switch ($importance) {
|
||||
case self::IMPORTANCE_URGENT:
|
||||
return self::PRIORITY_HIGHEST;
|
||||
case self::IMPORTANCE_HIGH:
|
||||
return self::PRIORITY_HIGH;
|
||||
case self::IMPORTANCE_MEDIUM:
|
||||
return self::PRIORITY_NORMAL;
|
||||
case self::IMPORTANCE_LOW:
|
||||
default:
|
||||
return self::PRIORITY_LOW;
|
||||
}
|
||||
}
|
||||
|
||||
private function getExceptionAsString($exception): string
|
||||
{
|
||||
if (class_exists(FlattenException::class)) {
|
||||
$exception = $exception instanceof FlattenException ? $exception : FlattenException::createFromThrowable($exception);
|
||||
|
||||
return $exception->getAsString();
|
||||
}
|
||||
|
||||
$message = \get_class($exception);
|
||||
if ('' !== $exception->getMessage()) {
|
||||
$message .= ': '.$exception->getMessage();
|
||||
}
|
||||
|
||||
$message .= ' in '.$exception->getFile().':'.$exception->getLine()."\n";
|
||||
$message .= "Stack trace:\n".$exception->getTraceAsString()."\n\n";
|
||||
|
||||
return rtrim($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
return [$this->context, parent::__serialize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
[$this->context, $parentData] = $data;
|
||||
|
||||
parent::__unserialize($parentData);
|
||||
}
|
||||
}
|
87
vendor/symfony/twig-bridge/Mime/TemplatedEmail.php
vendored
Normal file
87
vendor/symfony/twig-bridge/Mime/TemplatedEmail.php
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Twig\Mime;
|
||||
|
||||
use Symfony\Component\Mime\Email;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class TemplatedEmail extends Email
|
||||
{
|
||||
private $htmlTemplate;
|
||||
private $textTemplate;
|
||||
private $context = [];
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function textTemplate(?string $template)
|
||||
{
|
||||
$this->textTemplate = $template;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function htmlTemplate(?string $template)
|
||||
{
|
||||
$this->htmlTemplate = $template;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTextTemplate(): ?string
|
||||
{
|
||||
return $this->textTemplate;
|
||||
}
|
||||
|
||||
public function getHtmlTemplate(): ?string
|
||||
{
|
||||
return $this->htmlTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function context(array $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContext(): array
|
||||
{
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
return [$this->htmlTemplate, $this->textTemplate, $this->context, parent::__serialize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
[$this->htmlTemplate, $this->textTemplate, $this->context, $parentData] = $data;
|
||||
|
||||
parent::__unserialize($parentData);
|
||||
}
|
||||
}
|
194
vendor/symfony/twig-bridge/Mime/WrappedTemplatedEmail.php
vendored
Normal file
194
vendor/symfony/twig-bridge/Mime/WrappedTemplatedEmail.php
vendored
Normal file
@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Twig\Mime;
|
||||
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
final class WrappedTemplatedEmail
|
||||
{
|
||||
private $twig;
|
||||
private $message;
|
||||
|
||||
public function __construct(Environment $twig, TemplatedEmail $message)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
public function toName(): string
|
||||
{
|
||||
return $this->message->getTo()[0]->getName();
|
||||
}
|
||||
|
||||
public function image(string $image, string $contentType = null): string
|
||||
{
|
||||
$file = $this->twig->getLoader()->getSourceContext($image);
|
||||
if ($path = $file->getPath()) {
|
||||
$this->message->embedFromPath($path, $image, $contentType);
|
||||
} else {
|
||||
$this->message->embed($file->getCode(), $image, $contentType);
|
||||
}
|
||||
|
||||
return 'cid:'.$image;
|
||||
}
|
||||
|
||||
public function attach(string $file, string $name = null, string $contentType = null): void
|
||||
{
|
||||
$file = $this->twig->getLoader()->getSourceContext($file);
|
||||
if ($path = $file->getPath()) {
|
||||
$this->message->attachFromPath($path, $name, $contentType);
|
||||
} else {
|
||||
$this->message->attach($file->getCode(), $name, $contentType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setSubject(string $subject): self
|
||||
{
|
||||
$this->message->subject($subject);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSubject(): ?string
|
||||
{
|
||||
return $this->message->getSubject();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setReturnPath(string $address): self
|
||||
{
|
||||
$this->message->returnPath($address);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReturnPath(): string
|
||||
{
|
||||
return $this->message->getReturnPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function addFrom(string $address, string $name = ''): self
|
||||
{
|
||||
$this->message->addFrom(new Address($address, $name));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Address[]
|
||||
*/
|
||||
public function getFrom(): array
|
||||
{
|
||||
return $this->message->getFrom();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function addReplyTo(string $address): self
|
||||
{
|
||||
$this->message->addReplyTo($address);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Address[]
|
||||
*/
|
||||
public function getReplyTo(): array
|
||||
{
|
||||
return $this->message->getReplyTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function addTo(string $address, string $name = ''): self
|
||||
{
|
||||
$this->message->addTo(new Address($address, $name));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Address[]
|
||||
*/
|
||||
public function getTo(): array
|
||||
{
|
||||
return $this->message->getTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function addCc(string $address, string $name = ''): self
|
||||
{
|
||||
$this->message->addCc(new Address($address, $name));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Address[]
|
||||
*/
|
||||
public function getCc(): array
|
||||
{
|
||||
return $this->message->getCc();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function addBcc(string $address, string $name = ''): self
|
||||
{
|
||||
$this->message->addBcc(new Address($address, $name));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Address[]
|
||||
*/
|
||||
public function getBcc(): array
|
||||
{
|
||||
return $this->message->getBcc();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setPriority(int $priority): self
|
||||
{
|
||||
$this->message->priority($priority);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPriority(): int
|
||||
{
|
||||
return $this->message->getPriority();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user