|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the "andrey-helldar/laravel-lang-publisher" project. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Andrey Helldar <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright 2021 Andrey Helldar |
|
12
|
|
|
* |
|
13
|
|
|
* @license MIT |
|
14
|
|
|
* |
|
15
|
|
|
* @see https://github.com/andrey-helldar/laravel-lang-publisher |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
declare(strict_types=1); |
|
19
|
|
|
|
|
20
|
|
|
namespace Helldar\LaravelLangPublisher\Concerns; |
|
21
|
|
|
|
|
22
|
|
|
use Helldar\LaravelLangPublisher\Facades\Helpers\Config; |
|
23
|
|
|
use Illuminate\Support\Collection; |
|
24
|
|
|
use Illuminate\Support\Str; |
|
25
|
|
|
|
|
26
|
|
|
trait Paths |
|
27
|
|
|
{ |
|
28
|
|
|
protected $trim_chars = '/\\'; |
|
29
|
|
|
|
|
30
|
|
|
protected $directory_separator = DIRECTORY_SEPARATOR; |
|
31
|
|
|
|
|
32
|
|
|
protected function directory(string $path): string |
|
33
|
|
|
{ |
|
34
|
|
|
return pathinfo($path, PATHINFO_DIRNAME); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function filename(string $filename): string |
|
38
|
|
|
{ |
|
39
|
|
|
return pathinfo($filename, PATHINFO_FILENAME); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function basename(string $filename): string |
|
43
|
|
|
{ |
|
44
|
|
|
return pathinfo($filename, PATHINFO_BASENAME); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function extension(string $filename): string |
|
48
|
|
|
{ |
|
49
|
|
|
return pathinfo($filename, PATHINFO_EXTENSION); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function path(string $base_path, ...$parameters): string |
|
53
|
|
|
{ |
|
54
|
|
|
$base_path = rtrim($base_path, $this->trim_chars); |
|
55
|
|
|
|
|
56
|
|
|
$parameters = Collection::make($parameters) |
|
57
|
|
|
->map(function (string $parameter) { |
|
58
|
|
|
return trim($parameter, $this->trim_chars); |
|
59
|
|
|
})->implode($this->directory_separator); |
|
60
|
|
|
|
|
61
|
|
|
return $base_path . $this->directory_separator . $parameters; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
protected function vendorPath(string ...$parameters): string |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->path(Config::vendor(), ...$parameters); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function resourcesPath(string ...$parameters): string |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->path(Config::resources(), ...$parameters); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
protected function resolvePath(string $path, string $locale): string |
|
75
|
|
|
{ |
|
76
|
|
|
return Str::replace('{locale}', $locale, $path); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|