cheddar-getter/client
Composer 安装命令:
composer require cheddar-getter/client
包简介
The official PHP client for the CheddarGetter API
关键字:
README 文档
README
Via Composer
- Get Composer
- Learn Composer
- Define the requirement in your project
composer.jsonfile:
"require": { "cheddar-getter/client": "*" }
- Run
composer installfrom your command line. - Make sure you either have the cUrl extension installed in your PHP build or
Zend_Http_Client (ZF1) is available via autoload. Our
composer.jsononly suggests these packages but one or the other is required unless you build your own HTTP adapter (see below).
As a Git submodule
git clone git://github.com/marcguyer/cheddargetter-client-php.git /path/to/includepath/CheddarGetter
The 'CheddarGetter' directory must not exist prior to running the above command.
Just download it, geez
Download and unzip the files and put them in a directory called /path/to/includepath/CheddarGetter
Basic Usage
Instantiate the Client Object
<?php $client = new CheddarGetter_Client( 'https://[theurlforcheddargetter.com]', '[yourusername]', '[yourpassword]', '[yourproductcode]' ); ?>
Create a Customer
<?php $data = array( 'code' => 'EXAMPLE_CUSTOMER', 'firstName' => 'Example', 'lastName' => 'Customer', 'email' => 'example_customer@example.com', 'subscription' => array( 'planCode' => 'THE_PLAN_CODE', 'ccFirstName' => 'Example', 'ccLastName' => 'Customer', 'ccNumber' => '4111111111111111', 'ccExpiration' => '04/2011' ) ); $customer = $client->newCustomer($data); print_r($customer->toArray()); echo $customer->toJson(); ?>
Get a Customer
<?php $customer = $client->getCustomer('EXAMPLE_CUSTOMER'); print_r($customer->toArray()); echo $customer->toJson(); ?>
Error Handling
CheddarGetter_Client throws CheddarGetter_Client_Exception containing the error information.
CheddarGetter_Response throws CheddarGetter_Response_Exception containing the error information.
If the CheddarGetter API returns an error document, a CheddarGetter_Response_Exception is thrown. This can happen during the normal course of operation and the error data in the exception should be presented to the user or handled according to your specs. Here's a quick and dirty example:
<?php $data = array( 'code' => 'EXAMPLE_CUSTOMER', 'firstName' => 'Example', 'lastName' => 'Customer', 'email' => 'example_customer@example.com', 'subscription' => array( 'planCode' => 'A_PAID_PLAN', 'ccFirstName' => 'Example', 'ccLastName' => 'Customer', 'ccNumber' => '4111111111111111', 'ccExpiration' => '04/2011' ) ); try { $customer = $client->newCustomer($data); // under some circumstances, the customer is created but // contains an embedded error that needs to be handled $customer->handleEmbeddedErrors(); } catch (CheddarGetter_Response_Exception $re) { die($re->getCode() . '-' . $re->getAuxCode() . ': ' . $re->getMessage()); } ?>
More information about errors is available in the Error Handling knowledge base article. You can and should test by simulating the possible errors.
Advanced Usage
The adapter pattern (thanks to https://github.com/stof) is used so you can specify your own http adapter and/or super globals access adapter. The default built-in adapters use cUrl for http communication, and super globals are accessed directly. Also included are Zend Framework compatible adapters. If you've created an adapter of your own that should be included, just send us a pull request from your fork. Here's an example using a custom HTTP adapter:
<?php $client = new CheddarGetter_Client( 'https://theurlforcheddargetter.com', '[yourusername]', '[yourpassword]', '[yourproductcode]', new MyHTTPAdapter() ); $customers = $client->getCustomers(); print_r($customers->toArray()); echo $customers->toJson(); ?>
Specify a custom HTTP adapter
<?php CheddarGetter_Client::setHttpClient( new MyCustomClient() ); ?>
Specify a custom super globals access adapter
<?php CheddarGetter_Client::setRequestAdapter( new MyCustomAdapter() ); ?>
Contributing
Writing code
Pull requests are welcome! Please fork us, write and issue a pull request. Learn more about contributing to open source projects via GitHub
Asking questions
Support Forum
The best way to ask questions is via the CheddarGetter Support Forum.
GitHub Issues
You're also welcome to open a new issue if your inquiry is of a technical nature or you think you've found a bug.
Documentation
Check 'em out in the /docs directory or as hosted on GitHub: http://marcguyer.github.io/cheddargetter-client-php/
Also, raw API docs are here: http://cheddargetter.com/developers
cheddar-getter/client 适用场景与选型建议
cheddar-getter/client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.92k 次下载、GitHub Stars 达 28, 最近一次更新时间为 2012 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「CheddarGetter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cheddar-getter/client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cheddar-getter/client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cheddar-getter/client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 4.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 28
- 点击次数: 6
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-02-08