query->all(); } $key_exists = array_key_exists($property, $all); if (!$key_exists && $default != null) { $all[$property] = $default; $key_exists = true; } if (!$key_exists) { if ($required) { throw (new Errors())->errorRequired($property, "string"); } else { // value not exists return null; } } else if (is_string($all[$property])) { return $all[$property]; } else { throw (new Errors())->errorString($property); } } else { return null; } } /** * Throws exception if not integer. * @param Request|array $all Contains array with query. * @param string $property Contains the name of property * @param boolean $required Check if property exists in request * @param mixed $default Default value. * @return Integer Return integer or if the property not exists. * @throws Error Throws errors. */ function integer($all, $property, $required = true, $default = null) { if ($all != null) { if ($all instanceof Request) { $all = $all->query->all(); } $key_exists = array_key_exists($property, $all); if (!$key_exists && $default != null) { $all[$property] = $default; $key_exists = true; } if (!$key_exists) { if ($required) { throw (new Errors())->errorRequired($property, "integer"); } else { // value not exists return null; } } else if (is_numeric($all[$property])) { return $all[$property]; } else { throw (new Errors())->errorInteger($property); } } else { return null; } } /** * Throws exception if not integer. * @param string $property Contains the name of property * @param string $value Value for array key * @return string Return strings with format 'filters[$property]=$value or null. * @throws Error Throws errors. */ public function filters($property, $value) { if ($value != null) { $value = "filters[$property]=$value"; } return $value; } /** * Throws exception if not boolean. * @param Request|array $all Contains array with query. * @param string $property Contains the name of property * @param boolean $required Check if property exists in request * @param mixed $default Default value. * @return integer Return integer 0, 1 or null. * @throws Error Throws errors. */ function boolean($all, $property, $required = true, $default = null) { if ($all != null) { if ($all instanceof Request) { $all = $all->query->all(); } $key_exists = array_key_exists($property, $all); if (!$key_exists && $default != null) { $all[$property] = $default; $key_exists = true; } if (!$key_exists) { if ($required) { throw (new Errors())->errorRequired($property, "boolean"); } else { // value not exists return null; } } else if (is_bool($all[$property]) || in_array(strtolower($all[$property]),['true','false','0','1'])) { $bool = filter_var( $all[$property], FILTER_VALIDATE_BOOLEAN ); return (int)$bool; } else { throw (new Errors())->errorBoolean($property); } } else { return null; } } }