1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Nexcess.net Turpentine Extension for Magento |
5
|
|
|
* Copyright (C) 2012 Nexcess.net L.L.C. |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License along |
18
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
19
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version3 |
23
|
|
|
extends Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract { |
24
|
|
|
|
25
|
|
|
const VCL_TEMPLATE_FILE = 'version-3.vcl'; |
26
|
|
|
const VCL_VERSION = '3'; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Generate the Varnish 3.0-compatible VCL |
31
|
|
|
* |
32
|
|
|
* @param bool $doClean if true, VCL will be cleaned (whitespaces stripped, etc.) |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
public function generate($doClean = true) { |
|
|
|
|
36
|
|
|
// first, check if a custom template is set |
37
|
|
|
$customTemplate = $this->_getCustomTemplateFilename(); |
38
|
|
|
if ($customTemplate) { |
|
|
|
|
39
|
|
|
$tplFile = $customTemplate; |
40
|
|
|
} else { |
41
|
|
|
$tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); |
42
|
|
|
} |
43
|
|
|
$vcl = $this->_formatTemplate(file_get_contents($tplFile), |
44
|
|
|
$this->_getTemplateVars()); |
45
|
|
|
return $doClean ? $this->_cleanVcl($vcl) : $vcl; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
protected function _getAdvancedSessionValidation() { |
|
|
|
|
49
|
|
|
$validation = ''; |
50
|
|
|
foreach ($this->_getAdvancedSessionValidationTargets() as $target) { |
51
|
|
|
$validation .= sprintf('hash_data(%s);'.PHP_EOL, $target); |
52
|
|
|
} |
53
|
|
|
return $validation; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Build the list of template variables to apply to the VCL template |
58
|
|
|
* |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
|
View Code Duplication |
protected function _getTemplateVars() { |
|
|
|
|
62
|
|
|
$vars = parent::_getTemplateVars(); |
63
|
|
|
$vars['advanced_session_validation'] = |
64
|
|
|
$this->_getAdvancedSessionValidation(); |
65
|
|
|
|
66
|
|
|
//dispatch event to allow other extensions to add custom vcl template variables |
67
|
|
|
Mage::dispatchEvent('turpentine_get_templatevars_after', array( |
68
|
|
|
'vars' => &$vars, |
69
|
|
|
'vcl_version'=> self::VCL_VERSION |
70
|
|
|
)); |
71
|
|
|
|
72
|
|
|
return $vars; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.