Beispiel #1
0
 /**
  * Validate the Decoda markup.
  *
  * @param string $model
  * @param string $field
  * @return bool
  */
 public function validateDecoda($model, $field = 'content')
 {
     if (!isset($this->data[$model][$field])) {
         return true;
     }
     $decoda = new Decoda($this->data[$model][$field]);
     $decoda->defaults()->parse();
     $errors = $decoda->getErrors();
     if (!$errors) {
         return true;
     }
     $nesting = array();
     $closing = array();
     $scope = array();
     foreach ($errors as $error) {
         switch ($error['type']) {
             case Decoda::ERROR_NESTING:
                 $nesting[] = $error['tag'];
                 break;
             case Decoda::ERROR_CLOSING:
                 $closing[] = $error['tag'];
                 break;
             case Decoda::ERROR_SCOPE:
                 $scope[] = $error['child'] . ' -> ' . $error['parent'];
                 break;
         }
     }
     if ($nesting) {
         return $this->invalid('content', 'The following tags have been nested in the wrong order: %s', implode(', ', $nesting));
     }
     if ($closing) {
         return $this->invalid('content', 'The following tags have no closing tag: %s', implode(', ', $closing));
     }
     if ($scope) {
         return $this->invalid('content', 'The following tags can not be placed within a specific tag: %s', implode(', ', $scope));
     }
     return true;
 }