Improve args parsing to remove unnecessary defaults.
This commit is contained in:
@@ -21,20 +21,29 @@ class Publications {
|
||||
$this->issuu = $issuu;
|
||||
}
|
||||
|
||||
private static function parse_args(array $args, array $defaults):array {
|
||||
return array_filter(
|
||||
wp_parse_args($args, $defaults),
|
||||
function ($value, $key) use ($defaults) {
|
||||
return $value !== $defaults[$key];
|
||||
},
|
||||
ARRAY_FILTER_USE_BOTH
|
||||
);
|
||||
}
|
||||
|
||||
public function getPublicationAssetsBySlug(string $slug, array $args = []):stdClass {
|
||||
$args = wp_parse_args($args, [
|
||||
$args = self::parse_args($args, [
|
||||
'assetType' => '',
|
||||
'size' => 10,
|
||||
'page' => 1,
|
||||
'documentPageNumber' => 0.0,
|
||||
]);
|
||||
if (!$args['documentPageNumber']) unset($args['documentPageNumber']);
|
||||
|
||||
return $this->issuu->getResponse(method: 'GET', endpoint: "publications/{$slug}/assets", queryParameters: $args);
|
||||
}
|
||||
|
||||
public function getPublicationEmbedBySlug(string $slug, array $args = []):stdClass {
|
||||
$args = wp_parse_args($args, [
|
||||
$args = self::parse_args($args, [
|
||||
'responsive' => true,
|
||||
'width' => '100%',
|
||||
'height' => '100%',
|
||||
|
||||
Reference in New Issue
Block a user