Source of file FilterEmptyArraysLanguageProvider.php
Size: 1,043 Bytes - Last Modified: 2021-12-24T06:40:29+00:00
/var/www/docs.ssmods.com/process/src/src/FilterEmptyArraysLanguageProvider.php
12345678910111213141516171819202122232425262728293031323334353637383940 | <?php namespace ChristopherDarling\CacheIncludeFilterEmptyArrays; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; class FilterEmptyArraysLanguageProvider implements ExpressionFunctionProviderInterface { public function filterEmptyArrays($haystack) { foreach ($haystack as $key => $value) { if (is_array($value)) { $haystack[$key] = $this->filterEmptyArrays($haystack[$key]); } if (empty($haystack[$key])) { unset($haystack[$key]); } } return $haystack; } public function getFunctions() { return [ new ExpressionFunction('filterEmptyArrays', function ($str) { return sprintf('(is_array(%1$s) ? $this->filterEmptyArrays(%1$s) : %1$s)', $str); }, function ($arguments, $val) { if (!is_array($val)) { return $val; } return $this->filterEmptyArrays($val); }), ]; } } |