Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BlockPool.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Framework\View;
7 
10 
14 class BlockPool
15 {
20  protected $blockFactory;
21 
27  protected $blocks = [];
28 
35  {
36  $this->blockFactory = $blockFactory;
37  }
38 
48  public function add($name, $class, array $arguments = [])
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  }
62 
69  public function get($name = null)
70  {
71  if (!isset($name)) {
72  return $this->blocks;
73  }
74 
75  return $this->blocks[$name] ?? null;
76  }
77 }
$block
Definition: block.php:8
$_option $_optionId $class
Definition: date.phtml:13
__construct(BlockFactory $blockFactory)
Definition: BlockPool.php:34
$arguments
add($name, $class, array $arguments=[])
Definition: BlockPool.php:48
if(!isset($_GET['name'])) $name
Definition: log.php:14