From a9644d9f19cac99555cdf5709a7174c64a4110c5 Mon Sep 17 00:00:00 2001 From: Bradley Weston Date: Tue, 13 May 2014 08:52:21 +0100 Subject: [PATCH 1/6] Added @throws in doc comments. --- src/Routing/Router.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Routing/Router.php b/src/Routing/Router.php index fd7515779..888506d42 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -97,6 +97,7 @@ class Router extends IlluminateRouter { * @param array $options * @param callable $callback * @return void + * @throws \BadMethodCallException when api version not specified. */ public function api($options, callable $callback) { @@ -136,6 +137,7 @@ public function api($options, callable $callback) * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response|\Dingo\Api\Http\Response + * @throws \HttpExceptionInterface */ public function dispatch(Request $request) { From bfed9daef8b7e3861c521b15e4820faa0db99ac1 Mon Sep 17 00:00:00 2001 From: Bradley Weston Date: Tue, 13 May 2014 08:53:53 +0100 Subject: [PATCH 2/6] Updated doc for @throws on authenticate method --- src/Auth/BasicProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Auth/BasicProvider.php b/src/Auth/BasicProvider.php index af727b136..364bd92f5 100644 --- a/src/Auth/BasicProvider.php +++ b/src/Auth/BasicProvider.php @@ -39,6 +39,7 @@ public function __construct(AuthManager $auth, $identifier = 'email') * @param \Illuminate\Http\Request $request * @param \Illuminate\Routing\Route $route * @return int + * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException */ public function authenticate(Request $request, Route $route) { From 87632a484c339a9915f821a3941fd1eccece7693 Mon Sep 17 00:00:00 2001 From: Bradley Weston Date: Tue, 13 May 2014 08:55:39 +0100 Subject: [PATCH 3/6] Added @throws in doc comments. --- src/Auth/DingoOAuth2Provider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Auth/DingoOAuth2Provider.php b/src/Auth/DingoOAuth2Provider.php index b1324043c..87e467f40 100644 --- a/src/Auth/DingoOAuth2Provider.php +++ b/src/Auth/DingoOAuth2Provider.php @@ -33,6 +33,8 @@ public function __construct(Resource $resource) * @param \Illuminate\Http\Request $request * @param \Illuminate\Routing\Route $route * @return int + * @throws \Exception when header authorization fails. + * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException when invalid token exception is called inside token validator. */ public function authenticate(Request $request, Route $route) { From 108fa670b2a80cd5a20833ae93047758445e47e9 Mon Sep 17 00:00:00 2001 From: Bradley Weston Date: Tue, 13 May 2014 08:56:59 +0100 Subject: [PATCH 4/6] Added @throws in doc comments. --- src/Auth/LeagueOAuth2Provider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Auth/LeagueOAuth2Provider.php b/src/Auth/LeagueOAuth2Provider.php index ed6783d3b..95f26370a 100644 --- a/src/Auth/LeagueOAuth2Provider.php +++ b/src/Auth/LeagueOAuth2Provider.php @@ -42,6 +42,8 @@ public function __construct(Resource $resource, $httpHeadersOnly = false) * @param \Illuminate\Http\Request $request * @param \Illuminate\Routing\Route $route * @return int + * @throws \Exception + * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException */ public function authenticate(Request $request, Route $route) { From e7dbdde8750ecbe2531165f9fd036e55cf38a803 Mon Sep 17 00:00:00 2001 From: Bradley Weston Date: Tue, 13 May 2014 08:57:45 +0100 Subject: [PATCH 5/6] Added @throws in doc comments. --- src/Auth/Shield.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Auth/Shield.php b/src/Auth/Shield.php index b305c1127..84fd150c2 100644 --- a/src/Auth/Shield.php +++ b/src/Auth/Shield.php @@ -74,6 +74,7 @@ public function __construct(AuthManager $auth, Container $container, array $prov * Authenticate the current request. * * @return null|\Dingo\Api\Http\Response + * @throws \Exception */ public function authenticate(Request $request, Route $route) { From 4b280c464a535c3e5d35576303d4d738d0c47d46 Mon Sep 17 00:00:00 2001 From: Bradley Weston Date: Fri, 23 May 2014 11:23:41 +0100 Subject: [PATCH 6/6] Proposal for our own paginator for query string. Currently the Fractal Illuminate adapter fails to take the query string parameters required. The idea I am using is that rather then creating a new instance of the paginator just using the one that is already provided. The wrapper just makes it bind to the contract of PaginatorInterface. This currently breaks tests as I have been going round and round trying to fix it, sorry for this. --- src/Pagination/IlluminatePaginatorWrapper.php | 85 +++++++++++++++++++ src/Transformer/FractalTransformer.php | 4 +- 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/Pagination/IlluminatePaginatorWrapper.php diff --git a/src/Pagination/IlluminatePaginatorWrapper.php b/src/Pagination/IlluminatePaginatorWrapper.php new file mode 100644 index 000000000..befa15ac1 --- /dev/null +++ b/src/Pagination/IlluminatePaginatorWrapper.php @@ -0,0 +1,85 @@ +paginator = $paginator; + } + + /** + * {@inheritDoc} + */ + public function getCurrentPage() + { + return $this->paginator->getCurrentPage(); + } + + /** + * {@inheritDoc} + */ + public function getLastPage() + { + return $this->paginator->getLastPage(); + } + + /** + * {@inheritDoc} + */ + public function getTotal() + { + return $this->paginator->getTotal(); + } + + /** + * {@inheritDoc} + */ + public function count() + { + return $this->paginator->count(); + } + + /** + * {@inheritDoc} + */ + public function getPerPage() + { + return $this->paginator->getPerPage(); + } + + /** + * {@inheritDoc} + */ + public function getUrl($page) + { + return $this->paginator->getUrl($page); + } + + /** + * @param string $method + * @param array $args + * @throws \BadMethodCallException + */ + public function __call($method, $args) + { + if (! method_exists($this->paginator, $method)) + { + throw new \BadMethodCallException("Unable to find method {$method} on paginator instance."); + } + + return call_user_func_array([$this->paginator, $method], $args); + } + +} diff --git a/src/Transformer/FractalTransformer.php b/src/Transformer/FractalTransformer.php index 0469f020b..b365b6e36 100644 --- a/src/Transformer/FractalTransformer.php +++ b/src/Transformer/FractalTransformer.php @@ -2,7 +2,7 @@ use League\Fractal\Manager as Fractal; use League\Fractal\Resource\Item as FractalItem; -use League\Fractal\Pagination\IlluminatePaginatorAdapter; +use Dingo\Api\Pagination\IlluminatePaginatorWrapper; use Illuminate\Support\Collection as IlluminateCollection; use Illuminate\Pagination\Paginator as IlluminatePaginator; use League\Fractal\Resource\Collection as FractalCollection; @@ -63,7 +63,7 @@ public function transformResponse($response, $transformer) // collection resource. if ($response instanceof IlluminatePaginator) { - $paginator = new IlluminatePaginatorAdapter($response); + $paginator = new IlluminatePaginatorWrapper($response); $resource->setPaginator($paginator); }