Subversion Repositories Applications.framework

Rev

Rev 270 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 270 Rev 272
Line 2... Line 2...
2
class ServiceCacheFichier extends Service {
2
class ServiceCacheFichier extends Service {
Line 3... Line 3...
3
	
3
	
4
	public function consulter($ressources, $parametres) {
4
	public function consulter($ressources, $parametres) {
5
		$options = array(
5
		$options = array(
6
			'stockage_mode'				 => Cache::STOCKAGE_MODE_FICHIER,
6
			'stockage_mode'				 => Cache::STOCKAGE_MODE_FICHIER,
7
			'stockage_chemin'				 => $this->getTmpDir(),	
7
			'stockage_chemin'				 => Fichier::getDossierTmp(),	
8
			'controle_ecriture'			 => false,
8
			'controle_ecriture'			 => false,
9
			'mise_en_cache'		  		 => true,
9
			'mise_en_cache'		  		 => true,
10
			'cache_id_prefixe'		  		 => null,
10
			'cache_id_prefixe'		  		 => null,
11
			'serialisation_auto'		  	 => false,
11
			'serialisation_auto'		  	 => false,
Line 91... Line 91...
91
			$meta02 = $cache->getMetadonnees($id_test);
91
			$meta02 = $cache->getMetadonnees($id_test);
92
			echo "Durée de vie du cache '$id_test' après ajout supplément de -3540s : ".$meta02['expiration'].
92
			echo "Durée de vie du cache '$id_test' après ajout supplément de -3540s : ".$meta02['expiration'].
93
				' - diff. : '.($meta02['expiration'] - $meta01['expiration']).'<br/>';
93
				' - diff. : '.($meta02['expiration'] - $meta01['expiration']).'<br/>';
94
		}
94
		}
95
	}
95
	}
96
	
-
 
97
	/**
-
 
98
     * Determine system TMP directory and detect if we have read access
-
 
99
     *
-
 
100
     * inspired from Zend_File_Transfer_Adapter_Abstract & Zend_Cache
-
 
101
     *
-
 
102
     * @return string
-
 
103
     */
-
 
104
    public function getTmpDir() {
-
 
105
        $tmpdir = array();
-
 
106
        foreach (array($_ENV, $_SERVER) as $tab) {
-
 
107
            foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
-
 
108
                if (isset($tab[$key])) {
-
 
109
                    if (($key == 'windir') or ($key == 'SystemRoot')) {
-
 
110
                        $dir = realpath($tab[$key] . '\\temp');
-
 
111
                    } else {
-
 
112
                        $dir = realpath($tab[$key]);
-
 
113
                    }
-
 
114
                    if ($this->isGoodTmpDir($dir)) {
-
 
115
                        return $dir;
-
 
116
                    }
-
 
117
                }
-
 
118
            }
-
 
119
        }
-
 
120
        $upload = ini_get('upload_tmp_dir');
-
 
121
        if ($upload) {
-
 
122
            $dir = realpath($upload);
-
 
123
            if ($this->isGoodTmpDir($dir)) {
-
 
124
                return $dir;
-
 
125
            }
-
 
126
        }
-
 
127
        if (function_exists('sys_get_temp_dir')) {
-
 
128
            $dir = sys_get_temp_dir();
-
 
129
            if ($this->isGoodTmpDir($dir)) {
-
 
130
                return $dir;
-
 
131
            }
-
 
132
        }
-
 
133
        // Attemp to detect by creating a temporary file
-
 
134
        $tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
-
 
135
        if ($tempFile) {
-
 
136
            $dir = realpath(dirname($tempFile));
-
 
137
            unlink($tempFile);
-
 
138
            if ($this->isGoodTmpDir($dir)) {
-
 
139
                return $dir;
-
 
140
            }
-
 
141
        }
-
 
142
        if ($this->isGoodTmpDir('/tmp')) {
-
 
143
            return '/tmp';
-
 
144
        }
-
 
145
        if ($this->isGoodTmpDir('\\temp')) {
-
 
146
            return '\\temp';
-
 
147
        }
-
 
148
    }
-
 
149
    
-
 
150
    /**
-
 
151
     * Verify if the given temporary directory is readable and writable
-
 
152
     *
-
 
153
     * @param $dir temporary directory
-
 
154
     * @return boolean true if the directory is ok
-
 
155
     */
-
 
156
    protected function isGoodTmpDir($dir){
-
 
157
        if (is_readable($dir)) {
-
 
158
            if (is_writable($dir)) {
-
 
159
                return true;
-
 
160
            }
-
 
161
        }
-
 
162
        return false;
-
 
163
    }
-
 
164
    
-
 
165
}
96
}
166
?>
97
?>
167
98