This library is an PHP 5.3 implementation of the Discogs API v2.0. The Discogs API is a REST-based interface. By using this library you don't have to worry about communicating with the API: all the hard work has already be done.
This library is released under the MIT license. See the complete license in the LICENSE file.
Start by installing composer and finally install the dependencies.
PHP >=5.3.0
Creating a new instance is as simple as:
<?php
$service = new \Discogs\Service();
<?php
$resultset = $service->search(array(
'q' => 'Meagashira',
'label' => 'Enzyme'
));
// Total results
echo count($resultset)."\n";
// Total pages
$pagination = $resultset->getPagination();
echo count($pagination)."\n";
// Fetch all results (use on your own risk, only one request per second allowed)
do {
$pagination = $resultset->getPagination();
echo $pagination->getPage().'<br />';
foreach ($resultset as $result) {
echo get_class($result).'<br />';
}
} while($resultset = $service->next($resultset));
<?php
$label = $service->getLabel(1);
echo $label->getName()."\n";
<?php
$artist = $service->getArtist(1);
echo $artist->getName()."\n";
<?php
$release = $service->getRelease(1);
echo $release->getTitle()."\n";
<?php
$master = $service->getMaster(1);
echo $master->getTitle()."\n";
You have two options in which form to receive formatted response: as object using supplied models, or as plain array.
By default (if nothing has been set via setter) Model response transformer is chosen. You can manipulate it via
the setResponseTransfomer
setter:
$discogs->setResponseTransformer(new \Discogs\ResponseTransformer\Model());
// or
$discogs->setResponseTransformer(new \Discogs\ResponseTransformer\Hash());
You can also set your own response transformer which need to implement the ResponseTransformerInterface
NOTE At this moment only the "Database" resource has been implemented. The "Marketplace" and "User" are missing.
Further documentation can be found at the Discogs API v2.0 Documentation.