Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Environment.php
Go to the documentation of this file.
1 <?php
7 
10 
17 {
21  const PREFIX = 'CONFIG__';
22 
26  private $deploymentConfig;
27 
31  public function __construct(DeploymentConfig $deploymentConfig)
32  {
33  $this->deploymentConfig = $deploymentConfig;
34  }
35 
42  public function generate($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null)
43  {
44  $parts = $scopeType ? [$scopeType] : [];
45 
46  if ($scopeType !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT && $scopeCode) {
47  $parts[] = $scopeCode;
48  }
49 
50  $parts[] = $path;
51 
52  $template = implode('__', $parts);
53  $template = str_replace('/', '__', $template);
54  $template = static::PREFIX . $template;
55  $template = strtoupper($template);
56 
57  return $template;
58  }
59 
64  public function restore($template)
65  {
66  $template = preg_replace('/^' . static::PREFIX . '/', '', $template);
67  $template = str_replace('__', '/', $template);
68  $template = strtolower($template);
69 
70  return $template;
71  }
72 
77  public function isApplicable($placeholder)
78  {
79  return 1 === preg_match('/^' . static::PREFIX . '([a-zA-Z]+)([a-zA-Z0-9_])*$/', $placeholder);
80  }
81 }
$deploymentConfig
generate($path, $scopeType=ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode=null)
Definition: Environment.php:42
$template
Definition: export.php:12
__construct(DeploymentConfig $deploymentConfig)
Definition: Environment.php:31