Factory.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\Order\Pdf\Total;
  7. class Factory
  8. {
  9. /**
  10. * @var \Magento\Framework\ObjectManagerInterface
  11. */
  12. protected $_objectManager;
  13. /**
  14. * Default total model
  15. *
  16. * @var string
  17. */
  18. protected $_defaultTotalModel = \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal::class;
  19. /**
  20. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  21. */
  22. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  23. {
  24. $this->_objectManager = $objectManager;
  25. }
  26. /**
  27. * Create instance of a total model
  28. *
  29. * @param string|null $class
  30. * @param array $arguments
  31. * @return \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal
  32. * @throws \Magento\Framework\Exception\LocalizedException
  33. */
  34. public function create($class = null, $arguments = [])
  35. {
  36. $class = $class ?: $this->_defaultTotalModel;
  37. if (!is_a($class, \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal::class, true)) {
  38. throw new \Magento\Framework\Exception\LocalizedException(
  39. __(
  40. 'The PDF total model %1 must be or extend \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal.',
  41. $class
  42. )
  43. );
  44. }
  45. return $this->_objectManager->create($class, $arguments);
  46. }
  47. }