Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataSourcePool.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Framework\View;
7 
9 
14 {
20  protected $blockFactory;
21 
27  protected $dataSources = [];
28 
34  protected $assignments = [];
35 
42  {
43  $this->blockFactory = $blockFactory;
44  }
45 
54  public function add($name, $class)
55  {
56  if (!isset($this->dataSources[$name])) {
57  if (!class_exists($class)) {
58  throw new \InvalidArgumentException(
59  (string)new \Magento\Framework\Phrase('Invalid Data Source class name: %1', [$class])
60  );
61  }
62 
63  $data = $this->blockFactory->createBlock($class);
64 
65  $this->dataSources[$name] = $data;
66  }
67 
68  return $this->dataSources[$name];
69  }
70 
77  public function get($name = null)
78  {
79  if (!isset($name)) {
80  return $this->dataSources;
81  }
82 
83  return $this->dataSources[$name] ?? null;
84  }
85 
94  public function assign($dataName, $namespace, $alias)
95  {
96  $alias = $alias ?: $dataName;
97  $data = $this->get($dataName);
98 
99  $this->assignments[$namespace][$alias] = $data;
100  }
101 
108  public function getNamespaceData($namespace)
109  {
110  return $this->assignments[$namespace] ?? [];
111  }
112 }
assign($dataName, $namespace, $alias)
$_option $_optionId $class
Definition: date.phtml:13
__construct(BlockFactory $blockFactory)
if(!trim($html)) $alias
Definition: details.phtml:20
if(!isset($_GET['name'])) $name
Definition: log.php:14