Git Product home page Git Product logo

Comments (10)

94noni avatar 94noni commented on September 27, 2024 1

@TomasVotruba, for the latest part, kind of similar to the entity manager interface but for the messenger bus:

// src/Controller/SomeController.php

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+ use Symfony\Component\Messenger\MessageBusInterface;

 class SomeController extends AbstractController 
 {
-    public function index()
+    public function index(MessageBusInterface $bus)
     {
-        $this->dispatchMessage(...);
+        $bus->dispatch(...);
     }
 }

$bus is total arbitrary name, can be $messageBus or whatever


yes I need to improve this "old" code behavior split with more new logic/practice of coding

But I am new to rector I am testing step by step ;) and so far so good, this tool is a must have thank you so much

from rector-symfony.

TomasVotruba avatar TomasVotruba commented on September 27, 2024 1

Fixed in #97 ad #99

from rector-symfony.

94noni avatar 94noni commented on September 27, 2024 1

I will be pleased to test it live and report back, will check the next release :)
thank you @TomasVotruba

from rector-symfony.

TomasVotruba avatar TomasVotruba commented on September 27, 2024

Hi, could you share before and after example?

from rector-symfony.

94noni avatar 94noni commented on September 27, 2024

Hi thanks for reply
Yes I ll post back soon :)

from rector-symfony.

94noni avatar 94noni commented on September 27, 2024

@TomasVotruba here you are:

// src/Controller/SomeController.php

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+ use Doctrine\ORM\EntityManagerInterface;

 class SomeController extends AbstractController 
 {
-    public function index()
+    public function index(EntityManagerInterface $em)
     {
-         $em = $this->getDoctrine()->getManager();
           $em->getRepository(...);
     }
 }

$em injected because the var was named $em in the controller's action code

from rector-symfony.

TomasVotruba avatar TomasVotruba commented on September 27, 2024

The constructor injection would be better, but I get the idea. Thanks 👍

That's all methods or is there any other diff you can give me?

from rector-symfony.

94noni avatar 94noni commented on September 27, 2024

I've written example of controller action injection as this project is an evolution of an old symfony v2 app to v3,4,5 now 6
so old controller with lot of actions methods

On some new controllers, I prefer one invoke action with constructor injection that is why I showed an exemple of action injection, as I know rector can already do constructor injection

of course it could have already some arguments in the function so the EntityManagerInterface should be added after

for what I can read, there is also the dispatchMessage() of the same class from symfony :)

from rector-symfony.

TomasVotruba avatar TomasVotruba commented on September 27, 2024

so old controller with lot of actions methods

It might be handy to split such god class with custom simple Rector rule 👍

On some new controllers, I prefer one invoke action with constructor injection that is why I showed an exemple of action injection, as I know rector can already do constructor injection

The thing is, we have internal services for adding dependencies to constructor. We can re-use those easily. For any other modification, you can add custom rule to move your dependencies to places of need.

for what I can read, there is also the dispatchMessage() of the same class from symfony :)

Could you share diff for that one?

from rector-symfony.

TomasVotruba avatar TomasVotruba commented on September 27, 2024

But I am new to rector I am testing step by step ;) and so far so good, this tool is a must have thank you so much

That's the best approach. Start slowly then build up every day step by step :) thank you for positive feedback 👍


I'm looking into it... related pull-requests:

from rector-symfony.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.