-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from benrowe/releases/build-5
Releases/build 5
- Loading branch information
Showing
33 changed files
with
570 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/vendor/ | ||
.env | ||
.idea | ||
/storage/views/ | ||
/storage/views/ | ||
/storage/cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,11 @@ | |
|
||
use Exception; | ||
|
||
/** | ||
* HttpException | ||
* | ||
* @package App\Exceptions | ||
*/ | ||
class HttpException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Exceptions; | ||
|
||
use RuntimeException as Exception; | ||
|
||
/** | ||
* RuntimeException | ||
* | ||
* Represents a simple runtime Exception that is localised to this application | ||
* | ||
* @package App\Exceptions | ||
*/ | ||
class RuntimeException extends Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace App\Services\LastFm\Api; | ||
|
||
use App\Services\LastFm\Response\AbstractResponse; | ||
|
||
/** | ||
* Provides paginated result set functionality to the lastfm api components | ||
* | ||
* @package App\Services\LastFm\Api | ||
*/ | ||
trait TraitSupportsPagintation | ||
{ | ||
private function buildPaginationParams($params) | ||
{ | ||
if (!isset($params['limit'])) { | ||
$params['limit'] = $this->client->getOption('pagination.limit', 5); | ||
} | ||
if (!isset($params['page']) || $params['page'] < 1) { | ||
$params['page'] = 1; | ||
} | ||
|
||
return $params; | ||
} | ||
|
||
/** | ||
* @param $methodName | ||
* @param $params | ||
* @param $type | ||
* @param $key | ||
* @return \App\Services\LastFm\Response\ResultSet | ||
*/ | ||
private function buildPaginationResultSet($methodName, $params, $type, $key) | ||
{ | ||
$params = $this->buildPaginationParams($params); | ||
$response = $this->client->request($methodName, $params); | ||
|
||
/** | ||
* !important | ||
* see method note below | ||
*/ | ||
$response = $this->fixLastFmPaginationBug($response, $key); | ||
|
||
return AbstractResponse::makeResultSet($this->client, $response, $type, $key); | ||
} | ||
|
||
/** | ||
* Note: LastFM's pagination mechanism is very broken! Requesting a limit & page does | ||
* not reply with the expected result, thus the following is a client side fix to ensure the result set is | ||
* correct. | ||
* The problem is the limit is ignored, and the result includes previous pages! | ||
* If they ever fix this problem, this 'hack' should not effect the result set | ||
* | ||
* @param array $response | ||
* @param string $key | ||
* @return array | ||
*/ | ||
private function fixLastFmPaginationBug(array $response, $key): array | ||
{ | ||
$data = array_pull($response, $key); | ||
if (count($data) > $this->client->getOption('pagination.limit', 5)) { | ||
$data = array_slice($data, $this->client->getOption('pagination.limit', 5) * -1); | ||
} | ||
|
||
array_set( | ||
$response, | ||
$key, | ||
$data | ||
); | ||
|
||
return $response; | ||
} | ||
} |
Oops, something went wrong.