CompilerFactory.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\TemplateEngine\Xhtml;
  7. use Magento\Framework\Phrase;
  8. use Magento\Framework\ObjectManagerInterface;
  9. use Magento\Framework\Exception\LocalizedException;
  10. /**
  11. * Class CompilerFactory
  12. */
  13. class CompilerFactory
  14. {
  15. /**
  16. * Object manager
  17. *
  18. * @var ObjectManagerInterface
  19. */
  20. protected $objectManager;
  21. /**
  22. * Instance name
  23. *
  24. * @var string
  25. */
  26. protected $instanceName;
  27. /**
  28. * Constructor
  29. *
  30. * @param ObjectManagerInterface $objectManager
  31. * @param string $instanceName
  32. */
  33. public function __construct(ObjectManagerInterface $objectManager, $instanceName)
  34. {
  35. $this->objectManager = $objectManager;
  36. $this->instanceName = $instanceName;
  37. }
  38. /**
  39. * Create result
  40. *
  41. * @param array $arguments
  42. * @return CompilerInterface
  43. * @throws LocalizedException
  44. */
  45. public function create(array $arguments = [])
  46. {
  47. $object = $this->objectManager->create($this->instanceName, $arguments);
  48. if (!($object instanceof CompilerInterface)) {
  49. throw new LocalizedException(new Phrase('This class must implement the "CompilerInterface"'));
  50. }
  51. return $object;
  52. }
  53. }