Skip to content

Commit 7b344ff

Browse files
Fixed paths
1 parent 8ebe076 commit 7b344ff

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

src/Processors/Install.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected function create(): void
3535
protected function ensureDirectory(): void
3636
{
3737
Directory::ensureDirectory(
38-
$this->getActionsPath()
38+
$this->getActionsPath(realpath: $this->options->realpath)
3939
);
4040
}
4141
}

src/Processors/Make.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function handle(): void
2222
protected function run(): void
2323
{
2424
$name = $this->getName();
25-
$path = $this->getActionsPath($name);
25+
$path = $this->getActionsPath($name, realpath: $this->options->realpath);
2626

2727
$this->create($path);
2828
}

src/Processors/Processor.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ public function __construct(
4141
$this->migrator->setConnection($this->options->connection)->setOutput($this->output);
4242
}
4343

44-
protected function getFiles(?Closure $filter = null, ?string $path = null): array
44+
protected function getFiles(?Closure $filter = null, ?string $path = null, bool $realpath = false): array
4545
{
46-
$path = $this->getActionsPath($path);
46+
$path = $this->getActionsPath($path, $realpath);
4747

48-
return $this->file->exists($path) ? [$path] : $this->file->allPaths($path, $filter, true);
48+
return $this->file->exists($path) ? [$path] : $this->file->names($path, $filter, true);
4949
}
5050

51-
protected function getActionsPath(?string $path = null): string
51+
protected function getActionsPath(?string $path = null, bool $realpath = false): string
5252
{
53-
$path = $this->options->realpath ? $path : $this->config->path($path);
53+
$path = $realpath ? $path : $this->config->path($path);
5454

5555
if (! is_dir($path) && ! Str::endsWith($path, '.php')) {
5656
return $this->file->exists($path . '.php') ? $path . '.php' : $path;

src/Processors/Rollback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function getActions(?int $step): array
5151
protected function rollbackAction(string $action): void
5252
{
5353
$this->migrator->runDown(
54-
$this->getActionsPath($action)
54+
$this->getActionsPath($action, realpath: $this->options->realpath)
5555
);
5656
}
5757

src/Processors/Upgrade.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ protected function move(string $filename): void
4545
$content = $this->replaceClassName($content);
4646
$content = $this->replaceDeclareStrictType($content);
4747
$content = $this->replaceWithInvoke($content);
48+
$content = $this->replaceProperties($content);
4849

4950
$this->store($filename, $content);
50-
$this->delete($filename);
5151
}
5252

5353
protected function clean(): void
@@ -57,19 +57,19 @@ protected function clean(): void
5757
));
5858
}
5959

60-
protected function open(string $path): string
60+
protected function open(string $filename): string
6161
{
62-
return file_get_contents(base_path('database/actions/' . $path));
62+
return file_get_contents(base_path('database/actions/' . $filename));
6363
}
6464

65-
protected function store(string $path, string $content): void
65+
protected function store(string $filename, string $content): void
6666
{
67-
file_put_contents($this->config->path($path), $content);
67+
File::store($this->config->path($filename), $content);
6868
}
6969

70-
protected function delete(string $path): void
70+
protected function delete(string $filename): void
7171
{
72-
File::ensureDelete($this->config->path($path));
72+
File::ensureDelete($filename);
7373
}
7474

7575
protected function replaceNamespace(string $content): string
@@ -83,8 +83,9 @@ protected function replaceNamespace(string $content): string
8383
protected function replaceClassName(string $content): string
8484
{
8585
return Str::of($content)
86-
->pregReplace('/^([final\s|class]+.+extends\sAction)$/', 'return new class () extends Action')
86+
->pregReplace('/((?:return\s+new\s+class\s*\(?\s*\)?|final\s+class|class)\s*.+extends\s+Action)/', 'return new class () extends Action')
8787
->trim()
88+
->trim(';')
8889
->append(';')
8990
->append(PHP_EOL)
9091
->toString();
@@ -106,6 +107,18 @@ protected function replaceWithInvoke(string $content): string
106107
})->toString();
107108
}
108109

110+
protected function replaceProperties(string $content): string
111+
{
112+
return Str::of($content)
113+
->pregReplace('/protected\s+\$once/', 'protected bool $once')
114+
->pregReplace('/protected\s+\$transactions/', 'protected bool $transactions')
115+
->pregReplace('/protected\s+\$transaction_attempts/', 'protected int $transactionAttempts')
116+
->pregReplace('/protected\s+\$environment/', 'protected string|array|null $environment')
117+
->pregReplace('/protected\s+\$except_environment/', 'protected string|array|null $exceptEnvironment')
118+
->pregReplace('/protected\s+\$before/', 'protected bool $before')
119+
->toString();
120+
}
121+
109122
protected function moveConfig(): void
110123
{
111124
$this->notification->task('Moving config file', function () {
@@ -126,7 +139,7 @@ protected function moveConfig(): void
126139

127140
protected function getOldFiles(): array
128141
{
129-
return $this->getFiles(path: database_path('actions'));
142+
return $this->getFiles(path: database_path('actions'), realpath: true);
130143
}
131144

132145
protected function alreadyUpgraded(): bool

0 commit comments

Comments
 (0)