PHP code example of duffleman / baelorphp

1. Go to this page and download the library: Download duffleman/baelorphp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

duffleman / baelorphp example snippets


use Duffleman\baelor\BaelorAPI;

$api = new BaelorAPI('api-key');
$albumCollection = $api->getAlbums();

use Duffleman\baelor\BaelorAPI;

$api = new BaelorAPI();
$user = $api->createUser('myUsername', 'myEmail', 'myPassword');

$ourNewAPIKey = $user->api_key;

use Duffleman\baelor\BaelorAPI;

$api = new BaelorAPI();
$api->login('myUsername', 'myPassword');

$response = $api->getAlbums(); // Returns full set of Albums.

use Duffleman\baelor\BaelorAPI;

$api = new BaelorAPI('api-key');

$album = $api->getAlbums('1989');

use Duffleman\baelor\BaelorAPI;

$api = new BaelorAPI('api-key');

$album = $api->getAlbums('1989');

$songs = $album->attributes;

use Duffleman\baelor\BaelorAPI;

$api = new BaelorAPI('api-key');

$songCollection = $api->getSongs();

use Duffleman\baelor\BaelorAPI;

$api = new BaelorAPI('api-key');

$song = $api->getSongs('style');

$length = $song->length; // We can access attributes directly.

use Duffleman\baelor\BaelorAPI;
use Duffleman\baelor\Results\Lyrics;

$api = new BaelorAPI('api-key');

$song = $api->getSongs('style');

$lyrics = new Lyrics($song, $api);

echo($lyrics->toHTML());

use Duffleman\baelor\BaelorAPI;

$api = new BaelorAPI('api-key');

$bae = $api->getBae('word');
// or
$bae = $api->getBae();

var_dump($bae);

use Duffleman\baelor\BaelorAPI;
use Duffleman\baelor\Results\Lyrics;

$api = new BaelorAPI('api-key');

$song = $api->getSongs('style');
$lyrics = new Lyrics($song, $api);

$lines = $lyrics->toArray(true); // true because we do want to strip empty lines.

$longestLength = 0;
$longestLine = '';
foreach($lines as $line) {
  $lineLength = strlen($line);
  if($lineLength > $longestLength) {
    $longestLength = $lineLength;
    $longestLine = $line;
  }
}

echo("The longest line is {$lineLength} characters long. It reads: {$longestLine}.");