Comments (14)
OK, I made https://github.com/Bilge/rector-fail.
from rector-symfony.
I've tried the repository and after linking the XML via SYMFONY_CONTAINER_XML_PATH_PARAMETER
:
// rector.php
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Symfony\Set\SymfonySetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
__DIR__ . '/src'
]);
// path to dumped service container - run the project at least once to build container services map
$parameters->set(Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER,
__DIR__ . '/var/cache/dev/OrgOrg_KernelDevDebugContainer.xml');
$containerConfigurator->import(SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION);
};
...it works as expected 👍
See https://github.com/rectorphp/rector-symfony#use-sets
Could you complete your example? What effect has it on the result?
I do not have an access, otherwise I'd send PR to your repository.
from rector-symfony.
Yes, that does seem to work.
class DefaultController extends Controller
{
+ public function __construct(private \Org\Service\MyRegularService $myRegularService, private \Org\FirstBundle\Service\MyBundleService $myBundleService)
+ {
+ }
public function indexAction()
{
- $regularService = $this->get('my.regular.service');
- $bundleService = $this->get('my.bundle.service');
- $regularServiceAsClassName = $this->get(MyRegularService::class);
+ $regularService = $this->myRegularService;
+ $bundleService = $this->myBundleService;
+ $regularServiceAsClassName = $this->myRegularService;
return $this->render('FirstBundle:Default:index.html.twig');
}
It's weird that that has always been in the readme. It does not really draw attention to itself there.
from rector-symfony.
Hi, thanks for this question.
Could you provide minimalistic diff of what exactly you have in mind? Just to be sure we understand your request correctly.
from rector-symfony.
<!-- services.xml -->
<service id="my.service" class="My\MyService">
<argument type="service" id="My\OtherService" />
</service>
+use My\MyService;
class Foo extends Controller
{
function bar()
{
- $this->get('my.service');
+ $this->get(MyService::class);
}
}
Thereafter, the existing SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION
Rector set could take over and do its job of refactoring the DI service grab into constructor injection, now that the service class name is used instead of the "machine name".
Note that this would not be possible in the case where two different service definitions are declared for the same class name. In this rare case, probably the fixer should do nothing and defer to manual intervention. If it was super smart, it could perhaps create a ServiceLocator
or something, but that's out of scope here.
from rector-symfony.
Thanks for reporting. Looking at rules in linked set, this should be supported. I'm doing a bit cleanup of the rules just to be sure.
I'll need reproducible repository to verify where bug is. Could you share opened repository in Github? Ideally with single class and minimal composer.json
. It will speed up th efix.
from rector-symfony.
What do you mean by, where bug is? There is no bug here. Either the feature exists or it doesn't. If it doesn't then this can be treated as a feature request. That is, unless you mean SYMFONY_CONSTRUCTOR_INJECTION
is supposed to work for more than just services whose definition name matches the class name?
from rector-symfony.
The feature exists and should work.
from rector-symfony.
I see. Is it likely to not work when the service definitions are in XML format and/or in many separate bundles? In old versions of Symfony, it was recommended that even all first-party code be placed inside bundles, and indeed is this case in this project, though those bundles are in the same repository and in the same directory structure as everything else, so it shouldn't matter too much...
from rector-symfony.
It works for specifically located xml
config at the moment. That should be easy to implement 😉
Could you send the minimal repository with such example?
from rector-symfony.
Thank you, I'll look into it 👍
from rector-symfony.
That's issue with readmes. It's full of details that only one person needs :)
I'd be happy if you could send update of README.md
that would help you next person in the situation 👍
from rector-symfony.
I was thinking of a few different options.
- Maybe a note next to the relevant fixer(s) or set(s) reminding to set the configuration option for those fixers that need it.
- Maybe a notice/warning generated by Rector itself if a fixer is used that requires the option but it is missing.
from rector-symfony.
Maybe a notice/warning generated by Rector itself if a fixer is used that requires the option but it is missing.
This would be awesome 👍
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.