1 | <?php |
||
2 | /** |
||
3 | * {CLASS SUMMARY} |
||
4 | * |
||
5 | * Date: 7/27/18 |
||
6 | * Time: 11:31 PM |
||
7 | * @author Michael Munger <[email protected]> |
||
8 | */ |
||
9 | |||
10 | namespace HPHIO\Farret; |
||
11 | |||
12 | |||
13 | class TemplateHookWithArgs extends AbstractTag |
||
14 | { |
||
15 | |||
16 | protected $fartDictionary = []; |
||
17 | |||
18 | 26 | public function setup() |
|
19 | { |
||
20 | 26 | $this->type = AbstractTag::HOOK; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
21 | 26 | $this->parseArgs(); |
|
22 | 26 | } |
|
23 | |||
24 | 26 | private function trimArg($arg) { |
|
25 | |||
26 | 26 | $arg = str_replace("|",'',$arg); |
|
27 | 26 | $arg = trim($arg); |
|
28 | 26 | return $arg; |
|
29 | } |
||
30 | |||
31 | 26 | public function parseArgs() { |
|
32 | 26 | $argsPattern = '/(\|(?:{{){0,1}([A-Za-z0-9-]+)(?:}}){0,1})/'; |
|
33 | 26 | $matches = []; |
|
34 | |||
35 | 26 | preg_match_all($argsPattern, $this->tag, $matches, PREG_PATTERN_ORDER); |
|
36 | |||
37 | //Clean up the args. |
||
38 | 26 | $this->args = array_map([$this,'trimArg'], $matches[0]); |
|
39 | |||
40 | 26 | } |
|
41 | |||
42 | 7 | public function getLabel() |
|
43 | { |
||
44 | 7 | $matches = []; |
|
45 | 7 | $result = (preg_match_all($this->pattern, $this->tag,$matches, PREG_SET_ORDER) !== false); |
|
46 | |||
47 | 7 | return ($result ? $matches[0][1] : false); |
|
48 | } |
||
49 | |||
50 | 7 | public function fart($dictionary) { |
|
51 | 7 | $TagFactory = new TagFactory(); |
|
52 | |||
53 | 7 | for($x = 0; $x < count($this->args); $x++) { |
|
54 | 7 | $Tag = $TagFactory->getTag($this->args[$x]); |
|
55 | |||
56 | //If this argument is NOT a tag like {{FIRSTNAME}} |
||
57 | 7 | if($Tag === false) { |
|
58 | 5 | foreach($dictionary as $find => $replace) { |
|
59 | 3 | $this->args[$x] = str_replace($find, $replace, $this->args[$x]); |
|
60 | } |
||
61 | 5 | continue; |
|
62 | } |
||
63 | |||
64 | //This is some sort of tag. Use the Tag class to do the replacement. |
||
65 | 4 | $Tag->fart($dictionary); |
|
66 | 4 | $this->args[$x] = $Tag->getReplacement(); |
|
67 | } |
||
68 | 7 | } |
|
69 | |||
70 | 3 | public function getTag() |
|
71 | { |
||
72 | // $pattern = '/(?:{%)\s{0,}([A-Z]+)\s{0,}\|.*\s{0,}(?:%})/m'; |
||
73 | // $matches = []; |
||
74 | // $result = (preg_match_all($pattern, $this->tag,$matches, PREG_SET_ORDER) !== false); |
||
75 | // |
||
76 | // return ($result ? $matches[0][1] : false); |
||
77 | 3 | return $this->tag; |
|
78 | } |
||
79 | |||
80 | 2 | public function getReplacement() |
|
81 | { |
||
82 | 2 | return $this->replacement; |
|
83 | } |
||
84 | } |