-
Notifications
You must be signed in to change notification settings - Fork 6
/
TemplateFactory.php
53 lines (46 loc) · 1.21 KB
/
TemplateFactory.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
<?php
namespace DocxTemplate;
use DocxTemplate\Matcher\MatcherInterface;
use DocxTemplate\Matcher\RegExpMatcher;
class TemplateFactory
{
/**
* @var MatcherInterface
*/
private static $defaultMatcher;
/**
* @param string $prefix
* @param string $suffix
* @param bool $strictMatch
* @param string $markNameRegExp
*/
public static function useMarkSyntax($prefix, $suffix, $strictMatch = false, $markNameRegExp = null)
{
self::$defaultMatcher = new RegExpMatcher($prefix, $suffix, $strictMatch, $markNameRegExp);
}
/**
* @return MatcherInterface
*/
protected static function getDefaultMatcher()
{
if (!self::$defaultMatcher) {
self::$defaultMatcher = new RegExpMatcher();
}
return self::$defaultMatcher;
}
/**
* @param string $filePath
* @param MatcherInterface $matcher
* @return Template
*/
public static function load($filePath, MatcherInterface $matcher = null)
{
if (!$matcher) {
$matcher = self::getDefaultMatcher();
}
return new Template(
new Document($filePath),
$matcher
);
}
}