Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| Hyde | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
8 | |
100.00% |
1 / 1 |
| version | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| getBasePath | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| setBasePath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| titleFromSlug | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLatestPosts | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Hyde\Framework; |
| 4 | |
| 5 | use Composer\InstalledVersions; |
| 6 | use Hyde\Framework\Concerns\Internal\AssetManager; |
| 7 | use Hyde\Framework\Concerns\Internal\FileHelpers; |
| 8 | use Hyde\Framework\Concerns\Internal\FluentPathHelpers; |
| 9 | use Hyde\Framework\Helpers\HydeHelperFacade; |
| 10 | use Hyde\Framework\Models\Parsers\MarkdownPostParser; |
| 11 | use Hyde\Framework\Services\CollectionService; |
| 12 | use Illuminate\Support\Collection; |
| 13 | use Illuminate\Support\Str; |
| 14 | |
| 15 | /** |
| 16 | * General facade for Hyde services. |
| 17 | * |
| 18 | * @author Caen De Silva <caen@desilva.se> |
| 19 | * @copyright 2022 Caen De Silva |
| 20 | * @license MIT License |
| 21 | * |
| 22 | * @link https://hydephp.com/ |
| 23 | */ |
| 24 | class Hyde |
| 25 | { |
| 26 | use FileHelpers; |
| 27 | use AssetManager; |
| 28 | use FluentPathHelpers; |
| 29 | use HydeHelperFacade; |
| 30 | |
| 31 | protected static string $basePath; |
| 32 | |
| 33 | public static function version(): string |
| 34 | { |
| 35 | return InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased'; |
| 36 | } |
| 37 | |
| 38 | public static function getBasePath(): string |
| 39 | { |
| 40 | if (! isset(static::$basePath)) { |
| 41 | static::$basePath = getcwd(); |
| 42 | } |
| 43 | |
| 44 | return static::$basePath; |
| 45 | } |
| 46 | |
| 47 | public static function setBasePath(string $path): void |
| 48 | { |
| 49 | static::$basePath = $path; |
| 50 | } |
| 51 | |
| 52 | public static function titleFromSlug(string $slug): string |
| 53 | { |
| 54 | return Str::title(str_replace('-', ' ', ($slug))); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @deprecated v0.34.x Use MarkdownPost::getLatestPosts() instead. |
| 59 | */ |
| 60 | public static function getLatestPosts(): Collection |
| 61 | { |
| 62 | $collection = new Collection(); |
| 63 | |
| 64 | foreach (CollectionService::getMarkdownPostList() as $filepath) { |
| 65 | $collection->push((new MarkdownPostParser(basename($filepath, '.md')))->get()); |
| 66 | } |
| 67 | |
| 68 | return $collection->sortByDesc('matter.date'); |
| 69 | } |
| 70 | } |