Passed
Push — master ( 835fdf...8ea54b )
by Caen
03:25 queued 11s
created

VirtualPage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
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
10
/**
11
 * A virtual page is a page that does not have a source file.
12
 *
13
 * @experimental This feature is experimental and may change substantially before the 1.0.0 release.
14
 *
15
 * This can be useful for creating pagination pages and the like.
16
 * When used in a package, it's on the package developer to ensure
17
 * that the virtual page is registered with Hyde, usually within the
18
 * boot method of the package's service provider so it can be compiled.
19
 */
20
class VirtualPage extends HydePage
21
{
22
    protected string $contents;
23
24
    public static string $sourceDirectory = '';
25
    public static string $outputDirectory = '';
26
    public static string $fileExtension = '';
27
28
    public static function make(string $identifier = '', FrontMatter|array $matter = [], string $contents = ''): static
29
    {
30
        return new static($identifier, $matter, $contents);
31
    }
32
33
    public function __construct(string $identifier, FrontMatter|array $matter = [], string $contents = '')
34
    {
35
        parent::__construct($identifier, $matter);
36
37
        $this->contents = $contents;
38
    }
39
40
    public function contents(): string
41
    {
42
        return $this->contents;
43
    }
44
45
    public function compile(): string
46
    {
47
        return $this->contents();
48
    }
49
}
50