-
Notifications
You must be signed in to change notification settings - Fork 1
/
MFragment.php
60 lines (51 loc) · 1.38 KB
/
MFragment.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
57
58
59
60
<?php
/**
* @author Joachim Doerr
* @package redaxo5
* @license MIT
*/
namespace FriendsOfRedaxo;
use FriendsOfRedaxo\MFragment\Core\MFragmentProcessor;
use FriendsOfRedaxo\MFragment\MFragmentElements;
use rex_factory_trait;
use rex_fragment;
class MFragment extends MFragmentElements
{
use rex_factory_trait;
private bool $debug;
public static function factory(): MFragment
{
$class = static::getFactoryClass();
return new $class();
}
public function setDebug(bool $debug): MFragment
{
$this->debug = $debug;
return $this;
}
public function show(): string
{
$processor = new MFragmentProcessor();
return $processor->process($this);
}
/**
* @description filename can be with or without .php extension
*/
public static function parse(string $filename, array $vars): string
{
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if ($extension == 'php') {
$filename = substr($filename, 0, strlen($filename) - 4);
}
$fragment = new rex_fragment($vars);
return $fragment->parse($filename . '.php');
}
/**
* @description Parse content using ContentProcessor
*/
public static function process($content): string
{
$processor = new MFragmentProcessor();
return $processor->process($content);
}
}