/** * Creates a field instance * * @param string $method The field type * @param array $parameters An array of parameters * @return Former */ public static function __callStatic($method, $parameters) { // Form opener if (str_contains($method, 'open')) { static::$form = new Form(); return static::form()->open($method, $parameters); } // Avoid conflict with chained label method if ($method == 'label') { return call_user_func_array('static::_label', $parameters); } // Checking for any supplementary classes $classes = explode('_', $method); $method = array_pop($classes); // Destroy previous field instance static::$field = null; // Picking the right class if (class_exists('\\Former\\Fields\\' . ucfirst($method))) { $callClass = ucfirst($method); } else { switch ($method) { case 'multiselect': $callClass = 'Select'; break; case 'checkboxes': $callClass = 'Checkbox'; break; case 'radios': $callClass = 'Radio'; break; case 'files': $callClass = 'File'; break; default: $callClass = 'Input'; break; } } // Listing parameters $class = '\\Former\\Fields\\' . $callClass; static::$field = new $class($method, array_get($parameters, 0), array_get($parameters, 1), array_get($parameters, 2), array_get($parameters, 3), array_get($parameters, 4), array_get($parameters, 5)); // Inline checkboxes if (in_array($callClass, array('Checkbox', 'Radio')) and in_array('inline', $classes)) { static::$field->inline(); } // Add any size we found $size = Framework::getFieldSizes($classes); if ($size) { static::$field->addClass($size); } return new Former(); }
/** * Creates a field instance * * @param string $method The field type * @param array $parameters An array of parameters * @return Former */ public static function __callStatic($method, $parameters) { // Form opener if (str_contains($method, 'open')) { static::$form = new Form(); return static::form()->open($method, $parameters); } // Checking for any supplementary classes $classes = explode('_', $method); $method = array_pop($classes); // Picking the right class if (class_exists('\\Former\\Fields\\' . ucfirst($method))) { $callClass = ucfirst($method); } else { switch ($method) { case 'multiselect': $callClass = 'Select'; break; case 'checkboxes': $callClass = 'Checkbox'; break; case 'radios': $callClass = 'Radio'; break; default: $callClass = 'Input'; break; } } // Listing parameters $class = '\\Former\\Fields\\' . $callClass; static::$field = new $class($method, array_get($parameters, 0), array_get($parameters, 1), array_get($parameters, 2), array_get($parameters, 3), array_get($parameters, 4), array_get($parameters, 5)); // Inline checkboxes if (in_array($callClass, array('Checkbox', 'Radio')) and in_array('inline', $classes)) { static::$field->inline(); } // Add any size we found if ($sizes = array_intersect(static::$FIELD_SIZES, $classes)) { $size = $sizes[key($sizes)]; $size = starts_with($size, 'span') ? $size : 'input-' . $size; static::$field->addClass($size); } return new Former(); }
/** * Creates a field instance * * @param string $method The field type * @param array $parameters An array of parameters * @return Former */ public static function __callStatic($method, $parameters) { // Form opener if (str_contains($method, 'open')) { static::$form = new Form(); static::form()->open($method, $parameters); return new static(); } // Avoid conflict with chained label method if ($method == 'label') { return call_user_func_array('static::_label', $parameters); } // Checking for any supplementary classes $classes = explode('_', $method); $method = array_pop($classes); // Destroy previous field instance static::$field = null; // Picking the right class if (class_exists(static::FIELDSPACE . ucfirst($method))) { $callClass = ucfirst($method); } else { switch ($method) { case 'submit': case 'reset': $callClass = 'Button'; break; case 'multiselect': $callClass = 'Select'; break; case 'checkboxes': $callClass = 'Checkbox'; break; case 'radios': $callClass = 'Radio'; break; case 'files': $callClass = 'File'; break; default: $callClass = 'Input'; break; } } // Check for potential errors if (!class_exists(static::FIELDSPACE . $callClass)) { throw new \Exception('The class "' . static::FIELDSPACE . $callClass . '" called by field "' . $method . '" doesn\'t exist'); } // Listing parameters $class = static::FIELDSPACE . $callClass; static::$field = new $class($method, array_get($parameters, 0), array_get($parameters, 1), array_get($parameters, 2), array_get($parameters, 3), array_get($parameters, 4), array_get($parameters, 5)); // Inline checkboxes if (in_array($callClass, array('Checkbox', 'Radio')) and in_array('inline', $classes)) { static::$field->inline(); } // Filter classes according to field type $classes = $callClass == 'Button' ? Framework::getButtonTypes($classes) : Framework::getFieldSizes($classes); // Add any supplementary classes we found if ($classes) { static::$field->addClass($classes); } // As Buttons are more of a helper class, we return them directly if ($callClass == 'Button') { return static::$field; } return new static(); }