Skip to content

Commit 0aeda95

Browse files
committed
Adding namespacing and phpdoc
1 parent 417a5f4 commit 0aeda95

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

.gitignore

100644100755
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
composer.phar
2-
/vendor/
3-
4-
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
5-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6-
# composer.lock
1+
.idea/
2+
vendor/
3+
*.stackdump

README.md

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ TempCache::remove($key);
4141
```javascript
4242
{
4343
"require": {
44-
"cajogos/php-temp-cache": "1.0.1"
44+
"cajogos/php-temp-cache": "1.1"
4545
}
4646
}
4747
```

TempCache.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php
22

3+
namespace Cajogos;
4+
5+
/**
6+
* Class TempCache
7+
* @package Cajogos
8+
*/
39
class TempCache
410
{
511
const TIME_5_MIN = 300;
@@ -11,8 +17,15 @@ class TempCache
1117

1218
const CACHE_FOLDER = '/tmp/php-temp-cache/';
1319

20+
/**
21+
* @var bool
22+
*/
1423
private static $prepared = false;
1524

25+
/**
26+
* @param string $key
27+
* @return mixed|null
28+
*/
1629
public static function get($key)
1730
{
1831
if (self::prepare())
@@ -37,6 +50,12 @@ public static function get($key)
3750
return null;
3851
}
3952

53+
/**
54+
* @param string $key
55+
* @param string $value
56+
* @param integer $expiry
57+
* @return bool
58+
*/
4059
public static function put($key, $value, $expiry)
4160
{
4261
if (self::prepare())
@@ -50,13 +69,17 @@ public static function put($key, $value, $expiry)
5069
'key' => $cache_key,
5170
'expiry' => $expiry,
5271
'value' => $serialized
53-
);
72+
);
5473
$store = json_encode($store);
5574
return self::save_cache_file($file, $store);
5675
}
5776
return false;
5877
}
5978

79+
/**
80+
* @param string $key
81+
* @return bool
82+
*/
6083
public static function remove($key)
6184
{
6285
if (self::prepare())
@@ -68,6 +91,10 @@ public static function remove($key)
6891
return false;
6992
}
7093

94+
/**
95+
* @param string $file
96+
* @return bool|string
97+
*/
7198
private static function load_cache_file($file)
7299
{
73100
$file = self::CACHE_FOLDER . $file;
@@ -77,23 +104,41 @@ private static function load_cache_file($file)
77104
}
78105
return false;
79106
}
107+
108+
/**
109+
* @param string $file
110+
* @param string $data
111+
* @return bool
112+
*/
80113
private static function save_cache_file($file, $data)
81114
{
82115
$file = self::CACHE_FOLDER . $file;
83116
return (!(file_put_contents($file, $data) === false));
84117
}
118+
119+
/**
120+
* @param string $file
121+
* @return bool
122+
*/
85123
private static function delete_cache_file($file)
86124
{
87125
$file = self::CACHE_FOLDER . $file;
88126
return unlink($file);
89127
}
90128

129+
/**
130+
* @param string $key
131+
* @return string
132+
*/
91133
private static function cache_key_convert($key)
92134
{
93135
$key = 'tmpcache_' . $key;
94136
return md5($key);
95137
}
96138

139+
/**
140+
* @return bool
141+
*/
97142
private static function prepare()
98143
{
99144
if (self::$prepared)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"name": "Carlos Ferreira",
1111
"email": "c@rlos.rocks",
12-
"homepage": "http://ca.rlos.rocks",
12+
"homepage": "https://carlos.fyi",
1313
"role": "Developer"
1414
}
1515
],

composer.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)