Initial SQLite development (#1)
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
30
src/Mapper/StringMapper.php
Normal file
30
src/Mapper/StringMapper.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace BitBadger\PDODocument\Mapper;
|
||||
|
||||
/**
|
||||
* Map a string result from the
|
||||
*
|
||||
* @implements Mapper<string>
|
||||
*/
|
||||
class StringMapper implements Mapper
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $fieldName The name of the field to be retrieved as a string
|
||||
*/
|
||||
public function __construct(public string $fieldName) { }
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function map(array $result): ?string
|
||||
{
|
||||
return match (false) {
|
||||
key_exists($this->fieldName, $result) => null,
|
||||
is_string($result[$this->fieldName]) => "{$result[$this->fieldName]}",
|
||||
default => $result[$this->fieldName]
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user