new: [helper:valueGetter] Helper to help execute closure to get a value if needed
parent
f8c775ba03
commit
b8bc79e072
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue