forked from featherforums/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeatherCompiler.php
More file actions
73 lines (62 loc) · 1.61 KB
/
Copy pathFeatherCompiler.php
File metadata and controls
73 lines (62 loc) · 1.61 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php namespace Feather\Presenter\Compilers;
use Illuminate\View\Compilers\BladeCompiler;
class FeatherCompiler extends BladeCompiler {
/**
* Compile the given template contents.
*
* @param string $value
* @return string
*/
public function compileString($value)
{
$this->compilers = array_merge($this->compilers, array(
'Assignments',
'ExtensionEvents',
'InlineErrors',
'Errors'
));
return parent::compileString($value);
}
/**
* Compile assignments into valid PHP.
*
* @param string $value
* @return string
*/
public function compileAssignments($value)
{
return preg_replace('/(\s*)@assign\s*\(\$(.*), (.*)\)(\s*)/', '$1<?php $$2 = $3; ?>$4', $value);
}
/**
* Compile extension events into valid PHP.
*
* @param string $value
* @return string
*/
public function compileExtensionEvents($value)
{
$pattern = $this->createMatcher('event');
return preg_replace($pattern, '$1<?php echo Feather\Extension::fire$2; ?>', $value);
}
/**
* Compile inline errors into valid PHP.
*
* @param string $value
* @return string
*/
public function compileInlineErrors($value)
{
$pattern = $this->createMatcher('error');
return preg_replace($pattern, '$1<?php echo $errors->has$2 ? view("feather::errors.inline", array("error" => $errors->first$2)) : null; ?>', $value);
}
/**
* Compile errors into valid PHP.
*
* @param string $value
* @return string
*/
public function compileErrors($value)
{
return str_replace('@errors', '<?php echo $errors->all() ? view("feather::errors.page", array("errors" => $errors->all())) : null; ?>', $value);
}
}