Factory.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Helper\Shortcut;
  7. class Factory
  8. {
  9. /**
  10. * Default validator
  11. */
  12. const DEFAULT_VALIDATOR = \Magento\Paypal\Helper\Shortcut\Validator::class;
  13. /**
  14. * Checkout validator
  15. */
  16. const CHECKOUT_VALIDATOR = \Magento\Paypal\Helper\Shortcut\CheckoutValidator::class;
  17. /**
  18. * @var \Magento\Framework\ObjectManagerInterface
  19. */
  20. protected $_objectManager;
  21. /**
  22. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  23. */
  24. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  25. {
  26. $this->_objectManager = $objectManager;
  27. }
  28. /**
  29. * @param mixed $parameter
  30. * @return \Magento\Paypal\Helper\Shortcut\ValidatorInterface
  31. */
  32. public function create($parameter = null)
  33. {
  34. $instanceName = self::DEFAULT_VALIDATOR;
  35. if (is_object($parameter) && $parameter instanceof \Magento\Checkout\Model\Session) {
  36. $instanceName = self::CHECKOUT_VALIDATOR;
  37. }
  38. return $this->_objectManager->create($instanceName);
  39. }
  40. }