MoufTwigEnvironment   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 10
Bugs 0 Features 1
Metric Value
wmc 9
c 10
b 0
f 1
lcom 1
cbo 1
dl 0
loc 66
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setExtensions() 0 4 1
A get() 0 4 1
A set() 0 4 1
A purge() 0 4 1
B purgeAll() 0 13 5
1
<?php
2
namespace Mouf\Html\Renderer\Twig;
3
4
use Twig_LoaderInterface;
5
use Twig_ExtensionInterface;
6
use Mouf\Utils\Cache\CacheInterface;
7
8
/**
9
 * The simple class extending the Twig_Environment class whose sole purpose is to make it
10
 * easy to work with the Twig_Environement class in Mouf.
11
 *
12
 * It does this by overloading the constructor and adding a bunch of parameters that would
13
 * otherwise be passed in the very inconvenient config array.
14
 *
15
 * It also automatically registers the MoufTwigExtension extension.
16
 *
17
 * @author David Negrier <[email protected]>
18
 */
19
class MoufTwigEnvironment extends \Twig_Environment implements CacheInterface
20
{
21
    
22
    /**
23
     * Registers an array of extensions.
24
     * Note: the sole purpose of this function is to overload the @param annotation.
25
     *
26
     * @param Twig_ExtensionInterface[] $extensions An array of extensions
27
     */
28
    public function setExtensions(array $extensions)
29
    {
30
        parent::setExtensions($extensions);
31
    }
32
33
    /**
34
     * The get method of the cache is not implemented. The CacheInterface is implemented only to be able to
35
     * delete cache files when the "Purge cache" button is pressed in Mouf UI.
36
     * (non-PHPdoc)
37
     * @see \Mouf\Utils\Cache\CacheInterface::get()
38
     */
39
    public function get($key)
40
    {
41
        throw new \Exception("Unsupported call to 'get' method. MoufTwigEnvironment implements only the 'purgeAll' method of the CacheInterface");
42
    }
43
44
    /**
45
     * The set method of the cache is not implemented. The CacheInterface is implemented only to be able to
46
     * delete cache files when the "Purge cache" button is pressed in Mouf UI.
47
     * (non-PHPdoc)
48
     * @see \Mouf\Utils\Cache\CacheInterface::set()
49
     */
50
    public function set($key, $value, $timeToLive = null)
51
    {
52
        throw new \Exception("Unsupported call to 'set' method. MoufTwigEnvironment implements only the 'purgeAll' method of the CacheInterface");
53
    }
54
55
    /**
56
     * The purge method of the cache is not implemented. The CacheInterface is implemented only to be able to
57
     * delete cache files when the "Purge cache" button is pressed in Mouf UI.
58
     * (non-PHPdoc)
59
     * @see \Mouf\Utils\Cache\CacheInterface::purge()
60
     */
61
    public function purge($key)
62
    {
63
        throw new \Exception("Unsupported call to 'purge' method. MoufTwigEnvironment implements only the 'purgeAll' method of the CacheInterface");
64
    }
65
66
    /**
67
     * (non-PHPdoc)
68
     * @see \Mouf\Utils\Cache\CacheInterface::purgeAll()
69
     */
70
    public function purgeAll()
71
    {
72
        if (!empty($this->cache)) {
73
            if ($this->cache instanceof \Twig_CacheInterface || file_exists($this->cache)) {
74
                try {
75
                    $this->clearTemplateCache();
0 ignored issues
show
Deprecated Code introduced by
The method Twig_Environment::clearTemplateCache() has been deprecated with message: since 1.18.3 (to be removed in 2.0)

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
76
                    $this->clearCacheFiles();
0 ignored issues
show
Deprecated Code introduced by
The method Twig_Environment::clearCacheFiles() has been deprecated with message: since 1.22 (to be removed in 2.0)

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
77
                } catch (\UnexpectedValueException $e) {
78
                    // The directory might not exist. This is not a problem.
79
                }
80
            }
81
        }
82
    }
83
84
}
85