-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Zacharias Luiten <[email protected]>
- Loading branch information
Showing
13 changed files
with
935 additions
and
145 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
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,91 @@ | ||
<?php | ||
|
||
/** | ||
* @see https://github.com/laminas-api-tools/api-tools-doctrine-querybuilder for the canonical source repository | ||
* @copyright https://github.com/laminas-api-tools/api-tools-doctrine-querybuilder/blob/master/COPYRIGHT.md | ||
* @license https://github.com/laminas-api-tools/api-tools-doctrine-querybuilder/blob/master/LICENSE.md New BSD License | ||
*/ | ||
|
||
namespace Laminas\ApiTools\Doctrine\QueryBuilder\Filter\ODM; | ||
|
||
use DateTime; | ||
use DateTimeImmutable; | ||
use Laminas\ApiTools\Doctrine\QueryBuilder\Filter\TypeCastInterface; | ||
|
||
class TypeCaster implements TypeCastInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function typeCastField($metadata, string $field, $value, string $format = null, bool $doNotTypecastDatetime = false) | ||
{ | ||
if (! isset($metadata->fieldMappings[$field])) { | ||
return $value; | ||
} | ||
|
||
switch ($metadata->fieldMappings[$field]['type']) { | ||
case 'int': | ||
settype($value, 'integer'); | ||
break; | ||
case 'boolean': | ||
settype($value, 'boolean'); | ||
break; | ||
case 'float': | ||
settype($value, 'float'); | ||
break; | ||
case 'string': | ||
settype($value, 'string'); | ||
break; | ||
case 'bin_data_custom': | ||
break; | ||
case 'bin_data_func': | ||
break; | ||
case 'bin_data_md5': | ||
break; | ||
case 'bin_data': | ||
break; | ||
case 'bin_data_uuid': | ||
break; | ||
case 'collection': | ||
break; | ||
case 'custom_id': | ||
break; | ||
case 'date': | ||
if ($value && ! $doNotTypecastDatetime) { | ||
if (! $format) { | ||
$format = 'Y-m-d H:i:s'; | ||
} | ||
$value = DateTime::createFromFormat($format, $value); | ||
} | ||
break; | ||
case 'date_immutable': | ||
if ($value && ! $doNotTypecastDatetime) { | ||
if (! $format) { | ||
$format = 'Y-m-d H:i:s'; | ||
} | ||
$value = DateTimeImmutable::createFromFormat($format, $value); | ||
} | ||
break; | ||
case 'file': | ||
break; | ||
case 'hash': | ||
break; | ||
case 'id': | ||
break; | ||
case 'increment': | ||
break; | ||
case 'key': | ||
break; | ||
case 'object_id': | ||
break; | ||
case 'raw_type': | ||
break; | ||
case 'timestamp': | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return $value; | ||
} | ||
} |
Oops, something went wrong.