Add Formatters
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
eb6568de10
commit
328094d803
8 changed files with 61 additions and 31 deletions
39
src/Formatters.php
Normal file
39
src/Formatters.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder;
|
||||
|
||||
class Formatters {
|
||||
|
||||
public static function valueToString($value): string
|
||||
{
|
||||
if(is_string($value))
|
||||
{
|
||||
return '"' . $value . '"';
|
||||
}
|
||||
elseif(is_bool($value))
|
||||
{
|
||||
return $value ? 'true' : 'false';
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public static function toFluxArrayString(array $array): string
|
||||
{
|
||||
$array = array_map(function($column) {
|
||||
return self::valueToString($column);
|
||||
}, $array);
|
||||
|
||||
return implode(', ', $array);
|
||||
}
|
||||
|
||||
public static function toFluxAssociativeArrayString(array $array): string
|
||||
{
|
||||
array_walk($array, function(&$value, $key) {
|
||||
$value = $key . ': ' . self::valueToString($value);
|
||||
});
|
||||
|
||||
return implode(', ', $array);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue