1 | <?php |
||
13 | class FileAccess extends Object { |
||
14 | private $sUri; |
||
15 | |||
16 | private $sCachePath; |
||
17 | protected $saveToCache = true; |
||
18 | |||
19 | 1 | public function __construct($sUri) { |
|
22 | |||
23 | 1 | public function getUri() { |
|
26 | |||
27 | 1 | public function getCachePath() { |
|
30 | |||
31 | 1 | public function setCachePath($sPath) { |
|
32 | 1 | if (is_dir($sPath)) { |
|
33 | 1 | $this->sCachePath = $sPath; |
|
34 | } else { |
||
35 | throw new ExceptionAccess('Path [' . $sPath . '] is invalid for cache'); |
||
36 | } |
||
37 | 1 | } |
|
38 | |||
39 | /** |
||
40 | * @param string $sFile |
||
41 | * @return string |
||
42 | */ |
||
43 | 1 | public function getLocalPath($sFile) { |
|
46 | |||
47 | 1 | public function getSignature($sUri) { |
|
50 | |||
51 | /** |
||
52 | * @param string $sUri |
||
53 | * @return bool |
||
54 | */ |
||
55 | 1 | public function inCache($sUri) { |
|
58 | |||
59 | 1 | public function loadFromCache($sUri) { |
|
62 | |||
63 | /** |
||
64 | * @param string $sUri |
||
65 | * @param string $sContent |
||
66 | * @throws ExceptionError |
||
67 | */ |
||
68 | 1 | public function cacheFile($sUri, $sContent) { |
|
69 | 1 | $sFileName = $this->getLocalPath($this->getSignature($sUri)); |
|
70 | // creating the file |
||
71 | 1 | if (!touch($sFileName)) { |
|
72 | throw new ExceptionError('Path [' . $sFileName . '] is not accessible.'); |
||
73 | } |
||
74 | |||
75 | 1 | if (is_writable($sFileName)) { |
|
76 | 1 | file_put_contents($sFileName, $sContent); |
|
77 | } else { |
||
78 | throw new ExceptionError('Path [' . $sFileName . '] is not writable.'); |
||
79 | } |
||
80 | 1 | } |
|
81 | |||
82 | 1 | public function isLocalFile() { |
|
85 | |||
86 | 1 | public static function getFile($sPath) { |
|
89 | |||
90 | 2 | public function load() { |
|
91 | 2 | if ($this->isLocalFile($this->sUri) || !$this->inCache($this->sUri)) { |
|
110 | } |
||
111 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.