1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Code Mirror |
5
|
|
|
* @author Iurii Makukh |
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\codemirror; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Module, |
13
|
|
|
gplcart\core\Library; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Main class for Code Mirror module |
17
|
|
|
*/ |
18
|
|
|
class Codemirror extends Module |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Library class instance |
23
|
|
|
* @var \gplcart\core\Library $library |
24
|
|
|
*/ |
25
|
|
|
protected $library; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Library $library |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Library $library) |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
|
34
|
|
|
$this->library = $library; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Implements hook "library.list" |
39
|
|
|
* @param array $libraries |
40
|
|
|
*/ |
41
|
|
|
public function hookLibraryList(array &$libraries) |
42
|
|
|
{ |
43
|
|
|
$libraries['codemirror'] = array( |
44
|
|
|
'name' => 'CodeMirror', |
45
|
|
|
'description' => 'In-browser code editor', |
46
|
|
|
'type' => 'asset', |
47
|
|
|
'module' => 'codemirror', |
48
|
|
|
'url' => 'https://codemirror.net', |
49
|
|
|
'download' => 'http://codemirror.net/codemirror.zip', |
50
|
|
|
'version_source' => array( |
51
|
|
|
'file' => 'vendor/codemirror/CodeMirror/package.json' |
52
|
|
|
), |
53
|
|
|
'files' => array( |
54
|
|
|
'vendor/codemirror/CodeMirror/lib/codemirror.js', |
55
|
|
|
'vendor/codemirror/CodeMirror/lib/codemirror.css', |
56
|
|
|
), |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Implements hook "route.list" |
62
|
|
|
* @param array $routes |
63
|
|
|
*/ |
64
|
|
|
public function hookRouteList(array &$routes) |
65
|
|
|
{ |
66
|
|
|
$routes['admin/module/settings/codemirror'] = array( |
67
|
|
|
'access' => 'module_edit', |
68
|
|
|
'handlers' => array( |
69
|
|
|
'controller' => array('gplcart\\modules\\codemirror\\controllers\\Settings', 'editSettings') |
70
|
|
|
) |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Add codemirror library and context files depending on the module settings |
76
|
|
|
* @param \gplcart\core\Controller $object |
77
|
|
|
*/ |
78
|
|
|
public function addLibrary($object) |
79
|
|
|
{ |
80
|
|
|
if (!$object instanceof \gplcart\core\Controller) { |
|
|
|
|
81
|
|
|
throw new \InvalidArgumentException('Argument must be instance of gplcart\core\Controller'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$settings = $this->config->module('codemirror'); |
85
|
|
|
$object->setJsSettings('codemirror', $settings); |
86
|
|
|
|
87
|
|
|
$options = array('aggregate' => false); |
88
|
|
|
$base = 'system/modules/codemirror/vendor/codemirror/CodeMirror'; |
89
|
|
|
|
90
|
|
|
$object->addAssetLibrary('codemirror', $options); |
91
|
|
|
$object->setCss("$base/theme/{$settings['theme']}.css", $options); |
92
|
|
|
|
93
|
|
|
foreach ($settings['mode'] as $mode) { |
94
|
|
|
$object->setJs("$base/mode/$mode/$mode.js", $options); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Implements hook "module.enable.after" |
100
|
|
|
*/ |
101
|
|
|
public function hookModuleEnableAfter() |
102
|
|
|
{ |
103
|
|
|
$this->library->clearCache(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Implements hook "module.disable.after" |
108
|
|
|
*/ |
109
|
|
|
public function hookModuleDisableAfter() |
110
|
|
|
{ |
111
|
|
|
$this->library->clearCache(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Implements hook "module.install.after" |
116
|
|
|
*/ |
117
|
|
|
public function hookModuleInstallAfter() |
118
|
|
|
{ |
119
|
|
|
$this->library->clearCache(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Implements hook "module.uninstall.after" |
124
|
|
|
*/ |
125
|
|
|
public function hookModuleUninstallAfter() |
126
|
|
|
{ |
127
|
|
|
$this->library->clearCache(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.