Source of file UpperCaseFolderNamesForPSR4.php
Size: 2,444 Bytes - Last Modified: 2020-07-03T12:08:09+00:00
/var/www/docs.ssmods.com/process/src/src/Tasks/IndividualTasks/UpperCaseFolderNamesForPSR4.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | <?php namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; use Sunnysideup\UpgradeToSilverstripe4\Api\FileSystemFixes; use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; /** * Fixes the folder name cases in to make them PSR4 compatible * e.g. * yourmodule/src/model becomes yourmodule/src/Model */ class UpperCaseFolderNamesForPSR4 extends Task { protected $taskStep = 's30'; protected $nameReplacements = [ 'interface' => 'Interfaces', ]; public function getTitle() { return 'Fix Folder Case'; } public function getDescription() { return ' Change your src/code folders from lowercase to TitleCase - e.g. yourmodule/src/model becomes yourmodule/src/Model in accordance with PSR-4 autoloading'; } public function setNameReplacements($a) { $this->nameReplacements = $a; } public function runActualTask($params = []) { foreach ($this->mu()->findNameSpaceAndCodeDirs() as $codeDir) { $di = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($codeDir, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST ); //For all directories foreach ($di as $name => $fio) { if ($fio->isDir()) { //If its a directory then $newName = $fio->getPath() . DIRECTORY_SEPARATOR . $this->mu()->cleanCamelCase($fio->getFilename()); foreach ($this->nameReplacements as $from => $to) { if ($from === $name) { $newName = $to; } } if ($name === $newName) { $this->mu()->colourPrint('No need to move ' . str_replace($codeDir, '', $name) . ' as it is already in CamelCase', 'dark_gray'); } else { $this->mu()->colourPrint('New name for directory: ' . $newName, 'green'); $fixer = FileSystemFixes::inst($this->mu()); $fixer->moveFolderOrFile($name, $newName); } //rename($name, $newname); - first check the output, then remove the comment... } } } } protected function hasCommitAndPush() { return true; } } |