Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Use ADR pattern #457

Merged
merged 1 commit into from
Jun 19, 2018
Merged

Use ADR pattern #457

merged 1 commit into from
Jun 19, 2018

Conversation

core23
Copy link
Member

@core23 core23 commented Jun 16, 2018

I am targeting this branch, because this is BC.

Changelog

### Changed
- `Controller\PostController` is now deprecated in favor of `Action\*Action`

Todo

  • add NEXT_MAJOR comments
  • move to Action namespace
  • test this on an actual project

Subject

Using invokable CaaSes vs one big controller achieves several things:

  1. it discourages piling on more actions in controllers with vague names (SRP)
  2. it leads to easier to unit test actions and visible deps (DIP)
  3. it will allow us to make more services private

Refs sonata-project/SonataAdminBundle#5120

@core23
Copy link
Member Author

core23 commented Jun 16, 2018

Not sure how to handle getCommentForm. This method is used accross several actions. Should I create an abstract action or should we duplicate this piece of code.

Copy link
Contributor

@kunicmarko20 kunicmarko20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, love this change to Actions 👍

*/
private $collectionManager;

public function __construct(BlogInterface $blog, PostManagerInterface $postManager, CollectionManagerInterface $collectionManager)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is over 120 chars, can you make it multiline.

use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

class ModerateCommentAction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

public function __invoke(Request $request, $year, $month)
{
return $this->renderArchive($request, [
'date' => $this->getPostManager()->getPublicationDateQueryParts(sprintf('%d-%d-%d', $year, $month, 1), 'month'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

over 120 chars

'route_parameters' => $request->get('_route_params'),
], $parameters);

$response = $this->render(sprintf('@SonataNews/Post/archive.%s.twig', $request->getRequestFormat()), $parameters);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is over 120 chars

/**
* @param null|SeoPageInterface $seoPage
*/
public function setSeoPage(SeoPageInterface $seoPage = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? (It will be replaced with Trait?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -39,6 +39,7 @@ public function load(array $configs, ContainerBuilder $container)
$bundles = $container->getParameter('kernel.bundles');

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('actions.xml');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything is singular, this one is plural 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already had this discussion:
sonata-project/SonataAdminBundle#5120 (comment)

Would prefer singular too, but symfony is mainly using plural for this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, we should rename others then

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to do this :trollface:

private $postManager;

/**
* AbstractPostArchiveAction constructor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed?

* AbstractPostArchiveAction constructor.
*
* @param BlogInterface $blog
* @param PostManagerInterface $postManager
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed too IMO, and I thought you were against removing it but now I see you did not put it on some methods below.

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\RouterInterface;

final class HomeAction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greg0ire
Copy link
Contributor

This is so much cleaner! I was going to ask you to split the test , but I realise there is none :P

@core23 core23 force-pushed the feature/adr branch 2 times, most recently from 007f33f to 142d1b9 Compare June 17, 2018 06:04
'route_parameters' => $request->get('_route_params'),
], $parameters);

$response = $this->render(
Copy link
Contributor

@greg0ire greg0ire Jun 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@covex-nn , apparently you're doing a series of PR to decouple from the templating component, I didn't realise that when I made my PR. Maybe we could entirely skip the extends Controller and use $response->setContent($this->twig->render($view, $parameters)) ? Or is it wrong/to soon? See https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php#L224

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greg0ire PR about controller actions and PR about decoupling from templating are not related to each other (my PR was about using templating service inside blocks). So, i think, if you would inject twig into controller action, it will work. But, may be some other actions use other Controller/ControllerTrait features?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe yeah, but there's probably not that many, and if it can spare us from injecting the whole container, then it might be good. I might try it on the new actions I created but technically it will be a BC-break.

@core23
Copy link
Member Author

core23 commented Jun 19, 2018

Anything to do here? @greg0ire @covex-nn @kunicmarko20

@greg0ire
Copy link
Contributor

Anything to do here? @greg0ire @covex-nn @kunicmarko20

Experimenting with the Twig injection if you feel like it. Should work, even for 2.8


return $response;
return $action->renderArchive($this->resolveRequest($request), $criteria, $parameters);
Copy link
Contributor

@covex-nn covex-nn Jun 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@core23
Copy link
Member Author

core23 commented Jun 19, 2018

Experimenting with the Twig injection if you feel like it. Should work, even for 2.8

This is hard / impossible in a BC way. So I will do this on the master branch afterwards

@greg0ire greg0ire merged commit 05c76d9 into sonata-project:3.x Jun 19, 2018
@greg0ire
Copy link
Contributor

Thanks @core23 !

@core23 core23 deleted the feature/adr branch June 20, 2018 05:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants