-
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 #41 from mpscholten/min-max-parser
[WIP] min/max parser and restructured namespaces (ValidationParser)
- Loading branch information
Showing
24 changed files
with
729 additions
and
18 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
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
5 changes: 4 additions & 1 deletion
5
src/AbstractBetweenParser.php → src/Validator/AbstractBetweenParser.php
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,25 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
use MPScholten\RequestParser\AbstractValueParser; | ||
use MPScholten\RequestParser\Config; | ||
|
||
abstract class AbstractLargerThanOrEqualToParser extends AbstractValueParser | ||
{ | ||
protected $minValue; | ||
|
||
public function __construct(Config $config, $name, $value, $minValue) | ||
{ | ||
$this->minValue = $minValue; | ||
parent::__construct($config, $name, $value); | ||
} | ||
|
||
protected function parse($value) | ||
{ | ||
if ($value >= $this->minValue) { | ||
return $value; | ||
} | ||
return null; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
use MPScholten\RequestParser\AbstractValueParser; | ||
use MPScholten\RequestParser\Config; | ||
|
||
abstract class AbstractLargerThanParser extends AbstractValueParser | ||
{ | ||
protected $minValue; | ||
|
||
public function __construct(Config $config, $name, $value, $minValue) | ||
{ | ||
$this->minValue = $minValue; | ||
parent::__construct($config, $name, $value); | ||
} | ||
|
||
protected function parse($value) | ||
{ | ||
if ($value > $this->minValue) { | ||
return $value; | ||
} | ||
return null; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
use MPScholten\RequestParser\AbstractValueParser; | ||
use MPScholten\RequestParser\Config; | ||
|
||
abstract class AbstractSmallerThanOrEqualToParser extends AbstractValueParser | ||
{ | ||
protected $maxValue; | ||
|
||
public function __construct(Config $config, $name, $value, $maxValue) | ||
{ | ||
$this->maxValue = $maxValue; | ||
parent::__construct($config, $name, $value); | ||
} | ||
|
||
protected function parse($value) | ||
{ | ||
if ($value <= $this->maxValue) { | ||
return $value; | ||
} | ||
return null; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
use MPScholten\RequestParser\AbstractValueParser; | ||
use MPScholten\RequestParser\Config; | ||
|
||
abstract class AbstractSmallerThanParser extends AbstractValueParser | ||
{ | ||
protected $maxValue; | ||
|
||
public function __construct(Config $config, $name, $value, $maxValue) | ||
{ | ||
$this->maxValue = $maxValue; | ||
parent::__construct($config, $name, $value); | ||
} | ||
|
||
protected function parse($value) | ||
{ | ||
if ($value < $this->maxValue) { | ||
return $value; | ||
} | ||
return null; | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/FloatBetweenParser.php → src/Validator/FloatBetweenParser.php
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,44 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
class FloatLargerThanOrEqualToParser extends AbstractLargerThanOrEqualToParser | ||
{ | ||
protected function describe() | ||
{ | ||
return "a float larger than or equal to $this->minValue"; | ||
} | ||
|
||
/** | ||
* @param $value | ||
* @return int | ||
*/ | ||
protected function parse($value) | ||
{ | ||
if (!is_numeric($value)) { | ||
return null; | ||
} | ||
$value = (float) $value; | ||
return parent::parse($value); | ||
} | ||
|
||
/** | ||
* @param float $defaultValue | ||
* @return float | ||
*/ | ||
public function defaultsTo($defaultValue) | ||
{ | ||
return parent::defaultsTo($defaultValue); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
* @param string $invalidValueMessage | ||
* @param string $notFoundMessage | ||
* @return float | ||
*/ | ||
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,44 @@ | ||
<?php | ||
|
||
namespace MPScholten\RequestParser\Validator; | ||
|
||
class FloatLargerThanParser extends AbstractLargerThanParser | ||
{ | ||
protected function describe() | ||
{ | ||
return "a float larger than $this->minValue"; | ||
} | ||
|
||
/** | ||
* @param $value | ||
* @return int | ||
*/ | ||
protected function parse($value) | ||
{ | ||
if (!is_numeric($value)) { | ||
return null; | ||
} | ||
$value = (float) $value; | ||
return parent::parse($value); | ||
} | ||
|
||
/** | ||
* @param float $defaultValue | ||
* @return float | ||
*/ | ||
public function defaultsTo($defaultValue) | ||
{ | ||
return parent::defaultsTo($defaultValue); | ||
} | ||
|
||
/** | ||
* @throws \Exception | ||
* @param string $invalidValueMessage | ||
* @param string $notFoundMessage | ||
* @return float | ||
*/ | ||
public function required($invalidValueMessage = null, $notFoundMessage = null) | ||
{ | ||
return parent::required($invalidValueMessage, $notFoundMessage); | ||
} | ||
} |
Oops, something went wrong.