Completed
Push — development ( cfd391...deed4d )
by Andrij
12:03
created

application/helpers/cache_helper.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
if (!defined('BASEPATH')) {
4
    exit('No direct script access allowed');
5
}
6
7
class CmsCacheHelper
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
10
    public static $key = null;
11
12
    public static $duration = false;
13
14
    public function init($key, $duration) {
15
        $ci = get_instance();
16
17
        self::$key = $key;
18
        self::$duration = $duration;
19
20
        if (($data = $ci->cache->fetch('parts' . $key, 'parts')) === false) {
21
            return false;
22
        }
23
24
        return $data;
25
    }
26
27
    public function storeCache($content) {
28
        $ci = get_instance();
29
30
        $ci->cache->store('parts' . self::$key, $content, self::$duration, 'parts');
31
32
        return self::$key;
33
    }
34
35
}
36
37
if (!function_exists('beginCache')) {
38
39
    function beginCache($key, $duration = false) {
0 ignored issues
show
Invalid function name, expected begin_cache but found beginCache
Loading history...
40
        $result = CmsCacheHelper::init($key, $duration);
41
42
        if ($result === false) {
43
            ob_start();
44
            ob_implicit_flush(false);
45
            return true; // Begin cache
46
        } else {
47
            // Display cached content
48
            echo $result;
49
            return false;
50
        }
51
    }
52
53
}
54
55
if (!function_exists('endCache')) {
56
57
    function endCache() {
0 ignored issues
show
Invalid function name, expected end_cache but found endCache
Loading history...
58
        $content = ob_get_clean();
59
        CmsCacheHelper::storeCache($content);
60
        return $content;
61
    }
62
63
}