-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathBackend.php
100 lines (89 loc) · 2.77 KB
/
Backend.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/*
* This file is part of the simple cms project for Yii2
*
* (c) Schallschlucker Agency Paul Kerspe - project homepage <https://github.com/pkerspe/yii2-simple-cms>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace schallschlucker\simplecms;
use Yii;
use yii\base\InvalidConfigException;
/**
* The simple cms backend module
*
* @author Paul Kerspe
*/
class Backend extends \yii\base\Module {
const VERSION = '0.3';
public $controllerNamespace = 'schallschlucker\simplecms\controllers\backend';
public $languageManager;
public $cache;
/**
*
* @var array The rules to be used in URL management.
*/
public $urlRules = [
'default/index'
];
/**
* @inheritdoc
*/
public function __construct($id, $parent = null, $config = []) {
foreach ( $this->getModuleComponents () as $name => $component ) {
if (! isset ( $config ['components'] [$name] )) {
$config ['components'] [$name] = $component;
} elseif (is_array ( $config ['components'] [$name] ) && ! isset ( $config ['components'] [$name] ['class'] )) {
$config ['components'] [$name] ['class'] = $component ['class'];
}
}
parent::__construct ( $id, $parent, $config );
}
/**
* Returns module components.
*
* @return array
*/
protected function getModuleComponents() {
return [
'languageManager' => [
'class' => 'schallschlucker\simplecms\LanguageManager'
]
];
}
public function getLanguageManager(){
if($this->languageManager == null || $this->languageManager == '' ){
throw new InvalidConfigException("Module is not condfigured correctly, need to provide name of a configured languageManager component");
}
$configuredLangManager = $this->languageManager;
return Yii::$app->$configuredLangManager;
}
/**
* store a value to the cache, if the cache is configured. Just ignores value if cache is not configured
* @param unknown $cacheKey
* @param unknown $value
* @param unknown $caheLivetime
*/
public function setCacheValue($cacheKey, $value, $cacheLivetime){
if($this->cache != null){
Yii::$app->get($this->cache,true)->set($cacheKey, $value, $cacheLivetime);
}
}
/**
* retrieve a value with the given cacheKey from the cache if a cache is configured at all and if the value could be found.
* If no cache is configured the fallbackValue is returned (by default this value is "false" if no parameter is given)
* @param unknown $cacheKey
* @param string $fallbackValue
* @return unknown|string
*/
public function getCachedValue($cacheKey,$fallbackValue = false){
if($this->cache != null){
$value = Yii::$app->get($this->cache,true)->get($cacheKey);
if($value !== false){
return $value;
}
}
return $fallbackValue;
}
}