Factory.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Payment\Helper\Shortcut;
  17. class Factory
  18. {
  19. /**
  20. * Default validator
  21. */
  22. const DEFAULT_VALIDATOR = \Amazon\Payment\Helper\Shortcut\Validator::class;
  23. /**
  24. * Checkout validator
  25. */
  26. const CHECKOUT_VALIDATOR = \Amazon\Payment\Helper\Shortcut\CheckoutValidator::class;
  27. /**
  28. * @var \Magento\Framework\ObjectManagerInterface
  29. */
  30. private $_objectManager;
  31. /**
  32. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  33. */
  34. public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
  35. {
  36. $this->_objectManager = $objectManager;
  37. }
  38. /**
  39. * @param mixed $parameter
  40. * @return \Amazon\Payment\Helper\Shortcut\ValidatorInterface
  41. */
  42. public function create($parameter = null)
  43. {
  44. $instanceName = self::DEFAULT_VALIDATOR;
  45. if (is_object($parameter) && $parameter instanceof \Magento\Checkout\Model\Session) {
  46. $instanceName = self::CHECKOUT_VALIDATOR;
  47. }
  48. return $this->_objectManager->create($instanceName);
  49. }
  50. }