2022-09-01 09:49:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Arendsen\FluxQueryBuilder\Type;
|
|
|
|
|
|
2023-03-08 21:20:20 +01:00
|
|
|
use Arendsen\FluxQueryBuilder\Type;
|
|
|
|
|
|
2022-09-01 09:49:14 +00:00
|
|
|
class FnType implements TypeInterface
|
|
|
|
|
{
|
2022-09-09 11:07:42 +00:00
|
|
|
/**
|
2023-03-08 21:20:20 +01:00
|
|
|
* @var array $params
|
2022-09-09 11:07:42 +00:00
|
|
|
*/
|
2023-03-08 21:20:20 +01:00
|
|
|
protected $params;
|
2022-09-09 11:07:42 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string $content
|
|
|
|
|
*/
|
|
|
|
|
protected $content;
|
|
|
|
|
|
2023-03-08 21:20:20 +01:00
|
|
|
private function __construct(array $params)
|
|
|
|
|
{
|
|
|
|
|
$this->params = $params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function params(array $params)
|
|
|
|
|
{
|
|
|
|
|
return new self($params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withBody(string $content)
|
2022-09-01 09:49:14 +00:00
|
|
|
{
|
2022-09-09 11:07:42 +00:00
|
|
|
$this->content = $content;
|
2023-03-08 21:20:20 +01:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withBlock(string $content)
|
|
|
|
|
{
|
|
|
|
|
$this->content = '{ ' . $content . ' }';
|
|
|
|
|
return $this;
|
2022-09-01 09:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __toString(): string
|
|
|
|
|
{
|
2023-03-08 21:20:20 +01:00
|
|
|
array_walk($this->params, function (&$value, $key) {
|
|
|
|
|
if (is_string($key)) {
|
|
|
|
|
$value = $key . ' = ' . new Type($value);
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-09-09 11:07:42 +00:00
|
|
|
|
2023-03-08 21:20:20 +01:00
|
|
|
return '(' . implode(', ', $this->params) . ') => ' . $this->content;
|
2022-09-01 09:49:14 +00:00
|
|
|
}
|
|
|
|
|
}
|