定制 stolz/laravel-html-tidy 二次开发

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

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

stolz/laravel-html-tidy

Composer 安装命令:

composer require stolz/laravel-html-tidy

包简介

HTML Tidy middleware for Laravel

README 文档

README

tl;dr

Laravel-html-tidy is a Laravel middleware that parses Laravel's Response objects in order to detect and fix markup problems as well as to improve the layout and indent style of the resulting markup.

How it works

When editing HTML it's easy to make mistakes. Did you ever forget to close a <div> tag that made a mess of all your layout and then you went crazy trying to figure out what/where the problem was?. Wouldn't it be nice if there was a simple way to detect and fix these mistakes automatically and at the same time tidy up sloppy editing into nicely layed out markup? Well that is what W3C HTML Tidy utility is for!. HTML Tidy is available as an official PHP extension and this package makes using it with Laravel a breeze.

Once the middleware is enabled every time there is a problem with your HTML code you will see an error messages on your screen. Tidy will try its best to fix the problem for you. Also, if you take a look of the final HTML code sent to the browser you will get a pleasant surprise.

Note: HTML Tidy is fast but parsing output always adds a small overhead so consider using the middleware only in development environments.

Requirements

  • PHP compiled with HTML Tidy support and Tidy extension enabled in php.ini.
  • Laravel framework.

Installation

Install via composer

composer require stolz/laravel-html-tidy --dev

If you are using an old version of Laravel without the package discovery feature (or if you have disabled it), then you have to manually edit config/app.php file and add the service provider to the providers array:

'providers' => [
	...
	'Stolz\HtmlTidy\ServiceProvider',
],

The default settings can validate both (x)HTML 4 and HTML 5 markups. If you want to customize the settings create the file config/tidy.php by running

php artisan vendor:publish --provider='Stolz\HtmlTidy\ServiceProvider'

Usage

If you want the middleware to be run only on specific routes, add the class in the $routeMiddleware property of your app/Http/Kernel.php file, with your desired short-hand key.

protected $routeMiddleware = [
	...
	'tidy' => 'Stolz\HtmlTidy\Middleware',
];

Now you can use it in your routes.php file

Route::get('some/url', function () {...})->middleware('tidy');

Conversely if you want the middleware to be run on every HTTP request to your application, add the class in the $middleware property of your app/Http/Kernel.php file.

protected $middleware = [
	...
	'Stolz\HtmlTidy\Middleware',
];

Laravel 4

If you are still using Laravel 4 instead of loading Stolz\HtmlTidy\ServiceProvider use Stolz\HtmlTidy\LegacyServiceProvider and then in your routes.php file use something like this

// Register filter
Route::filter('tidy', function($route, $request, $response) {
	return app('stolz.tidy')->handle($request, $response);
});

// Use as an 'after' filter
Route::get('/', ['after' => 'tidy', function() {
	return View::make('home');
}]);

License

MIT License © Stolz

Read the provided LICENSE file for details.

stolz/laravel-html-tidy 适用场景与选型建议

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

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

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

围绕 stolz/laravel-html-tidy 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 8.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 27
  • 点击次数: 24
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 2
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-03-03