Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Hash.php
Go to the documentation of this file.
1 <?php
8 
13 
22 class Hash
23 {
27  const CONFIG_KEY = 'config_hash';
28 
34  private $configHashGenerator;
35 
41  private $dataConfigCollector;
42 
48  private $flagResource;
49 
55  private $flagFactory;
56 
63  public function __construct(
64  Hash\Generator $configHashGenerator,
65  DataCollector $dataConfigCollector,
66  FlagResource $flagResource,
67  FlagFactory $flagFactory
68  ) {
69  $this->configHashGenerator = $configHashGenerator;
70  $this->dataConfigCollector = $dataConfigCollector;
71  $this->flagResource = $flagResource;
72  $this->flagFactory = $flagFactory;
73  }
74 
86  public function regenerate($sectionName = null)
87  {
88  try {
89  $hashes = $this->get();
90  $configs = $this->dataConfigCollector->getConfig($sectionName);
91 
92  foreach ($configs as $section => $config) {
93  $hashes[$section] = $this->configHashGenerator->generate($config);
94  }
95 
97  $flag = $this->getFlagObject();
98  $flag->setFlagData($hashes);
99  $this->flagResource->save($flag);
100  } catch (\Exception $exception) {
101  throw new LocalizedException(__("The hash isn't saved."), $exception);
102  }
103  }
104 
110  public function get()
111  {
113  $flag = $this->getFlagObject();
114  return (array) ($flag->getFlagData() ?: []);
115  }
116 
124  private function getFlagObject()
125  {
127  $flag = $this->flagFactory
128  ->create(['data' => ['flag_code' => self::CONFIG_KEY]]);
129  $this->flagResource->load($flag, self::CONFIG_KEY, 'flag_code');
130  return $flag;
131  }
132 }
$config
Definition: fraud_order.php:17
__()
Definition: __.php:13
__construct(Hash\Generator $configHashGenerator, DataCollector $dataConfigCollector, FlagResource $flagResource, FlagFactory $flagFactory)
Definition: Hash.php:63