Component.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Block\Express\InContext;
  7. use Magento\Paypal\Model\Config;
  8. use Magento\Paypal\Model\ConfigFactory;
  9. use Magento\Framework\View\Element\Template;
  10. use Magento\Framework\Locale\ResolverInterface;
  11. use Magento\Framework\View\Element\Template\Context;
  12. /**
  13. * Class Component
  14. *
  15. * @api
  16. * @since 100.1.0
  17. */
  18. class Component extends Template
  19. {
  20. const IS_BUTTON_CONTEXT_INDEX = 'is_button_context';
  21. /**
  22. * @var ResolverInterface
  23. */
  24. private $localeResolver;
  25. /**
  26. * @var Config
  27. */
  28. private $config;
  29. /**
  30. * @inheritdoc
  31. * @param ResolverInterface $localeResolver
  32. */
  33. public function __construct(
  34. Context $context,
  35. ResolverInterface $localeResolver,
  36. ConfigFactory $configFactory,
  37. array $data = []
  38. ) {
  39. parent::__construct($context, $data);
  40. $this->localeResolver = $localeResolver;
  41. $this->config = $configFactory->create();
  42. $this->config->setMethod(Config::METHOD_EXPRESS);
  43. }
  44. /**
  45. * @inheritdoc
  46. * @since 100.1.0
  47. */
  48. protected function _toHtml()
  49. {
  50. if (!$this->isInContext()) {
  51. return '';
  52. }
  53. return parent::_toHtml();
  54. }
  55. /**
  56. * @return bool
  57. */
  58. private function isInContext()
  59. {
  60. return (bool)(int) $this->config->getValue('in_context');
  61. }
  62. /**
  63. * @return string
  64. * @since 100.1.0
  65. */
  66. public function getEnvironment()
  67. {
  68. return (int) $this->config->getValue('sandbox_flag') ? 'sandbox' : 'production';
  69. }
  70. /**
  71. * @return string
  72. * @since 100.1.0
  73. */
  74. public function getLocale()
  75. {
  76. return $this->localeResolver->getLocale();
  77. }
  78. /**
  79. * @return string
  80. * @since 100.1.0
  81. */
  82. public function getMerchantId()
  83. {
  84. return $this->config->getValue('merchant_id');
  85. }
  86. /**
  87. * @return bool
  88. * @since 100.1.0
  89. */
  90. public function isButtonContext()
  91. {
  92. return (bool) $this->getData(self::IS_BUTTON_CONTEXT_INDEX);
  93. }
  94. }