arthurkushman /
querypath
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * Do an XML lookup from MusicBrainz. |
||||
| 4 | * |
||||
| 5 | * This example shows how to make a simple REST-style request against a remote |
||||
| 6 | * server. (For a more advanced example of HTML requests, see {@link sparql.php}) |
||||
| 7 | * |
||||
| 8 | * This does two HTTP requests -- one to get information about a band, and another |
||||
| 9 | * to get a list of albums put out by that band. |
||||
| 10 | * |
||||
| 11 | * TODO: Fix the output. |
||||
| 12 | * |
||||
| 13 | * |
||||
| 14 | * @author M Butcher <[email protected]> |
||||
| 15 | * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license. |
||||
| 16 | * @see http://musicbrainz.org |
||||
| 17 | */ |
||||
| 18 | require_once '../src/QueryPath/QueryPath.php'; |
||||
| 19 | |||||
| 20 | $artist_url = 'http://musicbrainz.org/ws/1/artist/?type=xml&name=u2'; |
||||
| 21 | $album_url = 'http://musicbrainz.org/ws/1/release/?type=xml&artistid='; |
||||
| 22 | try { |
||||
| 23 | $artist = qp($artist_url, 'artist:first'); |
||||
| 24 | if ($artist->size() > 0) { |
||||
| 25 | $id = $artist->attr('id'); |
||||
| 26 | print '<p>The best match we found was for ' . $artist->children('name')->text() . PHP_EOL; |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 27 | print '</p><p>Artist ID: ' . $id . PHP_EOL; |
||||
|
0 ignored issues
–
show
Are you sure
$id of type QueryPath\DOMQuery|mixed|null can be used in concatenation?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 28 | print '</p><p>Albums for this artist' . PHP_EOL; |
||||
| 29 | print '</p><p><a href="'.$album_url . urlencode($id).'">'.$album_url.'</a></p>'; |
||||
|
0 ignored issues
–
show
It seems like
$id can also be of type QueryPath\DOMQuery and null; however, parameter $string of urlencode() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 30 | $albums = qp($album_url . urlencode($id))->writeXML(); |
||||
| 31 | |||||
| 32 | foreach ($albums as $album) { |
||||
| 33 | print $album->find('title')->text() . PHP_EOL; |
||||
| 34 | // Fixme: Label is broken. See Drupal QueryPath module. |
||||
| 35 | print '(' . $album->next('label')->text() . ')' .PHP_EOL; |
||||
| 36 | } |
||||
| 37 | } |
||||
| 38 | } |
||||
| 39 | catch (Exception $e) { |
||||
| 40 | print $e->getMessage(); |
||||
| 41 | } |
||||
| 42 |