Line | |
---|
1 | <?php |
---|
2 | |
---|
3 | require_once('Destructable.php'); |
---|
4 | |
---|
5 | class JavaScriptTernary extends Destructable { |
---|
6 | protected $expression; |
---|
7 | protected $if_true; |
---|
8 | protected $if_false; |
---|
9 | |
---|
10 | public function __construct($expression, $if_true, $if_false) { |
---|
11 | $this->expression = $expression; |
---|
12 | $this->if_true = $if_true; |
---|
13 | $this->if_false = $if_false; |
---|
14 | } |
---|
15 | |
---|
16 | public function __destruct() { |
---|
17 | $this->mem_flush('expression', 'if_true', 'if_false'); |
---|
18 | } |
---|
19 | |
---|
20 | public function type() { |
---|
21 | $trues = $this->if_true; |
---|
22 | if (!is_array($trues)) { |
---|
23 | $trues = array($trues); |
---|
24 | } |
---|
25 | foreach ($trues as $true) { |
---|
26 | if ($type = $true->type()) { |
---|
27 | return $type; |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | $falses = $this->if_false; |
---|
32 | if (!is_array($falses)) { |
---|
33 | $falses = array($falses); |
---|
34 | } |
---|
35 | foreach ($falses as $false) { |
---|
36 | if ($type = $false->type()) { |
---|
37 | return $type; |
---|
38 | } |
---|
39 | } |
---|
40 | return ''; |
---|
41 | } |
---|
42 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.