php - 致命错误:无法声明 JSMin 类,因为该名称已在 opencart 3.0.3.7 中使用
问题描述
我该如何解决一段代码上的错误,我找不到关于如何解决它的解释,如果有人遇到像我这样的问题,我等你帮助我
class JSMin {
const ORD_LF = 10;
const ORD_SPACE = 32;
const ACTION_KEEP_A = 1;
const ACTION_DELETE_A = 2;
const ACTION_DELETE_A_B = 3;
protected $a = '';
protected $b = '';
protected $input = '';
protected $inputIndex = 0;
protected $inputLength = 0;
protected $lookAhead = null;
protected $output = '';
// -- Public Static Methods --------------------------------------------------
/**
* Minify Javascript
*
* @uses __construct()
* @uses min()
* @param string $js Javascript to be minified
* @return string
*/
public static function minify($js) {
$jsmin = new JSMin($js);
return $jsmin->min();
}
解决方案
这里有几点注意事项:
- 我不使用开放式购物车,所以我不知道你是如何调用这个类的
- 您似乎正在尝试使用存档的 git repo
rgrove/jsmin-php
,位于此处https://github.com/rgrove/jsmin-php
作者已将其存档,并敦促不要再使用它,并建议使用其他更好的解决方案。
可能性一
但是,如果您要继续使用它,您可以使用如下所示的命名空间来修改它——假设 opencart 确实已经在其本机代码中声明了它:
<?php
namespace DeprecatedDontUse;
class JSMin
{
const ORD_LF = 10;
const ORD_SPACE = 32;
const ACTION_KEEP_A = 1;
const ACTION_DELETE_A = 2;
const ACTION_DELETE_A_B = 3;
protected $a = '';
protected $b = '';
protected $input = '';
protected $inputIndex = 0;
protected $inputLength = 0;
protected $lookAhead = null;
protected $output = '';
....etc
然后当你去使用它时,你会这样做:
<?php echo \DeprecatedDontUse\JSMin::minify($JSstring) ?>
那应该解决重复的类命名问题。
可能性二
如果您没有以某种方式将此类自动加载到您的应用程序中,而是手动将其包含在文件中,那么您只需将脚本保持原样(无命名空间),而不是使用require('/path/to/jsmin.php');
or include('/path/to/jsmin.php');
(无论您使用哪个),您将使用该once
版本其中,所以include_once('/path/to/jsmin.php');
或require_once('/path/to/jsmin.php');
。
这是为了防止 opencart 在整个执行过程中多次加载您添加的任何脚本。它只会加载一次类,不会给你这个错误。
推荐阅读
- node.js - Nodejs + Reactjs + passportjs google登录两个callbackURL作为子站点
- wordpress - 如何在 WordPress 网站中将 URL 从 www.example.com/2020/70 删除到 www.example.com?
- django - 未找到“”的反向。'' 不是有效的视图函数或模式名称 - django 修复
- dotnetnuke - 2sxc cms.run 预填充编辑
- spring-boot - AspectJ 自定义参数注释在 Spring Boot 中不起作用
- c++ - C++ - 套接字编程 - 多线程程序抛出致命的程序退出请求
- reactjs - 我需要为 react-youtube 添加哪个加载器
- java - 如何删除“错误:找不到符号 holder.name.setText(personNames.get(position))”的错误
- python - Neo4j图形平台如何将数据发布到搜索框
- http-post - Microsoft Teams HttpPost 操作因 BadRequest 而失败