承接 wikimedia/css-sanitizer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

wikimedia/css-sanitizer

Composer 安装命令:

composer require wikimedia/css-sanitizer

包简介

Classes to parse and sanitize CSS

README 文档

README

Latest Stable Version License

Wikimedia CSS Parser & Sanitizer

This library implements a CSS tokenizer, parser and grammar matcher in PHP.

Usage

use Wikimedia\CSS\Parser\Parser;
use Wikimedia\CSS\Sanitizer\StylesheetSanitizer;

/** Parse a stylesheet from a string **/

$parser = Parser::newFromString( $cssText );
$stylesheet = $parser->parseStylesheet();

/** Report any parser errors **/

foreach ( $parser->getParseErrors() as list( $code, $line, $pos ) ) {
	// $code is a string that should be suitable as a key for an i18n library.
	// See errors.md for details.
	$error = lookupI18nMessage( "css-parse-error-$code" );
	echo "Parse error: $error at line $line character $pos\n";
}

/** Apply sanitization to the stylesheet **/

// If you need to customize the defaults, copy the code of this method and
// modify it.
$sanitizer = StylesheetSanitizer::newDefault();
$newStylesheet = $sanitizer->sanitize( $stylesheet );

/** Report any sanitizer errors **/

foreach ( $sanitizer->getSanitizationErrors() as list( $code, $line, $pos ) ) {
	// $code is a string that should be suitable as a key for an i18n library.
	// See errors.md for details.
	$error = lookupI18nMessage( "css-sanitization-error-$code" );
	echo "Sanitization error: $error at line $line character $pos\n";
}

/** Convert the sanitized stylesheet back to text **/

$newText = (string)$newStylesheet;

// Or if you'd rather have it minified too
$minifiedText = Wikimedia\CSS\Util::stringify( $newStylesheet, [ 'minify' => true ] );

Conformance

The library follows the following grammar specifications:

The sanitizer recognizes the following CSS modules:

And also,

Running tests

composer install --prefer-dist
composer test

Adding properties

CSS specifications typically contain a summary of value grammars in the property index section. These value grammars map directly to PHP code.

Component value types

Syntax css-sanitizer code
foo new KeywordMatcher( 'foo' )
foo | bar new KeywordMatcher( [ 'foo', 'bar' ] )
<string> $matcherFactory->string()
<url> $matcherFactory->url()
<integer> $matcherFactory->integer()
<number> $matcherFactory->number()
<ratio> $matcherFactory->ratio()
<percentage> $matcherFactory->percentage()
<length> $matcherFactory->length()
<frequency> $matcherFactory->frequency()
<angle> $matcherFactory->angle()
<time> $matcherFactory->time()
<resolution> $matcherFactory->resolution()

Component value combinators

Syntax css-sanitizer code
a b new Juxtaposition( [ a, b ] )
a && b UnorderedGroup::allOf( [ a, b ] )
a || b UnorderedGroup::someOf( [ a, b ] )
a | b new Alternative( [ a, b ] )

Component value multipliers

Syntax css-sanitizer code
a* Quantifier::star( a )
a+ Quantifier::plus( a )
a? Quantifier::optional( a )
a{3,4} Quantifier::count( a, 3, 4 )
a# Quantifier::hash( a )
a! new NonEmpty( a )

Releasing a new version

This package uses wikimedia/update-history and its conventions.

See https://www.mediawiki.org/wiki/UpdateHistory for details.

History

We required a CSS sanitizer with several properties:

  • Strict parsing according to modern standards.
  • Includes line and character position for all errors.
  • Configurable to limit unsafe constructs such as external URL references.
  • Errors are easily localizable.

We could not find a library that fit these requirements, so we created one.

Additional release history is in HISTORY.md.

wikimedia/css-sanitizer 适用场景与选型建议

wikimedia/css-sanitizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.89M 次下载、GitHub Stars 达 16, 最近一次更新时间为 2017 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 wikimedia/css-sanitizer 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 5.89M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 26
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 11
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2017-04-06