Example #1
0
 /**
  * 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;
 }