Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LayoutUpdateConverter.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Widget\Setup;
7 
13 
18 {
22  private $normalizer;
23 
31  public function __construct(
32  Serialize $serialize,
33  Json $json,
34  Normalizer $normalizer
35  ) {
36  $this->normalizer = $normalizer;
37  parent::__construct($serialize, $json);
38  }
39 
47  public function convert($value)
48  {
49  preg_match_all(
50  '/^(.*?conditions_encoded<\/argument><argument [^<]*>)(.*?)(<\/argument>.*?)$/si',
51  $value,
52  $matches,
53  PREG_SET_ORDER
54  );
55  if (isset($matches[0])) {
56  $matchSegments = $matches[0];
57  $matchSegments[2] = parent::convert($matchSegments[2]);
58  return $matchSegments[1] . $matchSegments[2] . $matchSegments[3];
59  } else {
60  return $value;
61  }
62  }
63 
67  protected function isValidJsonValue($value)
68  {
69  $value = $this->normalizer->restoreReservedCharacters($value);
70  return parent::isValidJsonValue($value);
71  }
72 
76  protected function unserializeValue($value)
77  {
78  $value = htmlspecialchars_decode($value);
79  $value = $this->restoreReservedCharactersInSerializedContent($value);
80  return parent::unserializeValue($value);
81  }
82 
86  protected function encodeJson($value)
87  {
88  return htmlspecialchars(
89  $this->normalizer->replaceReservedCharacters(parent::encodeJson($value))
90  );
91  }
92 
99  private function restoreReservedCharactersInSerializedContent($serializedContent)
100  {
101  $map = [
102  '{' => '[',
103  '}' => ']',
104  '"' => '`',
105  '\\' => '|',
106  ];
107  return str_replace(
108  array_values($map),
109  array_keys($map),
110  $serializedContent
111  );
112  }
113 }
$value
Definition: gender.phtml:16
__construct(Serialize $serialize, Json $json, Normalizer $normalizer)