adrema/app/Lib/Editor/ConditionResolver.php

33 lines
776 B
PHP
Raw Normal View History

<?php
namespace App\Lib\Editor;
abstract class ConditionResolver
{
/**
2024-04-23 23:48:09 +02:00
* @param array<string, mixed> $ifs
*/
2024-04-23 23:48:09 +02:00
abstract public function filterCondition(string $mode, array $ifs): bool;
/**
* @param array<string, mixed> $content
* @return array<string, mixed>
*/
2024-04-23 23:48:09 +02:00
public function makeBlocks(array $content): array
{
2024-04-20 00:29:32 +02:00
return array_filter(data_get($content, 'blocks', []), fn ($block) => $this->filterBlock($block));
}
2024-04-23 23:48:09 +02:00
/**
2024-04-24 15:39:07 +02:00
* @param array<string, mixed> $block
2024-04-23 23:48:09 +02:00
*/
public function filterBlock(array $block): bool
{
$mode = data_get($block, 'tunes.condition.mode', 'any');
$ifs = data_get($block, 'tunes.condition.ifs', []);
return $this->filterCondition($mode, $ifs);
}
}