Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Component.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Paypal\Model\ConfigFactory;
13 
20 class Component extends Template
21 {
22  const IS_BUTTON_CONTEXT_INDEX = 'is_button_context';
23 
27  private $localeResolver;
28 
32  private $config;
33 
38  public function __construct(
39  Context $context,
40  ResolverInterface $localeResolver,
41  ConfigFactory $configFactory,
42  array $data = []
43  ) {
44  parent::__construct($context, $data);
45  $this->localeResolver = $localeResolver;
46  $this->config = $configFactory->create();
47 
48  $this->config->setMethod(Config::METHOD_EXPRESS);
49  }
50 
55  protected function _toHtml()
56  {
57  if (!$this->isInContext()) {
58  return '';
59  }
60 
61  return parent::_toHtml();
62  }
63 
67  private function isInContext()
68  {
69  return (bool)(int) $this->config->getValue('in_context');
70  }
71 
76  public function getEnvironment()
77  {
78  return (int) $this->config->getValue('sandbox_flag') ? 'sandbox' : 'production';
79  }
80 
85  public function getLocale()
86  {
87  return $this->localeResolver->getLocale();
88  }
89 
94  public function getMerchantId()
95  {
96  return $this->config->getValue('merchant_id');
97  }
98 
103  public function isButtonContext()
104  {
105  return (bool) $this->getData(self::IS_BUTTON_CONTEXT_INDEX);
106  }
107 }
getData($key='', $index=null)
Definition: DataObject.php:119
__construct(Context $context, ResolverInterface $localeResolver, ConfigFactory $configFactory, array $data=[])
Definition: Component.php:38
$configFactory
Definition: config_data.php:43