Zend Framework module to consume Wikipedia API
Install the module using Composer into your application's vendor directory. Add the following line to your
composer.json
.
{
"require": {
"firelike/wikipedia-api": "^1.0"
}
}
Enable the module in your application.config.php
file.
return array(
'modules' => array(
'Firelike\Wikipedia'
)
);
Copy and paste the wikipedia.local.php.dist
file to your config/autoload
folder and customize it with your credentials and
other configuration settings. Make sure to remove .dist
from your file.Your wikipedia.local.php
might look something like the following:
<?php
return [
'wikipedia_service' => [
'log'=>[
'enable'=>false,
'message_formats'=>[
'{method} {uri} HTTP/{version} {req_body}',
'RESPONSE: {code} - {res_body}',
],
'logger'=>[
'stream' => 'php://output',
]
]
]
];
Calling from your code:
use Firelike\Wikipedia\Request\QueryAction as QueryActionRequest;
use Firelike\Wikipedia\Service\WikipediaService;
$request = new QueryActionRequest();
$request->setTitles('HarperCollins')
->setProp('extracts');
$service = new WikipediaService();
$result = $service->query($request);
$pages= $result->toArray()['query']['pages'];
var_dump($pages);
Using the console:
php public/index.php wikipedia query --titles=HarperCollins -v
- query