/** * {@inheritdoc} */ public function validate($value) { if (Value::isEmpty($value)) { return true; } $valid = Arr::contains($value, $this->values); return $valid; }
/** * Process data * * @param array $data Data * * @return int * @throws \InvalidArgumentException */ protected function processData(array &$data) { $max = null; foreach ($data as $value) { $depth = Arr::depth($value) + 1; if ($max === null) { $max = $depth; } elseif ($depth !== $max) { throw new \InvalidArgumentException('Rendering INI format requires array in which all elements have with same complexity.'); } } $max = (int) $max; if ($max > 2) { throw new \InvalidArgumentException('Rendering INI format expects only 1 or 2 dimensional array.'); } return $max; }
/** * Group fields by specified pattern * Creates multi-dimensional tree in which each level corresponds to pattern parameter * Leafs are form fields * * @param string $template Field name template * * @return array * @throws \InvalidArgumentException */ public function groupFields($template) { $template = new Template($template); $result = array(); foreach ($this->fields as $name => $field) { $match = array(); if (preg_match($template->getRegExp(), $name, $match)) { unset($match[0]); $match[] = $field; $fields = Arr::nest($match); $result = array_replace_recursive($result, $fields); } } return $result; }
/** * Get uploaded files data * * @param mixed $key Key * @param mixed $default Value if key not found * * @return array */ public function getFile($key = null, $default = null) { return $key === null ? $this->file : Arr::value($this->file, $key, $default); }