/
SourcePathHelpers.php
56 lines (46 loc) · 1.63 KB
/
SourcePathHelpers.php
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
<?php
namespace Hyde\Framework\Concerns\Internal;
use Hyde\Framework\Services\DiscoveryService;
use Hyde\Framework\Models\BladePage;
use Hyde\Framework\Models\MarkdownPage;
use Hyde\Framework\Models\MarkdownPost;
use Hyde\Framework\Models\DocumentationPage;
/**
* Offloads file helper methods for the Hyde Facade.
*
* Provides a more fluent way of getting either the absolute path
* to a model's source directory, or an absolute path to a file within it.
*
* These are intended to be used as a dynamic alternative to legacy code
* Hyde::path('_pages/foo') becomes Hyde::getBladePagePath('foo')
*
* @see \Hyde\Framework\Hyde
* @see \Tests\Unit\SourcePathHelpersTest
*/
trait SourcePathHelpers
{
public static function getBladePagePath(string $path = ''): string
{
return static::getModelSourcePath(BladePage::class, $path);
}
public static function getMarkdownPagePath(string $path = ''): string
{
return static::getModelSourcePath(MarkdownPage::class, $path);
}
public static function getMarkdownPostPath(string $path = ''): string
{
return static::getModelSourcePath(MarkdownPost::class, $path);
}
public static function getDocumentationPagePath(string $path = ''): string
{
return static::getModelSourcePath(DocumentationPage::class, $path);
}
public static function getModelSourcePath(string $model, string $path = ''): string
{
if (empty($path)) {
return static::path(DiscoveryService::getFilePathForModelClassFiles($model));
}
$path = trim($path, '/\\');
return static::path(DiscoveryService::getFilePathForModelClassFiles($model).DIRECTORY_SEPARATOR.$path);
}
}