Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TemplateFactory.php
Go to the documentation of this file.
1 <?php
8 
12 
17 {
23  protected $objectManager;
24 
30  protected $instanceName;
31 
38  public function __construct(
40  $instanceName = \Magento\Framework\View\TemplateEngine\Xhtml\Template::class
41  ) {
42  $this->objectManager = $objectManager;
43  $this->instanceName = $instanceName;
44  }
45 
53  public function create(array $arguments = [])
54  {
55  $object = $this->objectManager->create($this->instanceName, $arguments);
56 
57  if (!($object instanceof Template)) {
58  throw new LocalizedException(
59  new Phrase('This class needs to inherit from a class "Template". Verify the class and try again.')
60  );
61  }
62 
63  return $object;
64  }
65 }
__construct(ObjectManagerInterface $objectManager, $instanceName=\Magento\Framework\View\TemplateEngine\Xhtml\Template::class)
$arguments