-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Add init command to generate configuration file (#1673)
Resolves: #1672
- Loading branch information
1 parent
cc20ad3
commit 6d55943
Showing
3 changed files
with
117 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Console\Command; | ||
|
||
use Rector\Core\Console\Command\AbstractCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symplify\PackageBuilder\Console\Command\CommandNaming; | ||
use Symplify\PackageBuilder\Console\ShellCode; | ||
use Symplify\SmartFileSystem\SmartFileSystem; | ||
|
||
final class Typo3InitCommand extends AbstractCommand | ||
{ | ||
/** | ||
* @var SmartFileSystem | ||
*/ | ||
private $smartFileSystem; | ||
|
||
/** | ||
* @var SymfonyStyle | ||
*/ | ||
private $symfonyStyle; | ||
|
||
public function __construct(SmartFileSystem $smartFileSystem, SymfonyStyle $symfonyStyle) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->smartFileSystem = $smartFileSystem; | ||
$this->symfonyStyle = $symfonyStyle; | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this->setName(CommandNaming::classToName(self::class)); | ||
$this->setDescription('Generate rector.php configuration file specific for TYPO3'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$rectorConfigFiles = $this->smartFileSystem->exists(getcwd() . '/rector.php'); | ||
|
||
if (! $rectorConfigFiles) { | ||
$this->smartFileSystem->copy(__DIR__ . '/../../../templates/rector.php.dist', getcwd() . '/rector.php'); | ||
$this->symfonyStyle->success('"rector.php" config file has been generated successfully!'); | ||
} else { | ||
$this->symfonyStyle->error('Config file not generated. A "rector.php" configuration file already exists'); | ||
} | ||
|
||
return ShellCode::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Core\Configuration\Option; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
use Ssch\TYPO3Rector\Set; | ||
use Ssch\TYPO3Rector\Rector\v9\v0\InjectAnnotationRector; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
// get parameters | ||
$parameters = $containerConfigurator->parameters(); | ||
|
||
// Define what rule sets will be applied | ||
$parameters->set(Option::SETS, [ | ||
Typo3SetList::TYPO3_95, | ||
]); | ||
|
||
// FQN classes are not imported by default. If you don't do it manually after every Rector run, enable it by: | ||
$parameters->set(Option::AUTO_IMPORT_NAMES, true); | ||
|
||
// this will not import root namespace classes, like \DateTime or \Exception | ||
$parameters->set(Option::IMPORT_SHORT_CLASSES, false); | ||
|
||
// this will not import classes used in PHP DocBlocks, like in /** @var \Some\Class */ | ||
$parameters->set(Option::IMPORT_DOC_BLOCKS, false); | ||
|
||
// Define your target version which you want to support | ||
$parameters->set(Option::PHP_VERSION_FEATURES, '7.2'); | ||
|
||
// If you set option Option::AUTO_IMPORT_NAMES to true, you should consider excluding some TYPO3 files. | ||
$parameters->set(Option::EXCLUDE_PATHS, [ | ||
'ClassAliasMap.php', | ||
'class.ext_update.php', | ||
'ext_localconf.php', | ||
'ext_emconf.php', | ||
'ext_tables.php', | ||
__DIR__ . '/packages/my_package/Configuration/*' | ||
]); | ||
|
||
// If you have trouble that rector cannot run because some TYPO3 constants are not defined add an additional constants file | ||
// Have a look at https://github.com/sabbelasichon/typo3-rector/typo3.constants.php | ||
$parameters->set(Option::AUTOLOAD_PATHS, [ | ||
__DIR__ . '/typo3.constants.php' | ||
]); | ||
|
||
// get services (needed for register a single rule) | ||
// $services = $containerConfigurator->services(); | ||
|
||
// register a single rule | ||
// $services->set(InjectAnnotationRector::class); | ||
}; |