forked from EFTEC/BladeOne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBladeOneLogic.php
59 lines (56 loc) · 1.75 KB
/
BladeOneLogic.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
<?php
/**
* trait BladeOneLogic
* Copyright (c) 2016 Jorge Patricio Castro Castillo MIT License. Don't delete this comment, its part of the license.
* Extends the tags of the class BladeOne. Its optional
* It adds the next tags
* <code>
* @ switch($variable)
* @ case(option1)
* ...
* @ case(option2)
* ...
* @ defaultcase()
* ...
* @ endswitch()
* </code>
* NOTE: Its not compatible with nested switches
* @package BladeOneLogic
* @version 1.4 2016-06-25
* @link https://github.com/EFTEC/BladeOne
* @author Jorge Patricio Castro Castillo <jcastro arroba eftec dot cl>
*/
namespace eftec\bladeone;
trait BladeOneLogic
{
/** @var int Indicates the number of open switches */
private $switchCount=0;
/** @var bool Indicates if the switch is recently open */
private $switchFirst=true;
//<editor-fold desc="compile function">
public function compileSwitch($expression) {
$this->switchCount++;
return $this->phpTag."switch($expression) { ?>";
}
public function compileCase($expression) {
if ($this->switchFirst) {
$this->switchFirst=false;
return $this->phpTag."case $expression: ?>";
}
return $this->phpTag."break;\n case $expression: ?>";
}
public function compileDefaultCase() {
if ($this->switchFirst) {
return $this->showError("@defaultcase","@switch without any @case",true);
}
return $this->phpTag."break;\n default: ?>";
}
public function compileEndSwitch() {
$this->switchCount=$this->switchCount-1;
if ($this->switchCount<0) {
return $this->showError("@endswitch","Missing @switch",true);
}
return $this->phpTag."} // end switch ?>";
}
//</editor-fold>
}