Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sf7 migrations - last tweaks #87

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

namespace Yosimitso\WorkingForumBundle\ParamConverter;
namespace Yosimitso\WorkingForumBundle\ArgumentResolver;

use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Yosimitso\WorkingForumBundle\Entity\Forum;
Expand All @@ -14,23 +12,29 @@
use Yosimitso\WorkingForumBundle\Entity\Thread;
use Yosimitso\WorkingForumBundle\Security\AuthorizationGuardInterface;
use Yosimitso\WorkingForumBundle\Service\ThreadService;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Traversable;

class GenericParamConverter implements ParamConverterInterface
class GenericArgumentResolver implements ValueResolverInterface
{
public function __construct(
protected readonly EntityManagerInterface $em,
protected readonly AuthorizationGuardInterface $authorizationGuard,
protected readonly string $classname
) {}

public function apply(Request $request, ParamConverter $configuration)
public function resolve(Request $request, ArgumentMetadata $argument): Traversable|array
{
$value = $request->attributes->get($configuration->getName());
if (!$this->supports($request, $argument)) {
return [];
}
$value = $request->attributes->get($argument->getName());
$param = (is_numeric($value)) ? 'id' : 'slug';
$entity = $this->em->getRepository($this->classname)->findOneBy([$param => $value]);

if (is_null($entity)) {
throw new NotFoundHttpException($configuration->getName().' "'.$value.'" not found');
throw new NotFoundHttpException($argument->getName().' "'.$value.'" not found');
}

$subforumAuthorization = null;
Expand All @@ -46,13 +50,13 @@ public function apply(Request $request, ParamConverter $configuration)
throw new UnauthorizedHttpException('Forbidden');
}

$request->attributes->set($configuration->getName(), $entity);
$request->attributes->set($argument->getName(), $entity);

return true;
return [$entity];
}

function supports(ParamConverter $configuration)
function supports(Request $request, ArgumentMetadata $argument)
{
return ($this->classname === $configuration->getClass());
return ($this->classname === $argument->getType());
}
}
5 changes: 3 additions & 2 deletions Controller/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace Yosimitso\WorkingForumBundle\Controller\Admin;

use Symfony\Component\Security\Http\Attribute\IsGranted;
use Yosimitso\WorkingForumBundle\Controller\BaseController;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\Routing\Attribute\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Response;
use Yosimitso\WorkingForumBundle\Entity\Forum;
use Yosimitso\WorkingForumBundle\Entity\PostReport;

#[Route('/admin')]
#[Security('is_granted("ROLE_ADMIN") or is_granted("ROLE_MODERATOR")')]
#[IsGranted(new Expression('is_granted("ROLE_ADMIN") or is_granted("ROLE_MODERATOR")'))]
class AdminController extends BaseController
{
#[Route('', name: 'workingforum_admin')]
Expand Down
1 change: 0 additions & 1 deletion Controller/ForumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Yosimitso\WorkingForumBundle\Entity\Subforum;
use Yosimitso\WorkingForumBundle\Entity\Thread;
use Yosimitso\WorkingForumBundle\Form\RulesType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

#[Route('/')]
class ForumController extends BaseController
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('yosimitso_working_forum');
$treeBuilder
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WorkingForumBundle

ENGLISH
=================
A forum bundle for Symfony 5/6, easy to use with a lot of features
A forum bundle for Symfony 5/6/7, easy to use with a lot of features
This bundle work with your user bundle with no extra configuration (which can extend FOSUserBundle)
The bundle was made to be customizable and overridable to fit your application

Expand Down
2 changes: 1 addition & 1 deletion Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
controller_routing:
resource: "@YosimitsoWorkingForumBundle/Controller/**/*"
type: annotation
type: attribute

34 changes: 16 additions & 18 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ services:
$themeColor: '%yosimitso_working_forum.theme_color%'

Yosimitso\WorkingForumBundle\:
resource: '../../{Event,Form,ParamConverter,Repository,Security,Service,Twig,Util}'
#exclude: '../../Entity/UserTest.php'
# exclude: '../../{DependencyInjection,Entity,Migrations,Tests,Kernel.php,vendor}'

resource: '../../{Event,Form,ArgumentResolver,Repository,Security,Service,Twig,Util}'

Yosimitso\WorkingForumBundle\Controller\:
resource: '../../Controller/**'
Expand Down Expand Up @@ -64,43 +61,44 @@ services:
arguments:
- '@service_container'

Yosimitso\WorkingForumBundle\ParamConverter\GenericParamConverter:
Yosimitso\WorkingForumBundle\ArgumentResolver\GenericArgumentResolver:
autowire: false
autoconfigure: false

yosimitso_workingforum.param_converters.forum:
class: Yosimitso\WorkingForumBundle\ParamConverter\GenericParamConverter
yosimitso_workingforum.argument_resolver.forum:
class: Yosimitso\WorkingForumBundle\ArgumentResolver\GenericArgumentResolver
arguments:
- '@doctrine.orm.entity_manager'
- '@Yosimitso\WorkingForumBundle\Security\AuthorizationGuard'
- 'Yosimitso\WorkingForumBundle\Entity\Forum'
tags:
- { name: request.param_converter, priority: 20 }
- { name: controller.argument_value_resolver, priority: 150 }



yosimitso_workingforum.param_converters.subforum:
class: Yosimitso\WorkingForumBundle\ParamConverter\GenericParamConverter
yosimitso_workingforum.argument_resolver.subforum:
class: Yosimitso\WorkingForumBundle\ArgumentResolver\GenericArgumentResolver
arguments:
- '@doctrine.orm.entity_manager'
- '@Yosimitso\WorkingForumBundle\Security\AuthorizationGuard'
- 'Yosimitso\WorkingForumBundle\Entity\Subforum'
tags:
- { name: request.param_converter, priority: 20 }
- { name: controller.argument_value_resolver, priority: 150 }

yosimitso_workingforum.param_converters.thread:
class: Yosimitso\WorkingForumBundle\ParamConverter\GenericParamConverter
yosimitso_workingforum.argument_resolver.thread:
class: Yosimitso\WorkingForumBundle\ArgumentResolver\GenericArgumentResolver
arguments:
- '@doctrine.orm.entity_manager'
- '@Yosimitso\WorkingForumBundle\Security\AuthorizationGuard'
- 'Yosimitso\WorkingForumBundle\Entity\Thread'
tags:
- { name: request.param_converter, priority: 20 }
- { name: controller.argument_value_resolver, priority: 150 }

yosimitso_workingforum.param_converters.post:
class: Yosimitso\WorkingForumBundle\ParamConverter\GenericParamConverter
yosimitso_workingforum.argument_resolver.post:
class: Yosimitso\WorkingForumBundle\ArgumentResolver\GenericArgumentResolver
arguments:
- '@doctrine.orm.entity_manager'
- '@Yosimitso\WorkingForumBundle\Security\AuthorizationGuard'
- 'Yosimitso\WorkingForumBundle\Entity\Post'
tags:
- { name: request.param_converter, priority: 20 }
- { name: controller.argument_value_resolver, priority: 150 }

4 changes: 2 additions & 2 deletions Resources/views/Admin/Report/report_content.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<td>{{ post.id }}</td>
<td>{{ post.cdate | date(date_format) }}</td>
<td>{{ post.post.user.username }}</td>
<td>{{ post.post.content | quote | markdown | replace({'\n':'<br />'}) | smiley | raw }}</td>
<td>{{ post.post.content | quote | markdown_to_html | replace({'\n':'<br />'}) | smiley | raw }}</td>
<td>{{ post.user.username }}</td>
<td>
{% if not post.processed %}
Expand All @@ -34,4 +34,4 @@
{% endfor %}
</tbody>

</table>
</table>
4 changes: 2 additions & 2 deletions Resources/views/Email/notification_new_message_en.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
</p>
<hr />
<p>
{{ post.content | quote | markdown | replace({'\n':'<br />'})| smiley | raw }}
{{ post.content | quote | markdown_to_html | replace({'\n':'<br />'})| smiley | raw }}
</p>
<p>
<a class="url" href="{{ path( 'workingforum_thread', {'forum': thread.subforum.forum.slug, 'subforum' : thread.subforum.slug, 'thread' : thread.slug}) }}">
Click here to see the thread
</a>
</p>
<p></p>
<p></p>
2 changes: 1 addition & 1 deletion Resources/views/Forum/rules.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{% if rules is not null %}
<p>{{ 'admin.rules.lang' | trans | capitalize }} : {{ rules.lang }}</p>
<p>{{ 'forum.switch_lang' | trans }} : {{ form_widget(form.langs) }}</p>
<p>{{ rules.content | markdown | smiley | raw }}</p>
<p>{{ rules.content | markdown_to_html | smiley | raw }}</p>
{% else %}
<p><em>{{ 'forum.no_rules_available' | trans }}</em></p>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Post/post.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
{# POST CONTENT #}
<div class="wf_post_content">
{% if post.moderateReason is empty %}
{{ post.content | quote | markdown | replace({'\n':'<br />'})| smiley | raw }}
{{ post.content | quote | markdown_to_html | replace({'\n':'<br />'})| smiley | raw }}
{% else %}
<p class="wf_moderate">{{ 'forum.post_moderated' | trans }} {{ post.moderateReason }}</p>
{% endif %}
Expand Down
21 changes: 10 additions & 11 deletions Tests/ParamConverter/GenericParamConverterTest.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php

namespace Yosimitso\WorkingForumBundle\Tests\ParamConverter;
namespace Yosimitso\WorkingForumBundle\Tests\ArgumentResolver;



use Doctrine\ORM\EntityManager;
use PHPUnit\Framework\TestCase;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Yosimitso\WorkingForumBundle\Entity\File;
use Yosimitso\WorkingForumBundle\Entity\Forum;
use Yosimitso\WorkingForumBundle\Entity\Post;
use Yosimitso\WorkingForumBundle\Entity\Subforum;
use Yosimitso\WorkingForumBundle\Entity\Thread;
use Yosimitso\WorkingForumBundle\ParamConverter\GenericParamConverter;
use Yosimitso\WorkingForumBundle\ArgumentResolver\GenericArgumentResolver;
use Yosimitso\WorkingForumBundle\Security\AuthorizationGuard;

class GenericParamConverterTest extends TestCase
class GenericArgumentResolverTest extends TestCase
{
public function getTestedClass($classname, $em = null, $authorization = null)
{
Expand All @@ -29,7 +28,7 @@ public function getTestedClass($classname, $em = null, $authorization = null)
}


return new GenericParamConverter(
return new GenericArgumentResolver(
$em,
$authorization,
$classname
Expand All @@ -39,7 +38,7 @@ public function getTestedClass($classname, $em = null, $authorization = null)
public function testSupportForum()
{
$testedClass = $this->getTestedClass(Forum::class);
$configuration = new ParamConverter([]);
$configuration = new ArgumentResolver([]);
$configuration->setClass(Forum::class);

$this->assertTrue($testedClass->supports($configuration));
Expand All @@ -48,7 +47,7 @@ public function testSupportForum()
public function testSupportSubForum()
{
$testedClass = $this->getTestedClass(Subforum::class);
$configuration = new ParamConverter([]);
$configuration = new ArgumentResolver([]);
$configuration->setClass(Subforum::class);

$this->assertTrue($testedClass->supports($configuration));
Expand All @@ -57,7 +56,7 @@ public function testSupportSubForum()
public function testSupportThread()
{
$testedClass = $this->getTestedClass(Thread::class);
$configuration = new ParamConverter([]);
$configuration = new ArgumentResolver([]);
$configuration->setClass(Thread::class);

$this->assertTrue($testedClass->supports($configuration));
Expand All @@ -66,7 +65,7 @@ public function testSupportThread()
public function testSupportPost()
{
$testedClass = $this->getTestedClass(Post::class);
$configuration = new ParamConverter([]);
$configuration = new ArgumentResolver([]);
$configuration->setClass(Post::class);

$this->assertTrue($testedClass->supports($configuration));
Expand All @@ -75,9 +74,9 @@ public function testSupportPost()
public function testNotSupportFile()
{
$testedClass = $this->getTestedClass(Forum::class);
$configuration = new ParamConverter([]);
$configuration = new ArgumentResolver([]);
$configuration->setClass(File::class);

$this->assertFalse($testedClass->supports($configuration));
}
}
}
5 changes: 0 additions & 5 deletions Tests/Scenario/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
* Class ThreadControllerTest
*
* @package Yosimitso\WorkingForumBundle\Tests\Controller
*/
class AdminController extends WebTestCase
{
private $client;
Expand Down
7 changes: 0 additions & 7 deletions Tests/Scenario/HttpResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@ public function setUp() : void
{
$client = static::createClient();
$container = static::$kernel->getContainer();
// $session = $container->get('request_stack')->getSession();
$person = self::$kernel->getContainer()->get('doctrine')->getRepository(UserTest::class)->findAll()[2];
$client->loginUser($person);
// $token = new UsernamePasswordToken($person, null, 'main', $person->getRoles());
// $session->set('_security_main', serialize($token));
// $session->save();
//
// $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId()));

$this->client = $client;
}
/**
Expand Down
1 change: 0 additions & 1 deletion Tests/Scenario/ThreadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class ThreadTest extends WebTestCase
use ReloadDatabaseTrait;
private $client;


private function getModeratorUserClient()
{
$client = static::createClient();
Expand Down
16 changes: 0 additions & 16 deletions Tests/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,4 @@ security:
pattern: ^/
provider: main
http_basic: ~
# form_login:
# login_path: login
# check_path: login_check
# csrf_token_generator: security.csrf.token_manager
# default_target_path: /
# logout:
# path: logout
# target: /

#sensio_framework_extra:
# router: { annotations: true }
# security: { annotations: true }


# Yosimitso\WorkingForumBundle\:
# resource: '../{Controller,Entity,Event,Form,ParamConverter,Repository,Security,Service,Twig,Util}'
# exclude: '../Entity/UserTest.php'
Loading