Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PlaceholderFactory.php
Go to the documentation of this file.
1 <?php
7 
10 
16 {
20  const TYPE_ENVIRONMENT = 'environment';
21 
25  private $objectManager;
26 
30  private $types;
31 
36  public function __construct(ObjectManagerInterface $objectManager, array $types = [])
37  {
38  $this->objectManager = $objectManager;
39  $this->types = $types;
40  }
41 
50  public function create($type)
51  {
52  if (!isset($this->types[$type])) {
53  throw new LocalizedException(__('There is no defined type ' . $type));
54  }
55 
56  $object = $this->objectManager->create($this->types[$type]);
57 
58  if (!$object instanceof PlaceholderInterface) {
59  throw new LocalizedException(__('Object is not instance of ' . PlaceholderInterface::class));
60  }
61 
62  return $object;
63  }
64 }
$objectManager
Definition: bootstrap.php:17
__()
Definition: __.php:13
$type
Definition: item.phtml:13
__construct(ObjectManagerInterface $objectManager, array $types=[])