Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Php Class Reference
Inheritance diagram for Php:
TemplateEngineInterface

Public Member Functions

 __construct (\Magento\Framework\ObjectManagerInterface $helperFactory)
 
 render (BlockInterface $block, $fileName, array $dictionary=[])
 
 __call ($method, $args)
 
 __isset ($name)
 
 __get ($name)
 
 helper ($className)
 
- Public Member Functions inherited from TemplateEngineInterface
 render (\Magento\Framework\View\Element\BlockInterface $block, $templateFile, array $dictionary=[])
 

Protected Attributes

 $_currentBlock
 
 $_helperFactory
 

Detailed Description

Template engine that enables PHP templates to be used for rendering

Definition at line 14 of file Php.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\ObjectManagerInterface  $helperFactory)

Constructor

Parameters
\Magento\Framework\ObjectManagerInterface$helperFactory

Definition at line 35 of file Php.php.

36  {
37  $this->_helperFactory = $helperFactory;
38  }

Member Function Documentation

◆ __call()

__call (   $method,
  $args 
)

Redirects methods calls to the current block

This is needed because the templates are included in the context of this engine rather than in the context of the block.

Parameters
string$method
array$args
Returns
mixed

Definition at line 80 of file Php.php.

81  {
82  return call_user_func_array([$this->_currentBlock, $method], $args);
83  }
$method
Definition: info.phtml:13

◆ __get()

__get (   $name)

Allows read access to properties of the current block

This is needed because the templates are included in the context of this engine rather than in the context of the block.

Parameters
string$name
Returns
mixed

Definition at line 108 of file Php.php.

109  {
110  return $this->_currentBlock->{$name};
111  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ __isset()

__isset (   $name)

Redirects isset calls to the current block

This is needed because the templates are included in the context of this engine rather than in the context of the block.

Parameters
string$name
Returns
bool

Definition at line 94 of file Php.php.

95  {
96  return isset($this->_currentBlock->{$name});
97  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ helper()

helper (   $className)

Get helper singleton

Parameters
string$className
Returns
\Magento\Framework\App\Helper\AbstractHelper
Exceptions

Definition at line 120 of file Php.php.

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  }
$helper
Definition: iframe.phtml:13
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ render()

render ( BlockInterface  $block,
  $fileName,
array  $dictionary = [] 
)

Render output

Include the named PHTML template using the given block as the $this reference, though only public methods will be accessible.

Parameters
BlockInterface$block
string$fileName
array$dictionary
Returns
string
Exceptions

Get output buffer.

Definition at line 52 of file Php.php.

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  }
$block
Definition: block.php:8
$fileName
Definition: translate.phtml:15

Field Documentation

◆ $_currentBlock

$_currentBlock
protected

Definition at line 21 of file Php.php.

◆ $_helperFactory

$_helperFactory
protected

Definition at line 28 of file Php.php.


The documentation for this class was generated from the following file: