__callStatic() public static method

Handle dynamic, static calls to the object.
public static __callStatic ( string $method, array $args ) : mixed
$method string
$args array
return mixed
Beispiel #1
0
    /**
     * Checks call to see if we can create an input from a magic call (for you wizards).
     * large_text, xlarge_textarea, small_number, etc...
     *
     * @param string $method Name of missing method
     * @param array $parameters array of parameters passed to missing method
     *
     * @return mixed
     */
    protected static function magic_input($method, $parameters)
    {
        //$sizes = array('mini' , 'small', 'medium', 'large', 'xlarge', 'xxlarge', 'span1', 'span2', 'span3', 'span4', 'span5', 'span6', 'span7', 'span8', 'span9', 'span10', 'span11', 'span12');
        $types = array(
            'input',
            'text',
            'password',
            'uneditable',
            'select',
            'multiselect',
            'file',
            'textarea',
            'date',
            'number',
            'url',
            'tel',
            'email',
            'search'
        );

        $method_array = explode('_', strtolower($method));
        $type_found = array_intersect($method_array, $types);

        if (count($type_found) > 0) {
            $function = $type_found[key($type_found)];
            $attr_index = 0;

            switch ($function) {
                case 'password':
                case 'file':
                case 'uneditable':
                    // password($name, $attributes = array())
                    // Set attributes array and call function
                    $attr_index = 1;
                    break;
                case 'input':
                    // input($type, $name, $value = null, $attributes = array())
                    // Set defaults and attributes array and call function
                    if (!isset($parameters[2])) {
                        $parameters[2] = null;
                    }
                    $attr_index = 3;
                    break;
                case 'select':
                case 'multiselect':
                    // select($name, $options = array(), $selected = null, $attributes = array())
                    // Set defaults and attributes array and call functions
                    if (!isset($parameters[1])) $parameters[1] = array();
                    if (!isset($parameters[2])) $parameters[2] = null;
                    $attr_index = 3;
                    break;
                default:
                    // text($name, $value = null, $attributes = array())
                    // textarea($name, $value = null, $attributes = array())
                    // Covers all the other methods
                    if (!isset($parameters[1])) $parameters[1] = null;
                    $attr_index = 2;
                    break;
            }
            if (in_array($function, $types)) {
                $attributes = isset($parameters[$attr_index]) ? $parameters[$attr_index] : array('class' => '');
                $attributes['class'] = isset($attributes['class']) ? $attributes['class'] . ' form-control' : 'form-control';
                $parameters[$attr_index] = $attributes;
            }
            $parameters = Helpers::set_multi_class_attributes(
                $function,
                $method_array,
                $parameters,
                $attr_index,
                'input-',
                'span'
            );
            $method = $function;

        }

        if (method_exists('Bootstrapper\Form', $method)) {
            return call_user_func_array('static::' . $method, $parameters);
        } elseif (method_exists(static::getFacadeAccessor(), $method)) {
            return parent::__callStatic($method, $parameters);
        } else {

            try {
                //Try solving a macro
                return parent::__callStatic($method, $parameters);
            } catch (\BadMethodCallException $e) {
                //Silences in case there is no macro and continues execution
            }

        }

        array_unshift($parameters, $method);

        return call_user_func_array('parent::input', $parameters);
    }