Skip to content

Commit

Permalink
Add swiftmailer bc-layer and update pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlagler committed Apr 10, 2024
1 parent d538845 commit 2061319
Show file tree
Hide file tree
Showing 21 changed files with 195 additions and 104 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,25 @@ jobs:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.1'
lint: true
lint: false
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.2'
lint: false
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak

- php-version: '8.3'
lint: true
dependency-versions: 'highest'
tools: 'composer:v2'
env:
SYMFONY_DEPRECATIONS_HELPER: weak
services:
mysql:
image: mysql:5.7
Expand All @@ -71,6 +84,11 @@ jobs:
if: ${{ matrix.php-version == '7.2' }}
run: composer remove php-cs-fixer/shim --dev --no-interaction

- name: Install additional lowest dependencies
if: ${{ matrix.dependency-versions == 'lowest' }}
run: |
composer require symfony/swiftmailer-bundle --no-interaction --no-update
- name: Install composer dependencies
uses: ramsey/composer-install@v1
with:
Expand Down
41 changes: 18 additions & 23 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,33 @@
$config->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'ordered_imports' => true,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'phpdoc_align' => ['align' => 'left'],
'class_definition' => [
'multi_line_extends_each_single_line' => true,
] ,
'linebreak_after_opening_tag' => true,
// 'declare_strict_types' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'class_definition' => false,
'concat_space' => ['spacing' => 'one'],
'function_declaration' => ['closure_function_spacing' => 'none'],
'header_comment' => ['header' => $header],
'native_constant_invocation' => true,
'native_function_casing' => true,
'native_function_invocation' => ['include' => ['@internal']],
'no_php4_constructor' => true,
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'remove_inheritdoc' => true],
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'php_unit_strict' => true,
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
'strict_comparison' => true,
'strict_param' => true,
'array_indentation' => true,
'multiline_whitespace_before_semicolons' => true,
'ordered_imports' => true,
'phpdoc_align' => ['align' => 'left'],
'phpdoc_types_order' => false,
'single_line_throw' => false,
'visibility_required' => ['elements' => ['property', 'method', 'const']],
'single_line_comment_spacing' => false,
'phpdoc_to_comment' => [
'ignored_tags' => ['todo', 'var'],
],
'trailing_comma_in_multiline' => ['elements' => ['arrays', /*'arguments', 'parameters' */]],
'phpdoc_separation' => [
'groups' => [
['Serializer\\*', 'VirtualProperty', 'Accessor', 'Type', 'Groups', 'Expose', 'Exclude', 'SerializedName', 'Inline', 'ExclusionPolicy'],
],
],
'get_class_to_class_keyword' => false, // should be enabled as soon as support for php < 8 is dropped
'nullable_type_declaration_for_default_null_value' => true,
'no_null_property_initialization' => false,
'fully_qualified_strict_types' => false,
])
->setFinder($finder);

Expand Down
14 changes: 5 additions & 9 deletions Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ protected function encodePassword(User $user, string $plainPassword): string
$hasher = $this->container->get('?security.password_hasher');

return $hasher->hashPassword($user, $plainPassword);
} else {
/** @var \Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface $encoder */
$encoder = $this->container->get('?security.password_encoder');

return $encoder->encodePassword($user, $plainPassword);
}
/** @var \Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface $encoder */
$encoder = $this->container->get('?security.password_encoder');

return $encoder->encodePassword($user, $plainPassword);
}

/**
Expand Down Expand Up @@ -147,9 +146,6 @@ private function getTemplateAttributes(array $custom = []): array
return $this->getTemplateAttributeResolver()->resolve($custom);
}

/**
* @return User
*/
public function getUser(): ?User
{
$user = parent::getUser();
Expand Down Expand Up @@ -190,7 +186,7 @@ private function addAddress(User $user): void
/**
* @param mixed[] $parameters
*/
public function render(string $view, array $parameters = [], Response $response = null): Response
public function render(string $view, array $parameters = [], ?Response $response = null): Response
{
return parent::render(
$view,
Expand Down
3 changes: 2 additions & 1 deletion Controller/BlacklistItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Provides admin-api for blacklist-items.
*
* @NamePrefix("sulu_community.")
*
* @RouteResource("blacklist-item")
*/
class BlacklistItemController extends AbstractRestController implements ClassResourceInterface
Expand Down Expand Up @@ -148,7 +149,7 @@ public function deleteAction(int $id): Response
*/
public function cdeleteAction(Request $request): Response
{
$ids = \array_map(function ($id) {
$ids = \array_map(function($id) {
return (int) $id;
}, \array_filter(\explode(',', (string) $request->query->get('ids', ''))));

Expand Down
2 changes: 1 addition & 1 deletion Controller/ConfirmationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function indexAction(Request $request, string $token): Response
$redirectTo = $communityManager->getConfigTypeProperty(self::TYPE, Configuration::REDIRECT_TO);

if ($redirectTo) {
if (0 === \strpos($redirectTo, '/')) {
if (\str_starts_with($redirectTo, '/')) {
$url = \str_replace('{localization}', $request->getLocale(), $redirectTo);
} else {
$url = $this->getRouter()->generate($redirectTo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
* },
* delete_user: bool,
* }
*
* @phpstan-type Config array{
* from: string|string[],
* to: string|string[],
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function getConfigTreeBuilder()
->end()
->beforeNormalization()
->ifString()
->then(function ($value) {
->then(function($value) {
return [
self::EMAIL_FROM_NAME => $value,
self::EMAIL_FROM_EMAIL => $value,
Expand All @@ -151,7 +151,7 @@ public function getConfigTreeBuilder()
->end()
->beforeNormalization()
->ifString()
->then(function ($value) {
->then(function($value) {
return [
self::EMAIL_TO_NAME => $value,
self::EMAIL_TO_EMAIL => $value,
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/SuluCommunityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function prepend(ContainerBuilder $container): void
'orm' => [
'dql' => [
'string_functions' => [
'regexp' => RegExp::class,
'regexp' => Regexp::class,
],
],
],
Expand Down
4 changes: 0 additions & 4 deletions Entity/BlacklistItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ class BlacklistItem
*/
private $type;

/**
* @param string $pattern
* @param string $type
*/
public function __construct(?string $pattern = null, ?string $type = null)
{
$this->type = $type;
Expand Down
2 changes: 1 addition & 1 deletion EventListener/LastLoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function getSubscribedEvents()
*/
public function onRequest(RequestEvent $event): void
{
if (!$event->isMasterRequest()) {
if (!$event->isMainRequest()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Form/Type/RegistrationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function configureOptions(OptionsResolver $resolver): void
[
'data_class' => User::class,
'validation_groups' => ['registration'],
'empty_data' => function (FormInterface $form) {
'empty_data' => function(FormInterface $form) {
$user = new User();
$user->setContact(new Contact());

Expand Down
2 changes: 0 additions & 2 deletions Mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class Mail
* user_template: string|null,
* admin_template: string|null,
* } $config
*
* @return Mail
*/
public static function create($from, $to, array $config): self
{
Expand Down
41 changes: 26 additions & 15 deletions Mail/MailFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Sulu\Bundle\CommunityBundle\Mail;

use Sulu\Bundle\SecurityBundle\Entity\User;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
Expand All @@ -25,7 +26,7 @@
class MailFactory implements MailFactoryInterface
{
/**
* @var MailerInterface
* @var MailerInterface|\Swift_Mailer
*/
protected $mailer;

Expand All @@ -39,7 +40,7 @@ class MailFactory implements MailFactoryInterface
*/
protected $translator;

public function __construct(MailerInterface $mailer, Environment $twig, TranslatorInterface $translator)
public function __construct($mailer, Environment $twig, TranslatorInterface $translator)
{
$this->mailer = $mailer;
$this->twig = $twig;
Expand Down Expand Up @@ -72,7 +73,6 @@ public function sendEmails(Mail $mail, User $user, array $parameters = []): void
}
}


/**
* Create and send email.
*
Expand All @@ -84,30 +84,41 @@ protected function sendEmail($from, $to, string $subject, string $template, arra
{
$body = $this->twig->render($template, $data);

$email = (new Email())
->subject($this->translator->trans($subject))
->from($this->getAddress($from))
->to($this->getAddress($to))
->html($body);
if ($this->mailer instanceof \Swift_Mailer) {
$email = $this->mailer->createMessage()
->setSubject($this->translator->trans($subject))
->setFrom($from)
->setTo($to)
->setBody($body, 'text/html');
} else {
if (!$this->getAddress($from) || !$this->getAddress($to)) {
return;
}

$email = (new Email())
->subject($this->translator->trans($subject))
->from($this->getAddress($from))
->to($this->getAddress($to))
->html($body);
}

$this->mailer->send($email);
}

/**
* Convert string/array email address to an Address object
* Convert string/array email address to an Address object.
*
* @param $address
* @return Address
* @param mixed $address
*/
protected function getAddress($address): ?Address
{
$name = '';

if (is_array($address)) {
if(empty($address)) {
if (\is_array($address)) {
if (empty($address)) {
return null;
} else if (!isset($address['email'])) {
$email = $address[array_keys($address)[0]];
} elseif (!isset($address['email'])) {
$email = $address[\array_keys($address)[0]];
} else {
$email = $address['email'];
$name = $address['name'] ?? '';
Expand Down
11 changes: 4 additions & 7 deletions Manager/CommunityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* },
* delete_user: bool,
* }
*
* @phpstan-type Config array{
* from: string|string[],
* to: string|string[],
Expand Down Expand Up @@ -109,9 +108,9 @@ public function getConfig(): array;
*
* @param TConfig $property
*
* @throws \InvalidArgumentException
*
* @return Config[TTypeConfig]
*
* @throws \InvalidArgumentException
*/
public function getConfigProperty(string $property);

Expand All @@ -124,9 +123,9 @@ public function getConfigProperty(string $property);
* @param TConfig $type
* @param TTypeConfigProperty $property
*
* @throws \InvalidArgumentException
*
* @return Config[TConfig][TTypeConfigProperty]
*
* @throws \InvalidArgumentException
*/
public function getConfigTypeProperty(string $type, string $property);

Expand All @@ -137,8 +136,6 @@ public function sendEmails(string $type, User $user): void;

/**
* Save profile for given user.
*
* @return User
*/
public function saveProfile(User $user): ?User;
}
Loading

0 comments on commit 2061319

Please sign in to comment.