Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HelperMethod.php
Go to the documentation of this file.
1 <?php
7 
10 
15 {
19  private $objectManager;
20 
24  private $paramsInterpreter;
25 
30  public function __construct(ObjectManagerInterface $objectManager, NamedParams $paramsInterpreter)
31  {
32  $this->objectManager = $objectManager;
33  $this->paramsInterpreter = $paramsInterpreter;
34  }
35 
40  public function evaluate(array $data)
41  {
42  if (!isset($data['helper']) || substr_count($data['helper'], '::') != 1) {
43  throw new \InvalidArgumentException('Helper method name in format "\Class\Name::methodName" is expected.');
44  }
45  $helperMethod = $data['helper'];
46  list($helperClass, $methodName) = explode('::', $helperMethod, 2);
47  if (!method_exists($helperClass, $methodName)) {
48  throw new \InvalidArgumentException("Helper method '{$helperMethod}' does not exist.");
49  }
50  $methodParams = $this->paramsInterpreter->evaluate($data);
51  $methodParams = array_values($methodParams);
52  // Use positional argument binding instead of named binding
53  $helperInstance = $this->objectManager->get($helperClass);
54  return call_user_func_array([$helperInstance, $methodName], $methodParams);
55  }
56 }
$objectManager
Definition: bootstrap.php:17
__construct(ObjectManagerInterface $objectManager, NamedParams $paramsInterpreter)