new: [helper:valueGetter] Helper to help execute closure to get a value if needed

pull/93/head
Sami Mokaddem 2022-01-21 09:07:21 +01:00
parent f8c775ba03
commit b8bc79e072
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,24 @@
<?php
namespace App\View\Helper;
use Cake\View\Helper;
class ValueGetterHelper extends Helper
{
public function get($target, $args=[])
{
$value = '';
if (is_callable($target)) {
$value = $this->eval($target, $args);
} else {
$value = h($target);
}
return $value;
}
private function eval($fun, $args=[])
{
return $fun($args);
}
}