2022-08-08 15:37:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Arendsen\FluxQueryBuilder\Function;
|
|
|
|
|
|
2022-08-11 12:42:43 +00:00
|
|
|
use Arendsen\FluxQueryBuilder\Formatters;
|
|
|
|
|
|
2022-08-08 15:37:04 +00:00
|
|
|
class Reduce extends Base {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array $settings
|
|
|
|
|
*/
|
|
|
|
|
private $settings;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var array $identity
|
|
|
|
|
*/
|
|
|
|
|
private $identity;
|
|
|
|
|
|
|
|
|
|
public function __construct(array $settings, array $identity)
|
|
|
|
|
{
|
|
|
|
|
$this->settings = $settings;
|
|
|
|
|
$this->identity = $identity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
|
{
|
|
|
|
|
return '|> reduce(fn: (r, accumulator) => ({' . implode(', ', $this->formatSettings($this->settings)) . '}), ' .
|
2022-08-11 12:42:43 +00:00
|
|
|
'identity: {' . Formatters::toFluxAssociativeArrayString($this->identity) . '}) ';
|
2022-08-08 15:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function formatSettings(array $settings)
|
|
|
|
|
{
|
|
|
|
|
array_walk($settings, function(&$value, $key) {
|
|
|
|
|
$value = $key . ': ' . $value;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return $settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|