This repository has been archived by the owner on Dec 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApplication.php
69 lines (56 loc) · 2.02 KB
/
Application.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
66
67
68
69
<?php
class EtuDev_Zend_Application extends Zend_Application
{
/**
*
* @var Zend_Cache_Core|null
*/
protected $_configCache;
public function __construct($environment, $options = null, Zend_Cache_Core $configCache = null)
{
$this->_configCache = $configCache;
parent::__construct($environment, $options);
}
protected function _cacheId($file)
{
return 'appconfig_' . $this->getEnvironment() . '_' . sha1($file);
}
protected function _loadConfigCache()
{
$configCache = new Zend_Cache_Core(array('automatic_serialization' => true));
if (extension_loaded('xcache')) {
$backend_type = 'Xcache';
} elseif (extension_loaded('apc')) {
$backend_type = 'Apc';
} elseif (extension_loaded('memcache')) {
$backend_type = 'Memcached';
} else {
$backend_type = 'File';
}
$backend = Zend_Cache::_makeBackend($backend_type, array());
$configCache->setBackend($backend);
$this->_configCache = $configCache;
}
//Override
protected function _loadConfig($file)
{
if (!$this->_configCache) {
$this->_loadConfigCache();
}
$suffix = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if ($this->_configCache === null || $suffix == 'php' || $suffix == 'inc') { //No need for caching those
return parent::_loadConfig($file);
}
$configMTime = filemtime($file);
$cacheId = $this->_cacheId($file);
//podemos quitar esto para acelerar, pero habría que borrar la cache manualmente en deploy entonces
$cacheLastMTime = $this->_configCache->test($cacheId);
if ($cacheLastMTime !== false && $configMTime < $cacheLastMTime) { //Valid cache?
return $this->_configCache->load($cacheId, true);
} else {
$config = parent::_loadConfig($file);
$this->_configCache->save($config, $cacheId);
return $config;
}
}
}