mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
possible solution for global execution (#1692)
* possible solution for global execution Ref https://github.com/rectorphp/rector/issues/6945 * try with no constant no getcwd(), direct vendor/autoload.php * doc clean up for -a vendor/autoload as included in bin/rector.php * try with is_dir() vendor/rector/rector without contant or getcwd() * check with realpath * check is_dir parent .. * loop up parent compare * ensure not dir * final touch: move check global to separate method
This commit is contained in:
parent
71719b5e05
commit
e5ed2372b9
|
@ -38,6 +38,7 @@ require_once __DIR__ . '/../src/constants.php';
|
|||
|
||||
$autoloadIncluder->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/scoper-autoload.php');
|
||||
$autoloadIncluder->autoloadProjectAutoloaderFile();
|
||||
$autoloadIncluder->autoloadRectorInstalledAsGlobalDependency();
|
||||
$autoloadIncluder->autoloadFromCommandLine();
|
||||
|
||||
$rectorConfigsResolver = new RectorConfigsResolver();
|
||||
|
@ -97,6 +98,22 @@ final class AutoloadIncluder
|
|||
$this->loadIfExistsAndNotLoadedYet(__DIR__ . '/../../../autoload.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* In case Rector is installed as global dependency
|
||||
*/
|
||||
public function autoloadRectorInstalledAsGlobalDependency(): void
|
||||
{
|
||||
if (dirname(__DIR__) === dirname(getcwd(), 2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_dir('vendor/rector/rector')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->loadIfExistsAndNotLoadedYet('vendor/autoload.php');
|
||||
}
|
||||
|
||||
public function autoloadFromCommandLine(): void
|
||||
{
|
||||
$cliArgs = $_SERVER['argv'];
|
||||
|
|
|
@ -83,7 +83,6 @@ In this case you may want to try one of the following solutions:
|
|||
|
||||
### Register to `Option::AUTOLOAD_PATHS`:
|
||||
|
||||
|
||||
```php
|
||||
$parameters->set(Option::AUTOLOAD_PATHS, [
|
||||
// the path to the exact class file
|
||||
|
@ -95,15 +94,7 @@ In this case you may want to try one of the following solutions:
|
|||
]);
|
||||
```
|
||||
|
||||
### Call command with `-a` option
|
||||
|
||||
This may happen when you're using rector globally (not recommended as autoload may overlapped)
|
||||
|
||||
```bash
|
||||
rector process -a vendor/autoload.php
|
||||
```
|
||||
|
||||
### Other solution is by register the path of the class to composer.json's `"files"` config, eg:
|
||||
### Register the path of the class to composer.json's `"files"` config, eg:
|
||||
|
||||
```javascript
|
||||
"autoload-dev": {
|
||||
|
|
Loading…
Reference in New Issue
Block a user