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

Make CoreController actions CaaSes #5120

Merged
merged 1 commit into from
Jun 13, 2018

Conversation

greg0ire
Copy link
Contributor

@greg0ire greg0ire commented Jun 9, 2018

I am targeting this branch, because this is BC.

Changelog

### Changed
- `Controller\CoreController` is now deprecated in favor of `Action\{Search,Dasbhoard}Action`

Todo

  • unit test search action
  • add NEXT_MAJOR comments
  • move to Action namespace
  • fix the build
  • rebase on Apply new CS fixer rules #5122
  • 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

*/
public function __invoke(Request $request)
{
if ($request->get('admin') && $request->isXmlHttpRequest()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about inversing if and putting the default return instead of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just did this, good call :)

@@ -378,7 +378,7 @@ public function fixTemplates(

// set template for simple pager if it is not already overwritten
if ('setPagerType' === $method[0]
&& $method[1][0] === Pager::TYPE_SIMPLE
&& Pager::TYPE_SIMPLE === $method[1][0]
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 in scope of this PR?

Copy link
Contributor Author

@greg0ire greg0ire Jun 10, 2018

Choose a reason for hiding this comment

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

The build will not pass otherwise.

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 idea, I love it!

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

final class DashboardAction extends Controller
Copy link
Member

Choose a reason for hiding this comment

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

Why do you extend the symfony Controller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For one thing and one thing only: the render method. I looked at it, it is fairly complicated because it looks for the templating component, and for twig. Not sure if I could safely get rid of it.

* file that was distributed with this source code.
*/

namespace Sonata\AdminBundle\Controller;
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker, but I would prefer the ..\Action namespace for actions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then maybe also change the name of service file to actions?

@core23 core23 added minor and removed pedantic labels Jun 10, 2018
@greg0ire
Copy link
Contributor Author

@core23 why did you relabel it to minor?

I'm going to make another PR for cs.

@greg0ire
Copy link
Contributor Author

@core23 why did you relabel it to minor?

Ah I know, that's because of the deprecations, forgot that rule 👍

@greg0ire greg0ire force-pushed the invokable_caas branch 8 times, most recently from cfe7999 to 09bc8db Compare June 10, 2018 12:34
@greg0ire greg0ire changed the title WIP: Make CoreController actions CaaSes Make CoreController actions CaaSes Jun 10, 2018
@core23
Copy link
Member

core23 commented Jun 10, 2018

Ah I know, that's because of the deprecations, forgot that rule 👍

That's one reason. You also introduce new stuff (the action classes), so it's a minor.

@greg0ire
Copy link
Contributor Author

I introduce new classes, but I introduce no new features I think :P

@greg0ire
Copy link
Contributor Author

Made Codacy happy :)

@@ -141,6 +141,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('block.xml');
$loader->load('menu.xml');
$loader->load('commands.xml');
$loader->load('actions.xml');
Copy link
Member

Choose a reason for hiding this comment

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

action.xml

Copy link
Contributor Author

@greg0ire greg0ire Jun 11, 2018

Choose a reason for hiding this comment

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

Why use singular? We use commands and services

Copy link
Member

Choose a reason for hiding this comment

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

What about block and menu?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe those are faulty, or maybe there is an unspoken rule about when to use singular and when to use plural, all I know is that in Symfony, you have services.yaml. Either way, fixing this is out of scope of this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Symfony is refering to a services.yaml:
https://symfony.com/doc/current/service_container.html#service-container-services-load-example

So we should use plurals 👍

core23
core23 previously approved these changes Jun 11, 2018
@greg0ire
Copy link
Contributor Author

Finally managed to test it on a very old project, it doesn't work :P

@greg0ire greg0ire force-pushed the invokable_caas branch 2 times, most recently from 1890f0e to 71cfddd Compare June 11, 2018 18:44
@greg0ire
Copy link
Contributor Author

Ready for review :)

@greg0ire greg0ire requested a review from a team June 11, 2018 19:33
@greg0ire greg0ire requested a review from a team June 13, 2018 06:08
@greg0ire greg0ire requested a review from a team June 13, 2018 12:03
@greg0ire greg0ire requested a review from a team June 13, 2018 13:38
@greg0ire
Copy link
Contributor Author

greg0ire requested a review (and also, a merge would be nice) from sonata-project/contributors 2 minutes ago

@covex-nn covex-nn merged commit cd74a2d into sonata-project:3.x Jun 13, 2018
@covex-nn
Copy link
Contributor

Thank you, @greg0ire =)

@greg0ire greg0ire deleted the invokable_caas branch June 13, 2018 14:27
@greg0ire
Copy link
Contributor Author

@greg0ire is happy :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants