-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from kasitmp/add-string-length-validation
Add string length validation
- Loading branch information
Showing
8 changed files
with
370 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
class StringLengthBetween extends AbstractBetweenParser | ||
{ | ||
protected function describe() | ||
{ | ||
return "a string with character length between $this->minValue and $this->maxValue"; | ||
} | ||
|
||
/** | ||
* @param $value | ||
* @return int | ||
*/ | ||
protected function parse($value) | ||
{ | ||
if (strlen($value) >= $this->minValue && strlen($value) <= $this->maxValue) { | ||
return $value; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @param string $defaultValue | ||
* @return string | ||
*/ | ||
public function defaultsTo($defaultValue) | ||
{ | ||
return parent::defaultsTo($defaultValue); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
* @param string $invalidValueMessage | ||
* @param string $notFoundMessage | ||
* @return string | ||
*/ | ||
public function required($invalidValueMessage = null, $notFoundMessage = null) | ||
{ | ||
return parent::required($invalidValueMessage, $notFoundMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
class StringLengthLargerThanOrEqualToParser extends AbstractLargerThanOrEqualToParser | ||
{ | ||
protected function describe() | ||
{ | ||
return "a string longer than or equal to $this->minValue characters"; | ||
} | ||
|
||
/** | ||
* @param $value | ||
* @return int | ||
*/ | ||
protected function parse($value) | ||
{ | ||
if (strlen($value) >= $this->minValue) { | ||
return $value; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @param string $defaultValue | ||
* @return string | ||
*/ | ||
public function defaultsTo($defaultValue) | ||
{ | ||
return parent::defaultsTo($defaultValue); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
* @param string $invalidValueMessage | ||
* @param string $notFoundMessage | ||
* @return string | ||
*/ | ||
public function required($invalidValueMessage = null, $notFoundMessage = null) | ||
{ | ||
return parent::required($invalidValueMessage, $notFoundMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
class StringLengthLargerThanParser extends AbstractLargerThanParser | ||
{ | ||
protected function describe() | ||
{ | ||
return "a string longer than $this->minValue characters"; | ||
} | ||
|
||
/** | ||
* @param $value | ||
* @return int | ||
*/ | ||
protected function parse($value) | ||
{ | ||
if (strlen($value) > $this->minValue) { | ||
return $value; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @param string $defaultValue | ||
* @return string | ||
*/ | ||
public function defaultsTo($defaultValue) | ||
{ | ||
return parent::defaultsTo($defaultValue); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
* @param string $invalidValueMessage | ||
* @param string $notFoundMessage | ||
* @return string | ||
*/ | ||
public function required($invalidValueMessage = null, $notFoundMessage = null) | ||
{ | ||
return parent::required($invalidValueMessage, $notFoundMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
class StringLengthSmallerThanOrEqualToParser extends AbstractSmallerThanOrEqualToParser | ||
{ | ||
protected function describe() | ||
{ | ||
return "a string shorter than or equal to $this->maxValue characters"; | ||
} | ||
|
||
/** | ||
* @param $value | ||
* @return int | ||
*/ | ||
protected function parse($value) | ||
{ | ||
if (strlen($value) <= $this->maxValue) { | ||
return $value; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @param string $defaultValue | ||
* @return string | ||
*/ | ||
public function defaultsTo($defaultValue) | ||
{ | ||
return parent::defaultsTo($defaultValue); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
* @param string $invalidValueMessage | ||
* @param string $notFoundMessage | ||
* @return string | ||
*/ | ||
public function required($invalidValueMessage = null, $notFoundMessage = null) | ||
{ | ||
return parent::required($invalidValueMessage, $notFoundMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
class StringLengthSmallerThanParser extends AbstractSmallerThanParser | ||
{ | ||
protected function describe() | ||
{ | ||
return "a string shorter than $this->maxValue characters"; | ||
} | ||
|
||
/** | ||
* @param $value | ||
* @return int | ||
*/ | ||
protected function parse($value) | ||
{ | ||
if (strlen($value) < $this->maxValue) { | ||
return $value; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @param string $defaultValue | ||
* @return string | ||
*/ | ||
public function defaultsTo($defaultValue) | ||
{ | ||
return parent::defaultsTo($defaultValue); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
* @param string $invalidValueMessage | ||
* @param string $notFoundMessage | ||
* @return string | ||
*/ | ||
public function required($invalidValueMessage = null, $notFoundMessage = null) | ||
{ | ||
return parent::required($invalidValueMessage, $notFoundMessage); | ||
} | ||
} |
Oops, something went wrong.