定制 expectedbehavior/php-docraptor 二次开发

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

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

expectedbehavior/php-docraptor

Composer 安装命令:

composer require expectedbehavior/php-docraptor

包简介

Official PHP wrapper for the DocRaptor API.

README 文档

README

Build Status Scrutinizer Code Quality

#PHP-DocRaptor

PHP-DocRaptor is a simple API wrapper for DocRaptor.com. You will need a DocRaptor account before you can use this library, as it requires a valid API key.

##Dependencies This wrapper requires PHP 5.4 or newer. PHP 5.4 support will be dropped when it reaches EOL. We strongly advise to migrate your projects to PHP 5.6. Other than that, only the PHP curl extension is needed.

At the moment, this library still works with PHP 5.3, but we don't guarantee that for any future releases.

##Installation

This library is PSR-4 autoloading compliant and you can install it via composer. Just require it in your composer.json.

"require": {
    "expectedbehavior/php-docraptor": "1.3.0"
}

Then run composer update resp. composer install.

##Usage

$docRaptor = new DocRaptor\ApiWrapper("YOUR_API_KEY_HERE"); // Or omit the API key and pass it in via setter
$docRaptor->setDocumentContent('<h1>Hello!</h1>')->setDocumentType('pdf')->setTest(true)->setName('output.pdf');
$file = $docRaptor->fetchDocument();

fetchDocument returns document contents by default. You can optionally provide a file path to the fetchDocument method, and the wrapper will attempt to write the returned value to that file path.

###Options

####Setting Prince Specific Options The API wrapper has the ability to set prince_options that is noted in the API documentation, where available keys are listed.

Example of setting prince version and PDF profile:

$docRaptor = new DocRaptor\ApiWrapper("YOUR_API_KEY_HERE");
$docRaptor
    ->setDocumentContent('<h1>Hello!</h1>')
    ->setDocumentType('pdf')
    ->setTest(true)
    ->setName('output.pdf')
    ->setDocumentPrinceOptions(array(
        'version' => '10',
        'profile' => 'PDF/A-1b',
    ));
$file = $docRaptor->fetchDocument();

####Asynchronous By default, PHP-DocRaptor submits requests sychronously. However, if you are trying to process large documents, you can make an asynchronous doc request. You can choose to do this by passing an argument to the setAsync method (true for asynchronous, false for synchronous request):

$docRaptor->setAsync(true);

Synchronous requests will return the file contents where as asynchronous requests will return a json response. Examples of the response can be found in the API documentation

####Async Callback URL If setAsync(true) is called and you want DocRaptor to do a POST request to your system when an asynchronous job has finished you can set the callback url via setCallbackUrl:

$docRaptor->setCallbackUrl('http://example.com/callback');

Details on the POST request can be found in the API documentation

####HTTPS or HTTP By default, PHP-DocRaptor submits requests over https. You can choose to submit via http by passing an argument to the setSecure method (true for https, false for http):

$docRaptor->setSecure(false);

NB! It IS not secure, you're basically broadcasting your api key over the network.

Privacy

By default this library will report usage statistics - the api wrapper version and PHP version - to the DocRaptor service by way of a user agent string. You can disable this by providing a config object to the ApiWrapper constructor or the HttpClient constructor.

$config     = new DocRaptor\Config(false);
$httpClient = new DocRaptor\HttpClient($config);
$docRaptor  = new DocRaptor\ApiWrapper("YOUR_API_KEY_HERE", $httpClient, $config);
// or
$config    = new DocRaptor\Config(false);
$docRaptor = new DocRaptor\ApiWrapper("YOUR_API_KEY_HERE", null, $config); // will use HttpClient by default

Alternate HTTP Implementation

Since we're injecting a HttpTransferInterface interface into the ApiWrapper you can either inject the provided HttpClient or inject your own implementation of the interface.

$httpClient = new DocRaptor\HttpClient();
$docRaptor  = new DocRaptor\ApiWrapper("YOUR_API_KEY_HERE", $httpClient);

The provided HttpClient is a very simple domain specific curl wrapper that extracts all curl functions from the ApiWrapper which makes it possible to inject a mock client for testing.

Contributing

If you find a bug, please make a new GitHub issue. If you know how to solve it, make a branch and once you're done make a new pull request.

When submitting a PR, you will need to install composer to run the tests. Once you have it installed, in the project root, run composer install. To run the tests from the project root, run vendor/bin/phpunit. They should all pass! Also we have travis and scrutinizer integration, so you can check those in your PR for things that could be better or don't work.

Releasing

With the new version number:

After pushing your new tagged version, make sure the new version shows up on Packagist.

expectedbehavior/php-docraptor 适用场景与选型建议

expectedbehavior/php-docraptor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43.49k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2015 年 04 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 expectedbehavior/php-docraptor 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-04-01