summaryrefslogtreecommitdiff
path: root/app/ServiceProvider/CacheProvider.php
blob: af8a8e7a910e982b69088c80613f9702232c61f7 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php

namespace Kanboard\ServiceProvider;

use Kanboard\Core\Cache\FileCache;
use Kanboard\Core\Cache\MemoryCache;
use Kanboard\Decorator\ColumnMoveRestrictionCacheDecorator;
use Kanboard\Decorator\ColumnRestrictionCacheDecorator;
use Kanboard\Decorator\MetadataCacheDecorator;
use Kanboard\Decorator\ProjectRoleRestrictionCacheDecorator;
use Kanboard\Decorator\UserCacheDecorator;
use Pimple\Container;
use Pimple\ServiceProviderInterface;

/**
 * Cache Provider
 *
 * @package Kanboard\ServiceProvider
 * @author  Frederic Guillot
 */
class CacheProvider implements ServiceProviderInterface
{
    /**
     * Register providers
     *
     * @access public
     * @param  \Pimple\Container $container
     * @return \Pimple\Container
     */
    public function register(Container $container)
    {
        $container['memoryCache'] = function() {
            return new MemoryCache();
        };

        if (CACHE_DRIVER === 'file') {
            $container['cacheDriver'] = function() {
                return new FileCache();
            };
        } else {
            $container['cacheDriver'] = $container['memoryCache'];
        }

        $container['userCacheDecorator'] = function($c) {
            return new UserCacheDecorator(
                $c['memoryCache'],
                $c['userModel']
            );
        };

        $container['userMetadataCacheDecorator'] = function($c) {
            return new MetadataCacheDecorator(
                $c['cacheDriver'],
                $c['userMetadataModel'],
                'user.metadata.',
                $c['userSession']->getId()
            );
        };

        $container['columnMoveRestrictionCacheDecorator'] = function($c) {
            return new ColumnMoveRestrictionCacheDecorator(
                $c['memoryCache'],
                $c['columnMoveRestrictionModel']
            );
        };

        $container['columnRestrictionCacheDecorator'] = function($c) {
            return new ColumnRestrictionCacheDecorator(
                $c['memoryCache'],
                $c['columnRestrictionModel']
            );
        };

        $container['projectRoleRestrictionCacheDecorator'] = function($c) {
            return new ProjectRoleRestrictionCacheDecorator(
                $c['memoryCache'],
                $c['projectRoleRestrictionModel']
            );
        };

        return $container;
    }
}