add multiple jalali date format validator
This commit is contained in:
1 parent
775dcc4198
commit
30bbeefb1c
2 files changed
+35
-14
No files matched your search
@@ -16,7 +16,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDate($attribute, $value, $parameters)
|
public function validateDate($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) ? $parameters[0] : 'Y/m/d';
|
$format = count($parameters) ? $parameters[0] : 'Y/m/d';
|
||||||
@@ -30,6 +30,23 @@ class JalaliValidator
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if an input is a valid Jalali date with the specified format
|
||||||
|
* @param string $attribute
|
||||||
|
* @param string $value
|
||||||
|
* @param array $parameters
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function validateDateMultiFormat(string $attribute, string $value, array $parameters): bool
|
||||||
|
{
|
||||||
|
foreach ($parameters as $format) {
|
||||||
|
if ($this->validateDate($attribute, $value, $format)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if an input is a valid Jalali date with the specified format and
|
* Determines if an input is a valid Jalali date with the specified format and
|
||||||
* it is equal a given date
|
* it is equal a given date
|
||||||
@@ -40,7 +57,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateEqual($attribute, $value, $parameters)
|
public function validateDateEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
@@ -64,7 +81,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateNotEqual($attribute, $value, $parameters)
|
public function validateDateNotEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
@@ -87,7 +104,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateTime($attribute, $value, $parameters)
|
public function validateDateTime($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +129,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateTimeEqual($attribute, $value, $parameters)
|
public function validateDateTimeEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
@@ -136,7 +153,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateTimeNotEqual($attribute, $value, $parameters)
|
public function validateDateTimeNotEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
@@ -160,7 +177,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateAfter($attribute, $value, $parameters)
|
public function validateDateAfter($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
@@ -184,7 +201,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateAfterEqual($attribute, $value, $parameters)
|
public function validateDateAfterEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
@@ -208,7 +225,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateTimeAfter($attribute, $value, $parameters)
|
public function validateDateTimeAfter($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
@@ -232,7 +249,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateTimeAfterEqual($attribute, $value, $parameters)
|
public function validateDateTimeAfterEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
@@ -256,7 +273,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateBefore($attribute, $value, $parameters)
|
public function validateDateBefore($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
@@ -280,7 +297,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateBeforeEqual($attribute, $value, $parameters)
|
public function validateDateBeforeEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d';
|
||||||
@@ -304,7 +321,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateTimeBefore($attribute, $value, $parameters)
|
public function validateDateTimeBefore($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
@@ -328,7 +345,7 @@ class JalaliValidator
|
|||||||
*/
|
*/
|
||||||
public function validateDateTimeBeforeEqual($attribute, $value, $parameters)
|
public function validateDateTimeBeforeEqual($attribute, $value, $parameters)
|
||||||
{
|
{
|
||||||
if (! is_string($value)) {
|
if (!is_string($value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
$format = count($parameters) > 1 ? $parameters[1] : 'Y/m/d H:i:s';
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ class VertaServiceProvider extends ServiceProvider
|
|||||||
'extend' => 'validateDate',
|
'extend' => 'validateDate',
|
||||||
'replacer' => 'replaceDateOrDatetime',
|
'replacer' => 'replaceDateOrDatetime',
|
||||||
],
|
],
|
||||||
|
'jdate_multi_format' => [
|
||||||
|
'extend' => 'validateDateMultiFormat',
|
||||||
|
'replacer' => 'replaceDateOrDatetime',
|
||||||
|
],
|
||||||
'jdate_equal' => [
|
'jdate_equal' => [
|
||||||
'extend' => 'validateDateEqual',
|
'extend' => 'validateDateEqual',
|
||||||
'replacer' => 'replaceDateAfterOrBeforeOrEqual',
|
'replacer' => 'replaceDateAfterOrBeforeOrEqual',
|
||||||
|
|||||||
Reference in new issue
Block a user