示例#1
0
 /**
  * Appends an element to the container, creating it first
  *
  * The element will be created via {@link HTML_QuickForm2_Factory::createElement()}
  * and then added via the {@link appendChild()} method.
  * The element type is deduced from the method name.
  * This is a convenience method to reduce typing.
  *
  * @param string $m Method name
  * @param array  $a Method arguments
  *
  * @return   LaraFormNode     Added element
  * @throws   \HTML_QuickForm2_InvalidArgumentException
  * @throws   \HTML_QuickForm2_NotFoundException
  */
 public function __call($m, $a)
 {
     if (preg_match('/^(add)([a-zA-Z0-9_]+)$/', $m, $match)) {
         if ($match[1] == 'add') {
             $type = strtolower($match[2]);
             $name = isset($a[0]) ? $a[0] : null;
             $attr = isset($a[1]) ? $a[1] : null;
             $data = isset($a[2]) ? $a[2] : [];
             return $this->addElement($type, $name, $attr, $data);
         }
     }
     if (preg_match('/^(put)([a-zA-Z0-9_]+)$/', $m, $match)) {
         if ($match[1] == 'put') {
             $type = \Illuminate\Support\Str::snake($match[2]);
             $callback = \Larakit\QuickForm\Register::callback($type);
             if (!is_callable($callback)) {
                 throw new \Exception('Элемент с типом ' . $type . ' не зарегистрирован');
             }
             $el = $this->addElement(call_user_func_array($callback, $a));
             return $el;
         }
     }
     throw new \Exception("Fatal error: Call to undefined method " . get_class($this) . "::" . $m . "()", E_USER_ERROR);
 }