1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helldar\LaravelLangPublisher\Packages; |
4
|
|
|
|
5
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Contains; |
6
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Logger; |
7
|
|
|
use Helldar\LaravelLangPublisher\Contracts\Package as Contract; |
8
|
|
|
use Helldar\LaravelLangPublisher\Facades\Config; |
9
|
|
|
use Helldar\LaravelLangPublisher\Facades\Path; |
10
|
|
|
use Helldar\Support\Concerns\Makeable; |
11
|
|
|
use Helldar\Support\Facades\Helpers\Filesystem\Directory; |
12
|
|
|
|
13
|
|
|
abstract class Package implements Contract |
14
|
|
|
{ |
15
|
|
|
use Contains; |
16
|
|
|
use Logger; |
|
|
|
|
17
|
|
|
use Makeable; |
18
|
|
|
|
19
|
|
|
public function target(): string |
20
|
|
|
{ |
21
|
|
|
return '/'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function has(string $package = null, string $locale = null): bool |
25
|
|
|
{ |
26
|
|
|
return Directory::exists($this->basePath() . '/' . $this->vendor()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function sourcePath(string $package, string $locale): string |
30
|
|
|
{ |
31
|
|
|
$path = Path::source($package, $locale); |
32
|
|
|
|
33
|
|
|
return $path . '/' . $this->source(); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function targetPath(string $locale, string $filename): string |
37
|
|
|
{ |
38
|
|
|
$target = Path::clean(Path::target($locale)); |
39
|
|
|
|
40
|
|
|
$path = $this->target(); |
41
|
|
|
|
42
|
|
|
$name = $this->targetFilename($locale, $filename); |
43
|
|
|
|
44
|
|
|
$filename = Path::clean($path . '/' . $name, true); |
45
|
|
|
|
46
|
|
|
return $target . '/' . $filename; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function targetFilename(string $locale, string $filename): string |
50
|
|
|
{ |
51
|
|
|
if ($this->isJson($filename)) { |
52
|
|
|
return $locale . '.json'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $this->fileBasename($filename); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function basePath(): string |
59
|
|
|
{ |
60
|
|
|
return Config::basePath(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function fileBasename(string $filename): string |
64
|
|
|
{ |
65
|
|
|
return Path::basename($filename); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|