tcopestake/w3capi 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tcopestake/w3capi

Composer 安装命令:

composer require tcopestake/w3capi

包简介

A PHP wrapper/client for the W3C validator API

README 文档

README

A PHP wrapper/client for the W3C validator API

Quick disclaimer

I'm unsure how stable the actual W3C API is, as it's documented as experimental and subject to change; don't be surprised if things stop working. You can read more at http://validator.w3.org/docs/api.html

Pay special attention to this notice:

If you wish to call the validator programmatically for a batch of documents, please make sure that your script will sleep for at least 1 second between requests. The Markup Validation service is a free, public service for all, your respect is appreciated. thanks.

When making multiple calls through a validator instance, this will be done for you (see below).

Requirements:

  • PHP 5.3+
  • * cURL
  • * SimpleXML

* Can be abstracted away by providing alternative interfaces

Installation

This package can be installed manually or via Composer.

Composer

Add the following to your project's composer.json:

"repositories": [
    {
        "type": "vcs",
        "url":  "https://github.com/tcopestake/w3capi"
    }
],

and:

"require": {
    "tcopestake/w3capi": "*"
},

Manual

Download and extract the files.

If your project doesn't already have a suitable autoloader, you can use the one provided by including src/bootstrap.php:

include('path/to/src/bootstrap.php');

Usage

The validator

To validate a document:

$validator = new \W3CAPI\Validator;

try {
    $validator->validate('http://url.test.com/a-html-page');
} catch(\W3CAPI\Exceptions\SoapClientBadResponse $e) {
    echo "Most likely, W3C reported a server error.";
} catch(\W3CAPI\ValidatorUnknownError $e) {
    echo "Something went wrong, but we don't know what.";
}

If successful, information can then be retrieved from the instance, such as whether the document passed validation:

echo ($validator->isValid()) ? 'Valid' : 'Invalid';

and information about semantic validation errors:

if($validator->getErrorCount() > 0) {
    foreach($validator->getErrors() as $error) {
        /*
         * $error will be an array
         * containing the error message, etc.
         *
         */
    }
}

and information about validation warnings:

if($validator->getWarningCount() > 0) {
    foreach($validator->getWarnings() as $warning) {
        /*
         * $warning will be an array
         * containing the warning message, etc.
         *
         */
    }
}

If you wish to validate another document, the validator instance can be easily reused:

try {
    $validator->validate('http://another.url.com/shame.css');
} catch(\W3CAPI\Exceptions\SoapClientBadResponse $e) {
    echo "Most likely, W3C reported a server error.";
} catch(\W3CAPI\ValidatorUnknownError $e) {
    echo "Something went wrong, but we don't know what.";
}

Note that when making subsequent calls, the validator class will enforce W3C's "1 second" rule by delaying sending the request if necessary.

Tests

There are unit tests.

Possible developments(?)

  • Support for validating documents via POST upload.
  • More documentation (esp. on dependency injection).
  • Revisit the XML parser.
  • More transparency between classes e.g. ability to retrieve HTTP headers
  • Peer pressure is forcing me to switch to PSR-2, but my muscle memory forgets this sometimes.

tcopestake/w3capi 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 31
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

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