public static function check_data() { if (empty(static::$data)) { throw new ValidationEmptyDataException('Validator attempted to validate empty data'); } $output = []; foreach (static::$data as $field => $value) { if (array_key_exists($field, static::$criteria)) { static::$field = ['name' => $field, 'value' => $value]; $result = static::validate(static::$field, static::$criteria[$field]); if ($result !== true) { $output = array_merge($output, $result); } } } return empty($output) ? true : $output; }
/** * 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(); 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(); }
/** * @return \Fubhy\GraphQL\Type\Definition\Types\ObjectType */ public static function field() { if (!isset(static::$field)) { static::$field = new ObjectType('__Field', ['name' => ['type' => new NonNullModifier(Type::stringType()), 'resolve' => [__CLASS__, 'resolveFieldName']], 'description' => ['type' => Type::stringType(), 'resolve' => [__CLASS__, 'resolveFieldDescription']], 'args' => ['type' => new NonNullModifier(new ListModifier(new NonNullModifier([__CLASS__, 'inputValue']))), 'resolve' => [__CLASS__, 'resolveFieldArguments']], 'type' => ['type' => new NonNullModifier([__CLASS__, 'type']), 'resolve' => [__CLASS__, 'resolveFieldType']], 'isDeprecated' => ['type' => new NonNullModifier(Type::booleanType()), 'resolve' => [__CLASS__, 'resolveFieldIsDeprecated']], 'deprecationReason' => ['type' => Type::stringType(), 'resolve' => [__CLASS__, 'resolveFieldDeprecationReason']]]); } return static::$field; }
/** * Prints out Field wrapped in ControlGroup * * @return string A form field */ public function __toString() { // Dry syntax (hidden fields, plain fields) if (static::$field->type == 'hidden' or static::form()->type == 'search' or static::form()->type == 'inline') { $html = static::$field->__toString(); } elseif (static::$useBootstrap and static::form()->type) { $html = $this->control()->wrapField(static::$field); } else { $html = \Form::label(static::$field->name, static::$field->label); $html .= static::$field; } // Destroy field instance static::$field = null; return $html; }