BaseSecurityPolicy::getTwigFunctions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace nystudio107\crafttwigsandbox\twig;
4
5
use craft\base\Model;
6
use Twig\Sandbox\SecurityPolicyInterface;
7
8
/**
9
 * @property string[] $twigTags  Tags for the Twig sandbox Security Policy
10
 * @property string[] $twigFilters  Filters for the Twig sandbox Security Policy
11
 * @property string[] $twigFunctions  Functions for the Twig sandbox Security Policy
12
 * @property array[] $twigMethods  Object methods for the Twig sandbox Security Policy
13
 * @property array[] $twigProperties  Object properties for the Twig sandbox Security Policy
14
 */
15
abstract class BaseSecurityPolicy extends Model implements SecurityPolicyInterface
16
{
17
    // Private Properties
18
    // =========================================================================
19
20
    /**
21
     * @var string[] Tags for the Twig sandbox Security Policy
22
     */
23
    private array $twigTags = [
24
    ];
25
26
    /**
27
     * @var string[] Filters for the Twig sandbox Security Policy
28
     */
29
    private array $twigFilters = [
30
    ];
31
32
    /**
33
     * @var string[] Functions for the Twig sandbox Security Policy
34
     */
35
    private array $twigFunctions = [
36
    ];
37
38
    /**
39
     * @var array[] Object methods for the Twig sandbox Security Policy
40
     */
41
    private array $twigMethods = [
42
    ];
43
44
    /**
45
     * @var array[] Object properties for the Twig sandbox Security Policy
46
     */
47
    private array $twigProperties = [
48
    ];
49
50
    // Public Methods
51
    // =========================================================================
52
53
    /**
54
     * @inheritDoc
55
     */
56
    public function checkSecurity($tags, $filters, $functions): void
57
    {
58
        // Allow all tags, filters, and functions
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function checkMethodAllowed($obj, $method): void
65
    {
66
        // Allow all methods
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function checkPropertyAllowed($obj, $property): void
73
    {
74
        // Allow all properties
75
    }
76
77
    // Getters & setters
78
    // =========================================================================
79
80
    public function getTwigTags(): array
81
    {
82
        return $this->twigTags;
83
    }
84
85
    public function setTwigTags(array $tags): void
86
    {
87
        $this->twigTags = $tags;
88
    }
89
90
    public function getTwigFilters(): array
91
    {
92
        return $this->twigFilters;
93
    }
94
95
    public function setTwigFilters(array $filters): void
96
    {
97
        $this->twigFilters = $filters;
98
    }
99
100
    public function getTwigFunctions(): array
101
    {
102
        return $this->twigFunctions;
103
    }
104
105
    public function setTwigFunctions(array $functions): void
106
    {
107
        $this->twigFunctions = $functions;
108
    }
109
110
    public function getTwigMethods(): array
111
    {
112
        return $this->twigMethods;
113
    }
114
115
    public function setTwigMethods(array $methods): void
116
    {
117
        $this->twigMethods = [];
118
        foreach ($methods as $class => $m) {
119
            $this->twigMethods[$class] = array_map(static function($value) {
120
                return strtolower($value);
121
            }, is_array($m) ? $m : [$m]);
122
        }
123
    }
124
125
126
    public function getTwigProperties(): array
127
    {
128
        return $this->twigProperties;
129
    }
130
131
    public function setTwigProperties(array $properties): void
132
    {
133
        $this->twigProperties = [];
134
        foreach ($properties as $class => $p) {
135
            $this->twigProperties[$class] = array_map(static function($value) {
136
                return strtolower($value);
137
            }, is_array($p) ? $p : [$p]);
138
        }
139
    }
140
}
141