Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Php.php
Go to the documentation of this file.
1 <?php
7 
10 
14 class Php implements TemplateEngineInterface
15 {
21  protected $_currentBlock;
22 
28  protected $_helperFactory;
29 
35  public function __construct(\Magento\Framework\ObjectManagerInterface $helperFactory)
36  {
37  $this->_helperFactory = $helperFactory;
38  }
39 
52  public function render(BlockInterface $block, $fileName, array $dictionary = [])
53  {
54  ob_start();
55  try {
56  $tmpBlock = $this->_currentBlock;
57  $this->_currentBlock = $block;
58  extract($dictionary, EXTR_SKIP);
59  include $fileName;
60  $this->_currentBlock = $tmpBlock;
61  } catch (\Exception $exception) {
62  ob_end_clean();
63  throw $exception;
64  }
66  $output = ob_get_clean();
67  return $output;
68  }
69 
80  public function __call($method, $args)
81  {
82  return call_user_func_array([$this->_currentBlock, $method], $args);
83  }
84 
94  public function __isset($name)
95  {
96  return isset($this->_currentBlock->{$name});
97  }
98 
108  public function __get($name)
109  {
110  return $this->_currentBlock->{$name};
111  }
112 
120  public function helper($className)
121  {
122  $helper = $this->_helperFactory->get($className);
123  if (false === $helper instanceof \Magento\Framework\App\Helper\AbstractHelper) {
124  throw new \LogicException($className . ' doesn\'t extends Magento\Framework\App\Helper\AbstractHelper');
125  }
126 
127  return $helper;
128  }
129 }
$helper
Definition: iframe.phtml:13
$block
Definition: block.php:8
$fileName
Definition: translate.phtml:15
$method
Definition: info.phtml:13
render(BlockInterface $block, $fileName, array $dictionary=[])
Definition: Php.php:52
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31
if(!isset($_GET['name'])) $name
Definition: log.php:14
__construct(\Magento\Framework\ObjectManagerInterface $helperFactory)
Definition: Php.php:35