File: JavaScriptTernary.php

package info (click to toggle)
dojo 1.10.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 97,980 kB
  • ctags: 10,348
  • sloc: php: 10,616; xml: 3,429; java: 3,098; sql: 928; sh: 484; pascal: 205; perl: 182; makefile: 77; python: 45; sed: 37; ruby: 10
file content (42 lines) | stat: -rw-r--r-- 879 bytes parent folder | download | duplicates (7)
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
<?php

require_once('Destructable.php');

class JavaScriptTernary extends Destructable {
  protected $expression;
  protected $if_true;
  protected $if_false;

  public function __construct($expression, $if_true, $if_false) {
    $this->expression = $expression;
    $this->if_true = $if_true;
    $this->if_false = $if_false;
  }

  public function __destruct() {
    $this->mem_flush('expression', 'if_true', 'if_false');
  }

  public function type() {
    $trues = $this->if_true;
    if (!is_array($trues)) {
      $trues = array($trues);
    }
    foreach ($trues as $true) {
      if ($type = $true->type()) {
        return $type;
      }
    }

    $falses = $this->if_false;
    if (!is_array($falses)) {
      $falses = array($falses);
    }
    foreach ($falses as $false) {
      if ($type = $false->type()) {
        return $type;
      }
    }
    return '';
  }
}