Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sulu/SuluCommunityBundle
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 539cdb5dc811f30512d76f5abbe82f62d11bd70c
Choose a base ref
..
head repository: sulu/SuluCommunityBundle
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d576ea6c702aead93c03e1aa91513ee1aadfb490
Choose a head ref
Showing with 420 additions and 190 deletions.
  1. +19 −1 .github/workflows/test-application.yaml
  2. +18 −23 .php-cs-fixer.dist.php
  3. +39 −13 Controller/AbstractController.php
  4. +1 −1 Controller/CompletionController.php
  5. +2 −2 Controller/PasswordController.php
  6. +1 −1 Controller/ProfileController.php
  7. +1 −1 Controller/RegistrationController.php
  8. +3 −2 Controller/RegistrationRuleItemController.php
  9. +2 −2 Controller/SaveMediaTrait.php
  10. +0 −1 DependencyInjection/CompilerPass/CommunityManagerCompilerPass.php
  11. +2 −2 DependencyInjection/Configuration.php
  12. +1 −1 DependencyInjection/SuluCommunityExtension.php
  13. +0 −4 Entity/RegistrationRuleItem.php
  14. +1 −1 EventListener/CompletionListener.php
  15. +1 −1 EventListener/LastLoginListener.php
  16. +1 −1 Form/Type/RegistrationType.php
  17. +0 −2 Mail/Mail.php
  18. +49 −8 Mail/MailFactory.php
  19. +0 −1 Manager/CommunityManager.php
  20. +4 −7 Manager/CommunityManagerInterface.php
  21. +1 −1 README.md
  22. +1 −1 Tests/Application/Kernel.php
  23. +28 −0 Tests/Application/config/config.php
  24. +1 −1 Tests/Application/config/{config_admin.yml → context_admin.yml}
  25. +9 −0 Tests/Application/config/context_website.yml
  26. +0 −10 Tests/Application/config/{config_website.yml → security-5-4.yml}
  27. +29 −0 Tests/Application/config/security-6.yml
  28. +3 −2 Tests/Application/config/{config.yml → sulu.yml}
  29. +13 −0 Tests/Functional/Controller/ProfileControllerTest.php
  30. +60 −30 Tests/Functional/Controller/RegistrationTest.php
  31. +1 −1 Tests/Unit/Listener/EmailConfirmationListenerTest.php
  32. +1 −1 Tests/Unit/Listener/RegistrationRuleListenerTest.php
  33. +35 −44 Tests/Unit/Mail/MailFactoryTest.php
  34. +1 −1 Tests/phpstan/object-manager.php
  35. +30 −21 composer.json
  36. +62 −2 phpstan-baseline.neon
20 changes: 19 additions & 1 deletion .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
@@ -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
@@ -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:
41 changes: 18 additions & 23 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -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);

52 changes: 39 additions & 13 deletions Controller/AbstractController.php
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;

/**
* Contains helper function for all controllers.
@@ -75,12 +75,26 @@ protected function setUserPasswordAndSalt(User $user, FormInterface $form): User
}

$user->setSalt($salt);
$password = $this->getUserPasswordEncoder()->encodePassword($user, $plainPassword);
$password = $this->encodePassword($user, $plainPassword);
$user->setPassword($password);

return $user;
}

protected function encodePassword(User $user, string $plainPassword): string
{
if ($this->container->has('?security.password_hasher')) {
/** @var UserPasswordHasherInterface $hasher */
$hasher = $this->container->get('?security.password_hasher');

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

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

/**
* Check if user should be logged in.
*/
@@ -106,9 +120,25 @@ protected function renderTemplate(string $type, array $data = []): Response
Configuration::TEMPLATE
);

$response = new Response();

// Reuse logic from Symfony AbstractController.
// See: https://github.com/symfony/symfony/blob/6.3/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php#L239-L243
// See: https://github.com/symfony/symfony/blob/6.3/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php#L260-L265
foreach ($data as $k => $v) {
if ($v instanceof FormInterface) {
if ($v->isSubmitted() && !$v->isValid()) {
$response->setStatusCode(422);
}

$data[$k] = $v->createView();
}
}

return $this->render(
$template,
$data
$data,
$response
);
}

@@ -132,9 +162,6 @@ private function getTemplateAttributes(array $custom = []): array
return $this->getTemplateAttributeResolver()->resolve($custom);
}

/**
* @return User
*/
public function getUser(): ?User
{
$user = parent::getUser();
@@ -175,7 +202,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,
@@ -207,11 +234,6 @@ protected function getSaltGenerator(): SaltGenerator
return $this->container->get('sulu_security.salt_generator');
}

protected function getUserPasswordEncoder(): UserPasswordEncoderInterface
{
return $this->container->get('security.password_encoder');
}

protected function getTemplateAttributeResolver(): TemplateAttributeResolverInterface
{
return $this->container->get('sulu_website.resolver.template_attribute');
@@ -232,9 +254,13 @@ public static function getSubscribedServices(): array
$subscribedServices['sulu_community.community_manager.registry'] = CommunityManagerRegistryInterface::class;
$subscribedServices['sulu_core.webspace.request_analyzer'] = RequestAnalyzerInterface::class;
$subscribedServices['sulu_security.salt_generator'] = SaltGenerator::class;
$subscribedServices['security.password_encoder'] = UserPasswordEncoderInterface::class;
$subscribedServices['sulu_website.resolver.template_attribute'] = TemplateAttributeResolverInterface::class;
$subscribedServices['doctrine.orm.entity_manager'] = EntityManagerInterface::class;
$subscribedServices['?security.password_hasher'] = UserPasswordHasherInterface::class;

if (\class_exists('Symfony\\Component\\Security\\Core\\Encoder\\UserPasswordEncoderInterface')) {
$subscribedServices['?security.password_encoder'] = 'Symfony\\Component\\Security\\Core\\Encoder\\UserPasswordEncoderInterface';
}

return $subscribedServices;
}
2 changes: 1 addition & 1 deletion Controller/CompletionController.php
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ public function indexAction(Request $request): Response
return $this->renderTemplate(
self::TYPE,
[
'form' => $form->createView(),
'form' => $form,
'success' => $success,
]
);
4 changes: 2 additions & 2 deletions Controller/PasswordController.php
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ public function forgetAction(Request $request): Response
return $this->renderTemplate(
Configuration::TYPE_PASSWORD_FORGET,
[
'form' => $form->createView(),
'form' => $form,
'success' => $success,
]
);
@@ -138,7 +138,7 @@ public function resetAction(Request $request, string $token): Response
return $this->renderTemplate(
Configuration::TYPE_PASSWORD_RESET,
[
'form' => $form->createView(),
'form' => $form,
'success' => $success,
]
);
2 changes: 1 addition & 1 deletion Controller/ProfileController.php
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ public function indexAction(Request $request): Response
return $this->renderTemplate(
self::TYPE,
[
'form' => $form->createView(),
'form' => $form,
'success' => $success,
]
);
2 changes: 1 addition & 1 deletion Controller/RegistrationController.php
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ public function indexAction(Request $request): Response
return $this->renderTemplate(
self::TYPE,
[
'form' => $form->createView(),
'form' => $form,
'success' => $success,
]
);
5 changes: 3 additions & 2 deletions Controller/RegistrationRuleItemController.php
Original file line number Diff line number Diff line change
@@ -34,8 +34,9 @@
* Provides admin-api for registration-rule-items.
*
* @NamePrefix("sulu_community.")
* @RouteResource("registration-rule-item")
*/
*/
class RegistrationRuleItemController extends AbstractRestController implements ClassResourceInterface
{
use RequestParametersTrait;
@@ -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', ''))));

4 changes: 2 additions & 2 deletions Controller/SaveMediaTrait.php
Original file line number Diff line number Diff line change
@@ -99,15 +99,15 @@ private function saveMedia(UploadedFile $uploadedFile, ?int $id, string $locale,
*/
private function getSystemCollectionManager(): SystemCollectionManagerInterface
{
return $this->get('sulu_media.system_collections.manager');
return $this->container->get('sulu_media.system_collections.manager');
}

/**
* Get media manager.
*/
private function getMediaManager(): MediaManagerInterface
{
return $this->get('sulu_media.media_manager');
return $this->container->get('sulu_media.media_manager');
}

/**
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@
* },
* delete_user: bool,
* }
*
* @phpstan-type Config array{
* from: string|string[],
* to: string|string[],
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -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,
@@ -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,
2 changes: 1 addition & 1 deletion DependencyInjection/SuluCommunityExtension.php
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ public function prepend(ContainerBuilder $container): void
'orm' => [
'dql' => [
'string_functions' => [
'regexp' => RegExp::class,
'regexp' => Regexp::class,
],
],
],
4 changes: 0 additions & 4 deletions Entity/RegistrationRuleItem.php
Original file line number Diff line number Diff line change
@@ -44,10 +44,6 @@ class RegistrationRuleItem
*/
private $type;

/**
* @param string $pattern
* @param string $type
*/
public function __construct(?string $pattern = null, ?string $type = null)
{
$this->type = $type;
2 changes: 1 addition & 1 deletion EventListener/CompletionListener.php
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ public function onRequest(RequestEvent $event): void
$request = $event->getRequest();
$completionUrl = $this->router->generate('sulu_community.completion');

if (!$event->isMasterRequest()
if (!$event->isMainRequest()
|| !$request->isMethodSafe()
|| $request->isXmlHttpRequest()
|| $request->getPathInfo() === $completionUrl
2 changes: 1 addition & 1 deletion EventListener/LastLoginListener.php
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ public static function getSubscribedEvents()
*/
public function onRequest(RequestEvent $event): void
{
if (!$event->isMasterRequest()) {
if (!$event->isMainRequest()) {
return;
}

2 changes: 1 addition & 1 deletion Form/Type/RegistrationType.php
Original file line number Diff line number Diff line change
@@ -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());

2 changes: 0 additions & 2 deletions Mail/Mail.php
Original file line number Diff line number Diff line change
@@ -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
{
Loading