定制 chromabits/purifier 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chromabits/purifier

最新稳定版本:2.1.1

Composer 安装命令:

composer require chromabits/purifier

包简介

HTMLPurifier package for Laravel 5

README 文档

README

A HTMLPurifier service for Laravel 5

Installation

Note: This package is for Laravel 5 only. It does not include a Facade and it requires certain "Contracts" interfaces only available in Laravel 5.

This package can be installed via Composer by requiring the chromabits/purifier package in your project's composer.json:

{
    "require": {
        "laravel/framework": "~5.0",
        "chromabits/purifier": "~2.1"
    }
}

Update your packages with composer update or install with composer install.

Usage

To use the HTMLPurifier service, you must register the service provider when bootstrapping your Laravel application.

Find the providers key in config/app.php and register the HTMLPurifier Service Provider:

    'providers' => [
        // ...
        'Chromabits\Purifier\PurifierServiceProvider',
    ]

After registering the provider, classes requiring the Chromabits\Purifier\Contracts\Purifier contract will get the purifier service instance through dependency injection (See below for examples).

Configuration

To use your own settings, copy the config/purifier.php file in this package into your application's config directory, and modify as needed.

You can define mutiple sets of configurations by sspecifying new entries in the settings array key:

return [
    "settings" => [
        "default" => [
            "HTML.SafeIframe" => 'true',
            "URI.SafeIframeRegexp" => "%^(http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
        ],
        "titles" => [
            'AutoFormat.AutoParagraph' => false,
            'AutoFormat.Linkify' => false,
        ]
    ],
];

The service will use the default key as the default set of configuration, any other configuration will extend this. If a configuraiton file is not provided, the service will use safe defaults.

Example

Full usage example with default settings within a Laravel 5 controller:

<?php

namespace Http\Controllers;

use Chromabits\Purifier\Contracts\Purifier;
use HTMLPurifier_Config;
use Illuminate\Http\Request;

/**
 * Class IndexController
 *
 * @package App\Http\Controllers;
 */
class IndexController {
	/**
	 * @var Purifier
	 */
	protected $purifier;
	
	/**
	 * Construct an instance of MyClass
	 *
	 * @param Purifier $purifier
	 */
	public function __construct(Purifier $purifier) {
		// Inject dependencies
		$this->purifier = $purifier;
	}
	
	/**
	 * Get index page
	 *
	 * @param Request $request
	 */
	public function getIndex(Request $request)
	{
		return $this->purifier->clean($request->input('first_name'));
	}
}

With dynamic configuration:

	// Using config entries from purifier.php
	$this->purifier->clean('This is my H1 title', 'titles');
	
	// Passing configuration from an array (inherits default config)
	$this->purifier->clean(
		'This is my H1 title',
		[ 'Attr.EnableID' => true ]
	);

Interacting with the HTMLPurifier_Config object directly using a custom service provider and Closure:

<?php

namespace App\Providers;

use Chromabits\Purifier\Purifier;
use Illuminate\Support\ServiceProvider;

/**
 * ...
 */
class CustomPurifierServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        // Bind contract with concrete implementation
        $this->app->bind(
        	'Chromabits\Purifier\Contracts\Purifier',
        	function ($app) {
          		new Purifier($app, $app['config'], function (HTMLPurifier_Config $config) {
                		// Do stuff with $config here
                		return $config;
                }
            }
        );
    }
}

License

Based on the Laravel 4 Purifier service

See LICENSE.md for license information

chromabits/purifier 适用场景与选型建议

chromabits/purifier 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.85k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2014 年 12 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「htmlpurifier」 「laravel」 「Purifier」 「laravel 5」 「l5」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 chromabits/purifier 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 chromabits/purifier 我们能提供哪些服务?
定制开发 / 二次开发

基于 chromabits/purifier 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 24.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 5
  • Forks: 230
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL
  • 更新时间: 2014-12-13