1 | <?php |
||||||||||
2 | namespace Inji; |
||||||||||
3 | /** |
||||||||||
4 | * Libs module |
||||||||||
5 | * |
||||||||||
6 | * @author Alexey Krupskiy <[email protected]> |
||||||||||
7 | * @link http://inji.ru/ |
||||||||||
8 | * @copyright 2015 Alexey Krupskiy |
||||||||||
9 | * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
||||||||||
10 | */ |
||||||||||
11 | class Libs extends Module { |
||||||||||
12 | |||||||||||
13 | public function loadLib($libName, $options = []) { |
||||||||||
14 | $className = 'Inji\Libs\\' . ucfirst($libName); |
||||||||||
15 | if (class_exists($className)) { |
||||||||||
16 | if (!empty($className::$composerPacks)) { |
||||||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||||||
17 | foreach ($className::$composerPacks as $packageName => $version) { |
||||||||||
18 | ComposerCmd::requirePackage($packageName, $version); |
||||||||||
19 | } |
||||||||||
20 | } |
||||||||||
21 | if (!empty($className::$bowerPacks)) { |
||||||||||
0 ignored issues
–
show
|
|||||||||||
22 | foreach ($className::$bowerPacks as $packageName => $version) { |
||||||||||
23 | BowerCmd::requirePackage($packageName, $version); |
||||||||||
24 | } |
||||||||||
25 | } |
||||||||||
26 | if (!empty($className::$requiredLibs)) { |
||||||||||
0 ignored issues
–
show
|
|||||||||||
27 | foreach ($className::$requiredLibs as $rLib) { |
||||||||||
28 | $this->loadLib($rLib); |
||||||||||
29 | } |
||||||||||
30 | } |
||||||||||
31 | if (!empty($className::$files['css']) && (!isset($options['loadCss']) || $options['loadCss'])) { |
||||||||||
0 ignored issues
–
show
|
|||||||||||
32 | foreach ($className::$files['css'] as $file) { |
||||||||||
33 | if (strpos($file, '/') === 0 || strpos($file, 'http') === 0) { |
||||||||||
34 | App::$cur->view->customAsset('css', $file, $libName); |
||||||||||
0 ignored issues
–
show
The property
view does not exist on Inji\App . Since you implemented __get , consider adding a @property annotation.
![]() The method
customAsset() does not exist on Inji\Module . It seems like you code against a sub-type of Inji\Module such as Inji\Db .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() The method
customAsset() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||||
35 | } else { |
||||||||||
36 | App::$cur->view->customAsset('css', '/static/libs/vendor/' . ucfirst($libName) . '/' . $file, $libName); |
||||||||||
37 | } |
||||||||||
38 | } |
||||||||||
39 | } |
||||||||||
40 | if (!empty($className::$files['js'])) { |
||||||||||
41 | foreach ($className::$files['js'] as $file) { |
||||||||||
42 | if (strpos($file, '/') === 0 || strpos($file, 'http') === 0) { |
||||||||||
43 | App::$cur->view->customAsset('js', $file, $libName); |
||||||||||
44 | } else { |
||||||||||
45 | App::$cur->view->customAsset('js', '/static/libs/vendor/' . ucfirst($libName) . '/' . $file, $libName); |
||||||||||
46 | } |
||||||||||
47 | } |
||||||||||
48 | } |
||||||||||
49 | if (!empty($className::$files['bower'])) { |
||||||||||
50 | $this->bowerFiles($libName, $className::$files['bower'], $options); |
||||||||||
51 | } |
||||||||||
52 | } |
||||||||||
53 | } |
||||||||||
54 | |||||||||||
55 | public function bowerFiles($libName, $files, $options) { |
||||||||||
56 | if (!empty($files['css']) && (!isset($options['loadCss']) || $options['loadCss'])) { |
||||||||||
57 | foreach ($files['css'] as $file) { |
||||||||||
58 | App::$cur->view->customAsset('css', '/cache/static/bowerLibs/' . $file, $libName); |
||||||||||
0 ignored issues
–
show
The property
view does not exist on Inji\App . Since you implemented __get , consider adding a @property annotation.
![]() |
|||||||||||
59 | } |
||||||||||
60 | } |
||||||||||
61 | if (!empty($files['js'])) { |
||||||||||
62 | foreach ($files['js'] as $file) { |
||||||||||
63 | App::$cur->view->customAsset('js', '/cache/static/bowerLibs/' . $file, $libName); |
||||||||||
64 | } |
||||||||||
65 | } |
||||||||||
66 | } |
||||||||||
67 | |||||||||||
68 | public function staticCalled($file, $dir) { |
||||||||||
69 | $libPath = preg_replace('!^libs/!', '', $file); |
||||||||||
70 | $libName = substr($libPath, 0, strpos($libPath, '/')); |
||||||||||
71 | $className = 'Inji\Libs\\' . ucfirst($libName); |
||||||||||
72 | if (class_exists($className)) { |
||||||||||
73 | if (!empty($className::$programDirs)) { |
||||||||||
0 ignored issues
–
show
|
|||||||||||
74 | $fileDir = substr($libPath, strlen($libName) + 1, strpos($libPath, '/', strlen($libName) + 1) - strlen($libName) - 1); |
||||||||||
75 | foreach ($className::$programDirs as $programDir) { |
||||||||||
76 | if ($programDir == $fileDir) { |
||||||||||
77 | include $dir . $file; |
||||||||||
78 | exit(); |
||||||||||
0 ignored issues
–
show
|
|||||||||||
79 | } |
||||||||||
80 | } |
||||||||||
81 | } |
||||||||||
82 | } |
||||||||||
83 | return $dir . $file; |
||||||||||
84 | } |
||||||||||
85 | |||||||||||
86 | public function getPath($args) { |
||||||||||
87 | if (!empty($args[0])) { |
||||||||||
88 | $libName = 'Inji\Libs\\' . ucfirst($args[0]); |
||||||||||
89 | if (class_exists($libName) && !empty($libName::$staticDirs)) { |
||||||||||
0 ignored issues
–
show
|
|||||||||||
90 | $file = implode('/', array_slice($args, 1)); |
||||||||||
91 | foreach ($libName::$staticDirs as $dir) { |
||||||||||
92 | if (strpos($file, $dir) === 0) { |
||||||||||
93 | return \App::$primary->path . '/vendor/' . $file; |
||||||||||
94 | } |
||||||||||
95 | } |
||||||||||
96 | } |
||||||||||
97 | } |
||||||||||
98 | return false; |
||||||||||
99 | } |
||||||||||
100 | } |