Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
441 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Apitte\Core\Mapping\Parameter; | ||
|
||
use Apitte\Core\Exception\Logical\InvalidArgumentException; | ||
use Apitte\Core\Schema\EndpointParameter; | ||
|
||
class BooleanTypeMapper implements ITypeMapper | ||
{ | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function normalize($value, EndpointParameter $parameter): ?bool | ||
{ | ||
if ($value === null || $value === '') { | ||
return null; | ||
} | ||
|
||
if (is_bool($value)) { | ||
return $value; | ||
} | ||
|
||
if ($value === '1' || $value === 'true') { | ||
return true; | ||
} | ||
|
||
if ($value === '0' || $value === 'false') { | ||
return false; | ||
} | ||
|
||
throw new InvalidArgumentException(sprintf( | ||
'Parameter "%s" should be of type boolean. Pass "true" or "1" for true and "false" or "0" for false.', | ||
$parameter->getName() | ||
)); | ||
} | ||
|
||
} |
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,41 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Apitte\Core\Mapping\Parameter; | ||
|
||
use Apitte\Core\Exception\Logical\InvalidArgumentException; | ||
use Apitte\Core\Schema\EndpointParameter; | ||
use DateTimeImmutable; | ||
use TypeError; | ||
|
||
class DateTimeTypeMapper implements ITypeMapper | ||
{ | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function normalize($value, EndpointParameter $parameter): ?DateTimeImmutable | ||
{ | ||
if ($value === null || $value === '') { | ||
return null; | ||
} | ||
|
||
try { | ||
$value = DateTimeImmutable::createFromFormat(DATE_ATOM, $value); | ||
} catch (TypeError $e) { | ||
throw new InvalidArgumentException(sprintf( | ||
'Parameter "%s" should be of type datetime in format ISO 8601 (Y-m-d\TH:i:sP).', | ||
$parameter->getName() | ||
)); | ||
} | ||
|
||
if ($value !== false) { | ||
return $value; | ||
} | ||
|
||
throw new InvalidArgumentException(sprintf( | ||
'Parameter "%s" should be of type datetime in format ISO 8601 (Y-m-d\TH:i:sP).', | ||
$parameter->getName() | ||
)); | ||
} | ||
|
||
} |
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
Oops, something went wrong.