zoukankan      html  css  js  c++  java
  • 写一个PHP单例模式

     1 <?php
     2 /**
     3  * Created by PhpStorm. 5  * Date: 2019/1/29
     6  * Time: 17:44
     7  */
     8 
     9 namespace App\Models;
    10 
    11 use DfaFilter\SensitiveHelper;
    12 use App\Models\Sensitive;
    13 
    14 class StringHelper {
    15 
    16     static private $instance;
    17     static private $handle;
    18 
    19     //敏感词库不能为空,所以必须要有默认值
    20     private function getWordArray(){
    21         $sensitive = new Sensitive;
    22         $wordData = $sensitive ->getAllWordsCache();
    23         return $wordData;        
    24     }
    25 
    26     private function __construct(){
    27         self::$handle = SensitiveHelper::init()->setTree($this->getWordArray());
    28     }
    29 
    30     static public function getInstance(){
    31         if(!self::$instance instanceof self){
    32             self::$instance = new self();
    33         }
    34         return self::$instance;
    35     }
    36 
    37     //敏感词用*代替
    38     public function replace($content){
    39         if(empty($content)){
    40             return $content;
    41         }
    42         $content = self::$handle->replace($content,"***");
    43         return $content;
    44     }
    45 
    46     //判断是否包含敏感词 
    47     public function islegal($content){
    48         return self::$handle->islegal($content);
    49     }
    50 
    51     
    52 
    53 
    54 }
  • 相关阅读:
    题目
    先贤祠3
    先贤祠2
    先贤祠1
    论文他引次数及ESI高被引论文查询方法
    [唐诗]古风(其三十一)-李白
    [唐诗]古风(其二十四)-李白
    [唐诗]古风(其十九)-李白
    [唐诗]古风(其十五)-李白
    [唐诗]古风(其三)-李白
  • 原文地址:https://www.cnblogs.com/lianruihong/p/15580691.html
Copyright © 2011-2022 走看看