-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurlCache.php
More file actions
42 lines (33 loc) · 843 Bytes
/
Copy pathCurlCache.php
File metadata and controls
42 lines (33 loc) · 843 Bytes
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
<?php
/**
* Created by PhpStorm.
* User: kath.young
* Date: 2/13/18
* Time: 1:16 PM
*/
namespace Forgemaster;
class CurlCache
{
protected static function sanitizeUrl($url){
$file = str_replace(":","-", $url);
$file = str_replace("/","-", $file);
$file = str_replace("&", "-", $file);
$file = str_replace("+", "_", $file);
return $file;
}
public static function get($url){
$file = self::sanitizeUrl($url);
if(file_exists("cache/$file")){
return file_get_contents("cache/$file");
}else{
return null;
}
}
public static function put($url, $data){
$file = self::sanitizeUrl($url);
if(!file_exists("cache")){
mkdir("cache");
}
file_put_contents("cache/$file", $data);
}
}