Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Processor.php
Go to the documentation of this file.
1 <?php
7 
10 
14 class Processor
15 {
19  private $assetRepository;
20 
24  public function __construct(Repository $assetRepository)
25  {
26  $this->assetRepository = $assetRepository;
27  }
28 
35  public function process($css)
36  {
37  $matches = [];
38  if (preg_match_all(Variable::VAR_REGEX, $css, $matches, PREG_SET_ORDER)) {
39  $replacements = [];
40  foreach ($matches as $match) {
41  if (!isset($replacements[$match[0]])) {
42  $replacements[$match[0]] = $this->getPlaceholderValue($match[1]);
43  }
44  }
45  $css = str_replace(array_keys($replacements), $replacements, $css);
46  }
47  return $css;
48  }
49 
56  private function getPlaceholderValue($placeholder)
57  {
59  $context = $this->assetRepository->getStaticViewFileContext();
60 
61  switch ($placeholder) {
62  case 'base_url_path':
63  return $context->getBaseUrl();
64  case 'locale':
65  return $context->getLocale();
66  default:
67  return '';
68  }
69  }
70 }
__construct(Repository $assetRepository)
Definition: Processor.php:24