1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace dev7ch\slick; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Slick.js slider LUYA module. |
7
|
|
|
* |
8
|
|
|
* @author Silvan Hahn <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
class Module extends \luya\base\Module |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritdoc} |
14
|
|
|
*/ |
15
|
|
|
|
16
|
2 |
|
public static function onLoad() |
17
|
|
|
{ |
18
|
2 |
|
self::registerTranslation('slick*', static::staticBasePath().'/messages', [ |
19
|
2 |
|
'fileMap' => [ |
20
|
|
|
'slick' => 'slick.php', |
21
|
|
|
], |
22
|
|
|
]); |
23
|
2 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Translations. |
27
|
|
|
* |
28
|
|
|
* @param $message |
29
|
|
|
* @param array $params |
30
|
|
|
* @param $category |
31
|
|
|
* @internal param unknown $language |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
|
35
|
1 |
|
public static function t($message, array $params = [], $category = 'slick') |
36
|
|
|
{ |
37
|
1 |
|
return parent::baseT($category, $message, $params); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Loading and parsing of json config array. |
42
|
|
|
* |
43
|
|
|
* @param $file |
44
|
|
|
* @return string |
45
|
|
|
* @throws \luya\Exception |
46
|
|
|
* @internal param string $message |
47
|
|
|
* @internal param array $params |
48
|
|
|
*/ |
49
|
|
|
|
50
|
|
|
private static function jsonLoad($file) |
51
|
|
|
{ |
52
|
|
|
if (file_exists(\Yii::$app->getWebroot() . '/' . $file)) { |
53
|
|
|
file_get_contents(\Yii::$app->getWebroot() . '/' . $file); |
54
|
|
|
return json_decode($file, true); |
55
|
|
|
} |
56
|
|
|
else { |
57
|
|
|
throw new \luya\Exception('Slick.js configs:' .\Yii::$app->getWebroot() . '/' . $file . ' was not found.'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Load Slick.js options via LUYA configs as $params. |
63
|
|
|
* |
64
|
|
|
* @return boolean | string | array |
65
|
|
|
* @internal param array $params |
66
|
|
|
* |
67
|
|
|
*/ |
68
|
|
|
|
69
|
1 |
|
public static function slickConfig() { |
70
|
|
|
|
71
|
1 |
|
$params = self::getInstance()->params; |
72
|
|
|
|
73
|
1 |
|
if (array_key_exists( 'slickConfig', $params) && $params['slickConfig'] === true) { |
74
|
|
|
|
75
|
|
|
return self::jsonLoad('slick-config.json'); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
if (array_key_exists( 'slickConfig', $params) && is_string($params['slickConfig']) ) { |
79
|
|
|
return self::jsonLoad($params['slickConfig']); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
if (array_key_exists( 'slickConfig', $params) && is_array($params['slickConfig'])) { |
83
|
|
|
return $params['slickConfig']; |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
if (array_key_exists( 'slickConfig', $params) && is_bool($params['slickConfig'] === false)) { |
87
|
|
|
return false; |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
return false; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: