mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Add getPagination* concrete functions on Pagination trait (#271)
This commit is contained in:
parent
47f816ac56
commit
b6d035c9a3
@ -10,6 +10,7 @@
|
|||||||
namespace Mailgun\Api;
|
namespace Mailgun\Api;
|
||||||
|
|
||||||
use Mailgun\Assert;
|
use Mailgun\Assert;
|
||||||
|
use Mailgun\Resource\Api\PagingProvider;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,13 +22,53 @@ trait Pagination
|
|||||||
|
|
||||||
abstract protected function safeDeserialize(ResponseInterface $response, $className);
|
abstract protected function safeDeserialize(ResponseInterface $response, $className);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PagingProvider $response
|
||||||
|
*
|
||||||
|
* @return PagingProvider|null
|
||||||
|
*/
|
||||||
|
public function nextPage(PagingProvider $response)
|
||||||
|
{
|
||||||
|
return $this->getPaginationUrl($response->getNextUrl(), get_class($response));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PagingProvider $response
|
||||||
|
*
|
||||||
|
* @return PagingProvider|null
|
||||||
|
*/
|
||||||
|
public function previousPage(PagingProvider $response)
|
||||||
|
{
|
||||||
|
return $this->getPaginationUrl($response->getPreviousUrl(), get_class($response));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PagingProvider $response
|
||||||
|
*
|
||||||
|
* @return PagingProvider|null
|
||||||
|
*/
|
||||||
|
public function firstPage(PagingProvider $response)
|
||||||
|
{
|
||||||
|
return $this->getPaginationUrl($response->getFirstUrl(), get_class($response));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PagingProvider $response
|
||||||
|
*
|
||||||
|
* @return PagingProvider|null
|
||||||
|
*/
|
||||||
|
public function lastPage(PagingProvider $response)
|
||||||
|
{
|
||||||
|
return $this->getPaginationUrl($response->getLastUrl(), get_class($response));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $class
|
* @param string $class
|
||||||
*
|
*
|
||||||
* @return mixed|null
|
* @return PagingProvider|null
|
||||||
*/
|
*/
|
||||||
public function getPaginationUrl($url, $class)
|
private function getPaginationUrl($url, $class)
|
||||||
{
|
{
|
||||||
Assert::stringNotEmpty($class);
|
Assert::stringNotEmpty($class);
|
||||||
|
|
||||||
|
@ -9,13 +9,14 @@
|
|||||||
|
|
||||||
namespace Mailgun\Resource\Api\Event;
|
namespace Mailgun\Resource\Api\Event;
|
||||||
|
|
||||||
|
use Mailgun\Resource\Api\PagingProvider;
|
||||||
use Mailgun\Resource\Api\PaginationResponse;
|
use Mailgun\Resource\Api\PaginationResponse;
|
||||||
use Mailgun\Resource\ApiResponse;
|
use Mailgun\Resource\ApiResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
||||||
*/
|
*/
|
||||||
class EventResponse implements ApiResponse
|
class EventResponse implements ApiResponse, PagingProvider
|
||||||
{
|
{
|
||||||
use PaginationResponse;
|
use PaginationResponse;
|
||||||
|
|
||||||
|
44
src/Mailgun/Resource/Api/PagingProvider.php
Normal file
44
src/Mailgun/Resource/Api/PagingProvider.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 Mailgun
|
||||||
|
*
|
||||||
|
* This software may be modified and distributed under the terms
|
||||||
|
* of the MIT license. See the LICENSE file for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mailgun\Resource\Api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sean Johnson <sean@mailgun.com>
|
||||||
|
*/
|
||||||
|
interface PagingProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns the `$paging->next` URL.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getNextUrl();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the `$paging->prev` URL.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPreviousUrl();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the `$paging->first` URL.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getFirstUrl();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the `$paging->last` URL.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLastUrl();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user