Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
BlockPool Class Reference

Public Member Functions

 __construct (BlockFactory $blockFactory)
 
 add ($name, $class, array $arguments=[])
 
 get ($name=null)
 

Protected Attributes

 $blockFactory
 
 $blocks = []
 

Detailed Description

Class BlockPool

Definition at line 14 of file BlockPool.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( BlockFactory  $blockFactory)

Constructor

Parameters
BlockFactory$blockFactory

Definition at line 34 of file BlockPool.php.

35  {
36  $this->blockFactory = $blockFactory;
37  }

Member Function Documentation

◆ add()

add (   $name,
  $class,
array  $arguments = [] 
)

Add a block

Parameters
string$name
string$class
array$arguments[optional]
Returns
BlockPool
Exceptions

Definition at line 48 of file BlockPool.php.

49  {
50  if (!class_exists($class)) {
51  throw new \InvalidArgumentException(
52  (string)new \Magento\Framework\Phrase('Invalid Block class name: %1', [$class])
53  );
54  }
55 
56  $block = $this->blockFactory->createBlock($class, $arguments);
57 
58  $this->blocks[$name] = $block;
59 
60  return $this;
61  }
$block
Definition: block.php:8
$_option $_optionId $class
Definition: date.phtml:13
$arguments
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ get()

get (   $name = null)

Get blocks

Parameters
string$name
Returns
BlockInterface|null

Definition at line 69 of file BlockPool.php.

70  {
71  if (!isset($name)) {
72  return $this->blocks;
73  }
74 
75  return $this->blocks[$name] ?? null;
76  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

Field Documentation

◆ $blockFactory

$blockFactory
protected

Definition at line 20 of file BlockPool.php.

◆ $blocks

$blocks = []
protected

Definition at line 27 of file BlockPool.php.


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