Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Signature.php
Go to the documentation of this file.
1 <?php
8 
12 class Signature
13 {
17  const XML_PATH_STATIC_FILE_SIGNATURE = 'dev/static/sign';
18 
22  const SIGNATURE_TEMPLATE = 'version%s';
23 
27  private $config;
28 
32  private $deploymentVersion;
33 
38  public function __construct(
39  \Magento\Framework\View\Url\ConfigInterface $config,
40  \Magento\Framework\App\View\Deployment\Version $deploymentVersion
41  ) {
42  $this->config = $config;
43  $this->deploymentVersion = $deploymentVersion;
44  }
45 
58  public function afterGetBaseUrl(
59  \Magento\Framework\Url\ScopeInterface $subject,
60  $baseUrl,
61  $type = \Magento\Framework\UrlInterface::URL_TYPE_LINK,
62  $secure = null
63  ) {
64  if ($type == \Magento\Framework\UrlInterface::URL_TYPE_STATIC && $this->isUrlSignatureEnabled()) {
65  $baseUrl .= $this->renderUrlSignature() . '/';
66  }
67  return $baseUrl;
68  }
69 
75  protected function isUrlSignatureEnabled()
76  {
77  return (bool)$this->config->getValue(self::XML_PATH_STATIC_FILE_SIGNATURE);
78  }
79 
85  protected function renderUrlSignature()
86  {
87  return sprintf(self::SIGNATURE_TEMPLATE, $this->deploymentVersion->getValue());
88  }
89 }
$config
Definition: fraud_order.php:17
$type
Definition: item.phtml:13
afterGetBaseUrl(\Magento\Framework\Url\ScopeInterface $subject, $baseUrl, $type=\Magento\Framework\UrlInterface::URL_TYPE_LINK, $secure=null)
Definition: Signature.php:58
__construct(\Magento\Framework\View\Url\ConfigInterface $config, \Magento\Framework\App\View\Deployment\Version $deploymentVersion)
Definition: Signature.php:38