Passed
Push — master ( 25efb9...c70e91 )
by Caen
04:09 queued 12s
created

BladePage::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Pages;
6
7
use Hyde\Markdown\Models\FrontMatter;
8
use Hyde\Pages\Concerns\HydePage;
9
use Illuminate\Support\Facades\View;
10
use function array_merge;
11
12
/**
13
 * Page class for Blade pages.
14
 *
15
 * Blade pages are stored in the _pages directory and using the .blade.php extension.
16
 * They will be compiled using the Laravel Blade engine the _site/ directory.
17
 *
18
 * @see https://hydephp.com/docs/master/static-pages#creating-blade-pages
19
 * @see https://laravel.com/docs/master/blade
20
 */
21
class BladePage extends HydePage
22
{
23
    public static string $sourceDirectory = '_pages';
24
    public static string $outputDirectory = '';
25
    public static string $fileExtension = '.blade.php';
26
27
    /**
28
     * The name of the Blade View to compile. Commonly stored in _pages/{$identifier}.blade.php.
29
     */
30
    public string $view;
31
32
    public function __construct(string $view = '', FrontMatter|array $matter = [])
33
    {
34
        parent::__construct($view, $matter);
35
        $this->view = $view;
36
    }
37
38
    /** @inheritDoc */
39
    public function getBladeView(): string
40
    {
41
        return $this->view;
42
    }
43
44
    /** @inheritDoc */
45
    public function compile(): string
46
    {
47
        return View::make($this->getBladeView())->render();
48
    }
49
50
    public function toArray(): array
51
    {
52
        return array_merge(parent::toArray(), [
53
            'view' => $this->view,
54
        ]);
55
    }
56
}
57