Use the autoloader from where Rector was installed, not started#5772
Use the autoloader from where Rector was installed, not started#5772TomasVotruba merged 3 commits intorectorphp:masterfrom
Conversation
bin/rector.php
Outdated
|
|
||
| $autoloadIncluder->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/scoper-autoload.php'); | ||
| $autoloadIncluder->loadIfExistsAndNotLoadedYet(getcwd() . '/vendor/autoload.php'); | ||
| $autoloadIncluder->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/autoload.php'); |
There was a problem hiding this comment.
I think add new call is safer instead of change existing value:
| $autoloadIncluder->loadIfExistsAndNotLoadedYet(getcwd() . '/vendor/autoload.php'); | |
| $autoloadIncluder->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/autoload.php'); | |
| $autoloadIncluder->loadIfExistsAndNotLoadedYet(getcwd() . '/vendor/autoload.php'); | |
| $autoloadIncluder->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/autoload.php'); |
There was a problem hiding this comment.
No, I think we have to remove the cwd()-based one.
There was a problem hiding this comment.
that will broke when using composer require --dev rector/rector:dev-patch-1 with pointed to your repository. I tried your PR branch, and it got error:
vendor/bin/rector process app
PHP Fatal error: Uncaught Error: Class "Rector\Core\Console\Style\SymfonyStyleFactory" not found in /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/bin/rector.php:35
Stack trace:
#0 /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/bin/rector(4): require_once()
#1 {main}
thrown in /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/bin/rector.php on line 35
Fatal error: Uncaught Error: Class "Rector\Core\Console\Style\SymfonyStyleFactory" not found in /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/bin/rector.php:35
Stack trace:
#0 /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/bin/rector(4): require_once()
#1 {main}
thrown in /Users/samsonasik/www/CodeIgniter4/vendor/rector/rector/bin/rector.php on line 35with the following composer.json config:
"require-dev": {
"rector/rector": "dev-patch-1"
},
"repositories" : [
{
"type" : "vcs",
"url" : "https://github.com/mpdude/rector",
"no-api": true
}
]Keep old method call will keep it working.
There was a problem hiding this comment.
Oh, I see... in Composer-based setups, it would have to be __DIR__.'/../../vendor/autoload.php probably?
There was a problem hiding this comment.
@samsonasik Does it work if you completely remove the line in question here? So both ones, with cwd() and __DIR__?
There was a problem hiding this comment.
Not ../../../? (see the latest commit I just pushed)
There was a problem hiding this comment.
Not sure about https://github.com/rectorphp/rector/blob/master/src/Stubs/PHPStanStubLoader.php#L18-L23, but maybe that needs a bit of scrutinity, too...
There was a problem hiding this comment.
__DIR__ . '/../../../../vendor/autoload.php' is same with __DIR__ . '/../../../autoload.php'. Just add more "up" to ensure the parent is named "vendor"
There was a problem hiding this comment.
Does my latest commit work?
…ncyOrRepositoryVendorAutoloadIfExists()
When Rector is installed as a project dependency through composer,
this script it will be in {vendor}/rector/rectory/bin/rector.php,
so ../../.. is where autoload.php lives.
|
Thank you both 👍 |
#5665 should allow Rector to work without autoloading code from the project that's analyzed. Since I knew about the conflicts between Rector and older Symfony versions, and since I happen to have an older project with Symfony 2.3 around here, I tried to run a Rector Docker image with the changes from #5665 on in.
It fails with
So, proably some mess-up between my project's version of Symfony and the one included in Rector.
I then modified
vendor/autoload.phpin my project to throw an exception:bin/rectorincludes my project's autoloader? That's becausebin/rector.phploadsvendor/autoload.phpfrom the current cwd. At least in the Docker image, that's the project directory, not the/rectorone.Thus, I think it would make more sense to use
__DIR__. That would always be the autoloader from where Rector was installed, not where it is running.