Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TemplateFile.php
Go to the documentation of this file.
1 <?php
8 
16 
20 class TemplateFile extends File
21 {
25  protected $appState;
26 
30  protected $templateMinifier;
31 
35  protected $assetConfig;
36 
40  private $deploymentConfig;
41 
49  public function __construct(
50  ResolverInterface $resolver,
54  DeploymentConfig $deploymentConfig = null
55  ) {
56  $this->appState = $appState;
57  $this->templateMinifier = $templateMinifier;
58  $this->assetConfig = $assetConfig;
59  $this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
60  parent::__construct($resolver);
61  }
62 
66  protected function getFallbackType()
67  {
68  return \Magento\Framework\View\Design\Fallback\RulePool::TYPE_TEMPLATE_FILE;
69  }
70 
80  public function getFile($area, ThemeInterface $themeModel, $file, $module = null)
81  {
82  $template = parent::getFile($area, $themeModel, $file, $module);
83 
84  if ($template && $this->assetConfig->isMinifyHtml()) {
85  switch ($this->appState->getMode()) {
87  return $this->getMinifiedTemplateInProduction($template);
89  return $this->templateMinifier->getMinified($template);
91  default:
92  return $template;
93  }
94  }
95  return $template;
96  }
97 
108  private function getMinifiedTemplateInProduction($template)
109  {
110  $forceMinification = $this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)
111  || $this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_FORCE_HTML_MINIFICATION);
112 
113  return $forceMinification ?
114  $this->templateMinifier->getMinified($template)
115  : $this->templateMinifier->getPathToMinified($template);
116  }
117 }
getFile($area, ThemeInterface $themeModel, $file, $module=null)
__construct(ResolverInterface $resolver, MinifierInterface $templateMinifier, State $appState, ConfigInterface $assetConfig, DeploymentConfig $deploymentConfig=null)
$template
Definition: export.php:12