Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions AbstractArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ abstract class AbstractArguments
protected $attr;

protected $fieldType;
protected $attrArr = array();
protected $attrArr = [];
protected $name;
protected $value;
protected $default;
protected $label;
protected $description;
protected $validate = array();
protected $items = array();
protected $config = array();
protected $fields = array();
protected $validate = [];
protected $items = [];
protected $config = [];
protected $fields = [];
protected $identifier;

/**
Expand Down Expand Up @@ -141,9 +141,9 @@ protected function setAttr(): string
protected function groupFields(callable $callback, bool $manipulateName = true)
{
$out = "";

if (!is_array($this->value)) {
$this->value = array(0);
$this->value = [0];
} // This will add new value
foreach ($this->value as $k => $a) {
$outB = "";
Expand Down Expand Up @@ -191,7 +191,7 @@ protected function isChecked($val): bool
protected function lastKey(): int
{
$findKey = 0;
if (!is_null($this->value) && is_array($this->value)) {
if ($this->value !== null && is_array($this->value)) {
$findKey = $this->value;
krsort($findKey);
$findKey = key($findKey);
Expand Down
22 changes: 11 additions & 11 deletions AbstractFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ abstract class AbstractFields
protected $name = "form";
protected $fields;
protected $type;
protected $args = array();
protected $values = array();
protected $inpArr = array();
protected $args = [];
protected $values = [];
protected $inpArr = [];

/**
* Form creator
Expand All @@ -49,10 +49,10 @@ public function __construct(FormFieldsInterface $fields)
public function __call($method, $args): FormFieldsInterface
{
// Reset fields instance
if (!is_null($this->type)) {
if ($this->type !== null) {
$this->fields = $this->fields->withField();
}

if ($this instanceof FieldInterface) {
$this->fields->setFieldInst($this);
}
Expand Down Expand Up @@ -109,11 +109,11 @@ public function setValues(array|object $values): void
}
}

/**
* Delete search and find a array item
* @param array $key Possible to traverse to form field with the comma select property
* @return void
*/
/**
* Delete search and find a array item
* @param array $key Possible to traverse to form field with the comma select property
* @return void
*/
final protected function findDelete(array &$array, array $key): void
{
$firstKey = array_shift($key);
Expand All @@ -133,7 +133,7 @@ final protected function findDelete(array &$array, array $key): void
*/
final protected function resolveGrpName(): array
{
$get = array();
$get = [];
foreach ($this->inpArr as $a1) {
foreach ($a1 as $k => $a2) {
if (isset($a2['type'])) {
Expand Down
8 changes: 4 additions & 4 deletions AbstractFormFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function container(callable $callback): string

$out = "";
$out .= "<div class=\"mb-15\" data-count=\"{$length}\">";
if (!is_null($this->label)) {
if ($this->label !== null) {
$boolLength = (isset($this->validate['length'][0]) && $this->validate['length'][0] > 0);
$req = ($boolLength) ? "*" : "";
$out .= "<label>{$this->label}<span class=\"req\">{$req}</span><div class=\"message hide\"></div></label>";
}
if (!is_null($this->description)) {
if ($this->description !== null) {
$out .= "<div class=\"description legend\">{$this->description}</div>";
}
$out .= $callback();
Expand Down Expand Up @@ -183,10 +183,10 @@ public function group()
$lastKey = $this->lastKey();
$out = "<div class=\"mb-20 group\" {$this->attr}data-key=\"{$lastKey}\">";

if (!is_null($this->label)) {
if ($this->label !== null) {
$out .= "<label>{$this->label}</label>";
}
if (!is_null($this->description)) {
if ($this->description !== null) {
$out .= "<div class=\"legend mb-20 v3\">{$this->description}</div>";
}

Expand Down
11 changes: 6 additions & 5 deletions Arguments.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @Package: MaplePHP - Form builder engine
* @Author: Daniel Ronkainen
Expand Down Expand Up @@ -128,7 +129,7 @@ public function validate(array $arr): self
*/
public function default(?string $default): self
{
if (!is_null($default)) {
if ($default !== null) {
$this->default = $default;
}
return $this;
Expand All @@ -149,7 +150,7 @@ public function name(string $name): self

$this->inst->setValidateData($this->identifier, [
"id" => ($this->rows['id'] ?? 0),
"type" => (!is_null($this->fieldType) ? $this->fieldType : "text"),
"type" => ($this->fieldType !== null ? $this->fieldType : "text"),
"validate" => $this->validate,
"default" => $this->default,
"config" => $this->config
Expand All @@ -168,7 +169,7 @@ public function name(string $name): self
*/
public function value(?string $val = null): self
{
if (!is_null($val)) {
if ($val !== null) {
$this->value = $val;
} elseif (is_array($this->nameExp) && count($this->nameExp) > 0) {
$this->valueShifting($this->nameExp, $val);
Expand All @@ -185,7 +186,7 @@ public function value(?string $val = null): self
protected function valueShifting(array $exp, ?string $fallback): void
{
$values = $this->inst->getValues();
if (!is_null($values)) {
if ($values !== null) {
// Can convert obj to arr if needed
$values = (array)$values;
$first = array_shift($exp);
Expand All @@ -195,7 +196,7 @@ protected function valueShifting(array $exp, ?string $fallback): void
$this->value = $this->json($this->value);
foreach ($exp as $item) {
$item = htmlentities(trim($item));
if (!is_null($this->value)) {
if ($this->value !== null) {
$this->value = (isset($this->value[$item]) && is_array($this->value[$item])) ? $this->value[$item] : $fallback;
}
}
Expand Down
1 change: 0 additions & 1 deletion Examples/TestFormFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

class TestFormFields extends AbstractFormFields
{

/**
* Input text (Take a look at AbstractFormFields)
* @return string
Expand Down
14 changes: 7 additions & 7 deletions Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Fields extends AbstractFields implements FieldInterface
{
private $buildArr;
private $validateData = array();
private $validateData = [];

/**
* Get form name
Expand All @@ -41,7 +41,7 @@ public function getFormData(): array
*/
public function hasFormData(?string $name = null): bool
{
if (is_null($name)) {
if ($name === null) {
$name = $this->name;
}
return (isset($this->inpArr[$name]));
Expand Down Expand Up @@ -81,7 +81,7 @@ public function getValues(): mixed
*/
public function add($fields, ?string $name = null): self
{
if (is_null($name)) {
if ($name === null) {
$name = $this->name;
}
$this->inpArr[$name] = $fields;
Expand Down Expand Up @@ -171,7 +171,7 @@ public function getValidateDataRow(string $key): array
*/
public function build(): void
{
$this->validateData = array();
$this->validateData = [];
foreach ($this->inpArr as $key => $array) {
$this->buildArr[$key] = $this->html($array);
}
Expand All @@ -195,7 +195,7 @@ public function withBuild(): static
*/
public function get(): string
{
if (!is_null($this->type) && method_exists($this->fields, $this->type)) {
if ($this->type !== null && method_exists($this->fields, $this->type)) {
$get = call_user_func_array([$this->fields, $this->type], $this->args);
return $get;
}
Expand All @@ -209,7 +209,7 @@ public function get(): string
*/
public function hasForm(?string $name = null): bool
{
if (is_null($name)) {
if ($name === null) {
$name = $this->name;
}
return (isset($this->buildArr[$name]));
Expand All @@ -222,7 +222,7 @@ public function hasForm(?string $name = null): bool
*/
public function getForm(?string $name = null): string
{
if (is_null($name)) {
if ($name === null) {
$name = $this->name;
}
if (!$this->hasFormData($name)) {
Expand Down
16 changes: 8 additions & 8 deletions Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace MaplePHP\Form;

use MaplePHP\Form\Interfaces\FieldInterface;
use MaplePHP\Validate\Inp;
use MaplePHP\Validate\Validator;
use MaplePHP\DTO\Format\Local;

class Validate
Expand All @@ -14,8 +14,8 @@ class Validate
private $validArr;
private $fields;
private $post;
private $request = array();
private $files = array();
private $request = [];
private $files = [];
private $local;
private $value;
private $length = 0;
Expand Down Expand Up @@ -80,7 +80,7 @@ public function execute(): ?array
$this->fields->setValues($this->post);
$this->fields->build();

$postArr = array();
$postArr = [];
$arr = $this->fields->getValidateData();
foreach ($arr as $name => $arr) {
$field = $this->fields->{$arr['type']}();
Expand All @@ -95,7 +95,7 @@ public function execute(): ?array
if (isset($arr['validate'])) {
$this->value = htmlspecialchars((string)$value);
$this->length = strlen($this->value);
$this->validate = Inp::value($this->value);
$this->validate = Validator::value($this->value);

if ($error = $this->isInvalid($arr['validate'])) {
$this->validArr[$nameKey] = $error;
Expand Down Expand Up @@ -151,7 +151,7 @@ protected function isInvalid($arr): bool|array
private function validateWithMethod(string $method, ?array $args, bool $valFilledIn): bool
{
if (!is_array($args)) {
$args = array();
$args = [];
}
$object = call_user_func_array([$this->validate, $method], $args);
return (($valFilledIn && $this->length > 0 && !$object) || (!$valFilledIn && !$object));
Expand All @@ -175,9 +175,9 @@ private function buildMessage(string $method, ?array $args, string $message): ar
* @param array $args sprint push possible values
* @return string
*/
protected function message(string $key, array $args = array())
protected function message(string $key, array $args = [])
{
if (!is_null($this->local)) {
if ($this->local !== null) {
return $this->local->get($key, $key, $args);
}
return $key;
Expand Down
57 changes: 31 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
{
"name": "maplephp/form",
"type": "library",
"description": "Develop advanced, consistent, and secure forms that are also very easy to validate.",
"keywords": ["form builder", "form", "builder", "validate"],
"homepage": "https://wazabii.se",
"license": "Apache-2.0",
"authors": [
{
"name": "Daniel Ronkainen",
"email": "daniel.ronkainen@wazabii.se"
},
{
"name": "MaplePHP",
"homepage": "https://wazabii.se"
}
],
"require": {
"php": ">=8.0",
"maplephp/dto": "^1.0",
"maplephp/validate": "^1.0"
"name": "maplephp/form",
"type": "library",
"description": "Develop advanced, consistent, and secure forms that are also very easy to validate.",
"keywords": [
"form builder",
"form",
"builder",
"validate"
],
"homepage": "https://wazabii.se",
"license": "Apache-2.0",
"authors": [
{
"name": "Daniel Ronkainen",
"email": "daniel.ronkainen@wazabii.se"
},
"autoload": {
"psr-4": {
"MaplePHP\\Form\\": ""
}
},
"minimum-stability": "dev"
{
"name": "MaplePHP",
"homepage": "https://wazabii.se"
}
],
"require": {
"php": ">=8.2",
"maplephp/dto": "^3.1",
"maplephp/validate": "^2.0"
},
"autoload": {
"psr-4": {
"MaplePHP\\Form\\": ""
}
},
"minimum-stability": "dev"
}