|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
|
4
|
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Api\FileSystemFixes; |
|
6
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Fixes the folder name cases in to make them PSR4 compatible |
|
10
|
|
|
* e.g. |
|
11
|
|
|
* yourmodule/src/model becomes yourmodule/src/Model |
|
12
|
|
|
*/ |
|
13
|
|
|
class UpperCaseFolderNamesForPSR4 extends Task |
|
14
|
|
|
{ |
|
15
|
|
|
protected $taskStep = 's30'; |
|
16
|
|
|
|
|
17
|
|
|
protected $nameReplacements = [ |
|
18
|
|
|
'interface' => 'Interfaces', |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
public function getTitle() |
|
22
|
|
|
{ |
|
23
|
|
|
return 'Fix Folder Case'; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function getDescription() |
|
27
|
|
|
{ |
|
28
|
|
|
return ' |
|
29
|
|
|
Change your src/code folders from lowercase to TitleCase - e.g. |
|
30
|
|
|
yourmodule/src/model becomes yourmodule/src/Model in accordance with PSR-4 autoloading'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function setNameReplacements($a) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->nameReplacements = $a; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function runActualTask($params = []): ?string |
|
39
|
|
|
{ |
|
40
|
|
|
foreach ($this->mu()->findNameSpaceAndCodeDirs() as $codeDir) { |
|
|
|
|
|
|
41
|
|
|
$di = new \RecursiveIteratorIterator( |
|
42
|
|
|
new \RecursiveDirectoryIterator($codeDir, \FilesystemIterator::SKIP_DOTS), |
|
43
|
|
|
\RecursiveIteratorIterator::CHILD_FIRST |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
//For all directories |
|
47
|
|
|
foreach ($di as $name => $fio) { |
|
48
|
|
|
if ($fio->isDir()) { |
|
49
|
|
|
//If its a directory then |
|
50
|
|
|
$newName = $fio->getPath() . DIRECTORY_SEPARATOR . $this->mu()->cleanCamelCase($fio->getFilename()); |
|
|
|
|
|
|
51
|
|
|
foreach ($this->nameReplacements as $from => $to) { |
|
52
|
|
|
if ($from === $name) { |
|
53
|
|
|
$newName = $to; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
if ($name === $newName) { |
|
57
|
|
|
$this->mu()->colourPrint('No need to move ' . str_replace($codeDir, '', $name) . ' as it is already in CamelCase', 'dark_gray'); |
|
|
|
|
|
|
58
|
|
|
} else { |
|
59
|
|
|
$this->mu()->colourPrint('New name for directory: ' . $newName, 'green'); |
|
60
|
|
|
$fixer = FileSystemFixes::inst($this->mu()); |
|
61
|
|
|
$fixer->moveFolderOrFile($name, $newName); |
|
62
|
|
|
} |
|
63
|
|
|
//rename($name, $newname); - first check the output, then remove the comment... |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
return null; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function hasCommitAndPush() |
|
71
|
|
|
{ |
|
72
|
|
|
return true; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|