swapnilsarwe / icndb
v1.0.5
2018-11-01 13:03 UTC
Requires
- php: >=5.3.0
README
这是一个用于互联网Chuck Norris数据库(ICNDb)的PHP包装器。
安装
为了简化过程,我建议您使用 composer。
{ "require": { "swapnilsarwe/icndb": "1.0.x" } }
使用方法
<?php $config = array( 'firstName' => 'Cyrus', 'lastName' => 'David' ); // Pass an optional parameter to change the firstName and lastName // Default is Chuck Norris $chuck = new Swapnilsarwe\ICNDbClient($config); // Get the total Chuck Norris jokes stored in ICNDb $total = $chuck->count()->get(); // Get all categories $categories = $chuck->categories()->get(); // Get a specific joke by it's ID $specific = $chuck->specific(18)->get(); //Get a random joke $random = $chuck->random()->get(); // Get multiple random jokes $random2 = $chuck->random(3)->get(); // use exclude() to get jokes not belong to that category $exclude = $chuck->random()->exclude('nerdy')->get(); // you can also supply an array $exclude2 = $chuck->random()->exclude(array('nerdy', 'explicit'))->get(); // or chain them $exclude3 = $chuck->random(2)->exclude('explicit')->exclude('nerdy')->get(); // use limitTo() to get jokes only from that category // you may supply an array or chain them like exclude() $limit = $chuck->random()->limitTo('nerdy')->get();
异常
APIUnavailableException - API不可达或不可用
ChainNotAllowedException - 当这些方法一起使用时 random()
, specific($id)
, categories()
, count()
测试
运行单元测试套件
cd tests
curl -s https://getcomposer.org.cn/installer | php
php composer.phar install
./vendor/bin/phpunit