-
-
Notifications
You must be signed in to change notification settings - Fork 624
Expand file tree
/
Copy pathInteractsWithFilesystem.php
More file actions
63 lines (48 loc) · 1.55 KB
/
InteractsWithFilesystem.php
File metadata and controls
63 lines (48 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Statamic\StarterKits\Concerns;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Statamic\Console\NullConsole;
use Statamic\Facades\Path;
trait InteractsWithFilesystem
{
/**
* Install starter kit file.
*/
protected function installFile(string $fromPath, string $toPath, Command|NullConsole $console): self
{
$displayPath = str_replace(Path::tidy(base_path().'/'), '', $toPath);
$console->line("Installing file [{$displayPath}]");
app(Filesystem::class)->copy($fromPath, $this->preparePath($toPath));
return $this;
}
/**
* Export relative path to starter kit.
*/
protected function exportRelativePath(string $starterKitPath, string $from, ?string $to = null): void
{
$to = $to
? "{$starterKitPath}/{$to}"
: "{$starterKitPath}/{$from}";
$from = base_path($from);
$this->preparePath($to);
$files = app(Filesystem::class);
$files->isDirectory($from)
? $files->copyDirectory($from, $to)
: $files->copy($from, $to);
}
/**
* Prepare path directory.
*/
protected function preparePath(string $path): string
{
$files = app(Filesystem::class);
$directory = $files->isDirectory($path)
? $path
: preg_replace('/(.*)\/[^\/]*/', '$1', Path::tidy($path));
if (! $files->exists($directory)) {
$files->makeDirectory($directory, 0755, true);
}
return Path::tidy($path);
}
}