[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/form/ -> AphrontErrorView.php (source)

   1  <?php
   2  
   3  final class AphrontErrorView extends AphrontView {
   4  
   5    const SEVERITY_ERROR = 'error';
   6    const SEVERITY_WARNING = 'warning';
   7    const SEVERITY_NOTICE = 'notice';
   8    const SEVERITY_NODATA = 'nodata';
   9  
  10    private $title;
  11    private $errors;
  12    private $severity;
  13    private $id;
  14  
  15    public function setTitle($title) {
  16      $this->title = $title;
  17      return $this;
  18    }
  19  
  20    public function setSeverity($severity) {
  21      $this->severity = $severity;
  22      return $this;
  23    }
  24  
  25    public function setErrors(array $errors) {
  26      $this->errors = $errors;
  27      return $this;
  28    }
  29  
  30    public function setID($id) {
  31      $this->id = $id;
  32      return $this;
  33    }
  34  
  35    final public function render() {
  36  
  37      require_celerity_resource('aphront-error-view-css');
  38  
  39      $errors = $this->errors;
  40      if ($errors) {
  41        $list = array();
  42        foreach ($errors as $error) {
  43          $list[] = phutil_tag(
  44            'li',
  45            array(),
  46            $error);
  47        }
  48        $list = phutil_tag(
  49          'ul',
  50          array(
  51            'class' => 'aphront-error-view-list',
  52          ),
  53          $list);
  54      } else {
  55        $list = null;
  56      }
  57  
  58      $title = $this->title;
  59      if (strlen($title)) {
  60        $title = phutil_tag(
  61          'h1',
  62          array(
  63            'class' => 'aphront-error-view-head',
  64          ),
  65          $title);
  66      } else {
  67        $title = null;
  68      }
  69  
  70      $this->severity = nonempty($this->severity, self::SEVERITY_ERROR);
  71  
  72      $classes = array();
  73      $classes[] = 'aphront-error-view';
  74      $classes[] = 'aphront-error-severity-'.$this->severity;
  75      $classes = implode(' ', $classes);
  76  
  77      $children = $this->renderChildren();
  78      $children[] = $list;
  79  
  80      return phutil_tag(
  81        'div',
  82        array(
  83          'id' => $this->id,
  84          'class' => $classes,
  85        ),
  86        array(
  87          $title,
  88          phutil_tag(
  89            'div',
  90            array(
  91              'class' => 'aphront-error-view-body',
  92            ),
  93            $children),
  94        ));
  95    }
  96  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1