-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathSecurityInfo.php
65 lines (60 loc) · 1.57 KB
/
SecurityInfo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Url security information
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Url;
class SecurityInfo implements \Magento\Framework\Url\SecurityInfoInterface
{
/**
* List of secure url patterns
*
* @var array
*/
protected $secureUrlsList = [];
/**
* List of patterns excluded form secure url list
*/
protected $excludedUrlsList = [];
/**
* List of already checked urls
*
* @var array
*/
protected $secureUrlsCache = [];
/**
* @param string[] $secureUrlList
* @param string[] $excludedUrlList
*/
public function __construct($secureUrlList = [], $excludedUrlList = [])
{
$this->secureUrlsList = $secureUrlList;
$this->excludedUrlsList = $excludedUrlList;
}
/**
* Check whether url is secure
*
* @param string $url
* @return bool
*/
public function isSecure($url)
{
if (!isset($this->secureUrlsCache[$url])) {
$this->secureUrlsCache[$url] = false;
foreach ($this->excludedUrlsList as $match) {
if (strpos($url, (string)$match) === 0) {
return $this->secureUrlsCache[$url];
}
}
foreach ($this->secureUrlsList as $match) {
if (strpos($url, (string)$match) === 0) {
$this->secureUrlsCache[$url] = true;
break;
}
}
}
return $this->secureUrlsCache[$url];
}
}