You are here

private function Validator::parse in Form API Validation 8.2

Parse user defined validator.

1 call to Validator::parse()
Validator::__construct in src/Validator.php
Create object and parse validator data.

File

src/Validator.php, line 68

Class

Validator
Validator Class to parse Form Element validators content.

Namespace

Drupal\fapi_validation

Code

private function parse() {
  if (is_array($this->rawValidator)) {
    if (isset($this->rawValidator['error'])) {
      $this->error_message = $this->rawValidator['error'];
    }
    if (isset($this->rawValidator['error callback'])) {
      $this->error_callback = $this->rawValidator['error callback'];
    }
    if (!isset($this->rawValidator['rule'])) {
      throw new \LogicException("You can't define a validator as array and don't define 'rule' key.");
    }
    $this->rawValidator = $this->rawValidator['rule'];
  }
  preg_match('/^(.*?)(\\[(.*)\\])?$/', $this->rawValidator, $rs);
  $this->name = $rs[1];
  if (isset($rs[3])) {
    if ($this->name == 'regexp') {
      $this->params = [
        $rs[3],
      ];
    }
    else {
      $this->params = preg_split('/ *, */', $rs[3]);
    }
  }
}