Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Variable.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class Variable
15 {
19  const VAR_REGEX = '/{{([_a-z]*)}}/si';
20 
24  const VAR_BASE_URL_PATH = 'base_url_path';
25 
29  private $assetRepo;
30 
34  public function __construct(Asset\Repository $assetRepo)
35  {
36  $this->assetRepo = $assetRepo;
37  }
38 
45  public function convertVariableNotation($path)
46  {
47  $matches = [];
48  if (preg_match_all(self::VAR_REGEX, $path, $matches, PREG_SET_ORDER)) {
49  $replacements = [];
50  foreach ($matches as $match) {
51  if (!isset($replacements[$match[0]])) {
52  $replacements[$match[0]] = $this->getPlaceholderValue($match[1]);
53  }
54  }
55  $path = str_replace(array_keys($replacements), $replacements, $path);
56  }
57  return $path;
58  }
59 
66  public function getPlaceholderValue($placeholder)
67  {
69  $context = $this->assetRepo->getStaticViewFileContext();
70 
71  switch ($placeholder) {
73  return '{{' . self::VAR_BASE_URL_PATH . '}}' . $context->getAreaCode() .
74  ($context->getThemePath() ? '/' . $context->getThemePath() . '/' : '') .
75  '{{locale}}';
76  default:
77  return '';
78  }
79  }
80 }