HTMLPurifier 扩展包 clean 方法如何应用到 TopicObserver.php 中的?
扩展包publish 以后 helpers.php 所有函数都被全局注册了吗?就是说在控制器,或者模型之类的都可以使用对吗?
还有helpers.php 代码中 用了一个判断函数是否存在是为了解决函数名冲突问题吗? 是不是所有的扩展包都可以定义helpers.php函数用于全局使用? 有没有关于扩展包的结构的讲解?求一篇准确的~谢谢大家了嗷~
vendor\mews\purifier\src\helpers.php
<?php
if (!function_exists('clean')) {
function clean($dirty, $config = null)
{
return app('purifier')->clean($dirty, $config);
}
}
app\Observers\TopicObserver.php
public function saving(Topic $topic)
{
$topic->body = clean($topic->body,'user_topic_body');
$topic->excerpt = make_excerpt($topic->body);
}
推荐文章: