Comments (10)
@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.
from rector-symfony.
I will be pleased to test it live and report back, will check the next release :)
thank you @TomasVotruba
from rector-symfony.
Hi, could you share before and after example?
from rector-symfony.
Hi thanks for reply
Yes I ll post back soon :)
from rector-symfony.
@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.
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.
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.
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.
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)
- Bug on AnnotationToAttribute ? HOT 4
- RouteCollectionBuilderToRoutingConfiguratorRector should not rename `confifgureRoutes` to `configureRouting` HOT 9
- WebTestCaseAssertResponseCodeRector && WebTestCaseAssertIsSuccessfulRector does not handle methods that don't use self::createClient HOT 2
- How I am supossed to use this package? HOT 2
- ActionSuffixRemoverRector should not replace getAction to get HOT 4
- trying to run AddRouteAnnotationRector throws BindingResolutionException HOT 17
- Error when running AddRouteAnnotationRector HOT 5
- MakeCommandLazy rule is broken
- Overzealous StringToArrayArgumentProcessRector conversion HOT 2
- MessageHandlerInterfaceToAttributeRector False positive HOT 19
- Symfony 7 rector rule collection HOT 8
- .
- Can't make yaml routing to annotation/attribute rule work HOT 4
- [Downgrade] New rule to handle attribute Symfony Command to Symfony HOT 6
- [PHP 8.0] Add swagger attribute set HOT 1
- Update readme with RectorConfigBuilder HOT 8
- The rector rule for TranslatorInterface does not take into account possible null parameter HOT 1
- Symfony Console: Migrate `configure` to `AsCommand` HOT 6
- Updated for rector 1+ HOT 2
- Bug: ContainerGetToConstructorInjectionRector replaces constant with object HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rector-symfony.