8000 [Feature-WIP] Add various fixes · volldigital/laravel-json-api@c707ea9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c707ea9

Browse files
committed
[Feature-WIP] Add various fixes
1 parent 890481d commit c707ea9

File tree

6 files changed

+56
-222
lines changed

6 files changed

+56
-222
lines changed

config/json-api-errors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
* and a 400 response status will be set.
147147
*/
148148
V::QUERY_PARAMETERS_MESSAGES => [
149-
Error::TITLE => 'Invalid Filter',
149+
Error::TITLE => 'Invalid Query Parameter',
150150
],
151151

152152
/**

config/json-api.php

Lines changed: 0 additions & 185 deletions
This file was deleted.

src/Pagination/StandardStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
use Neomerx\JsonApi\Contracts\Encoder\Parameters\SortParameterInterface;
3232
use Neomerx\JsonApi\Contracts\Http\Query\QueryParametersParserInterface;
3333

34-
class StandardStrategy
34+
class StandardStrategy implements PagingStrategyInterface
3535
{
3636

3737
/**

src/ServiceProvider.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public function boot(
8686
Router $router,
8787
ResponseFactoryContract $responses
8888
) {
89-
$this->bootPublishing();
9089
$this->bootMiddleware($router);
9190
$this->bootResponseMacro($responses);
9291
}
@@ -107,22 +106,7 @@ public function register()
107106
$this->bindLinkFactory();
108107
$this->bindPagination();
109108
$this->registerArtisanCommands();
110-
}
111-
112-
/**
113-
* Register the configuration that this package publishes.
114-
*
115-
* @return void
116-
*/
117-
protected function bootPublishing()
118-
{
119-
$this->publishes([
120-
__DIR__ . '/../config/json-api.php' => config_path('json-api.php'),
121-
], 'config');
122-
123-
$this->publishes([
124-
__DIR__ . '/../config/json-api-errors.php' => config_path('json-api-errors.php'),
125-
], 'errors');
109+
$this->mergePackageConfig();
126110
}
127111

128112
/**
@@ -263,6 +247,14 @@ protected function registerArtisanCommands()
263247
}
264248
}
265249

250+
/**
251+
* Merge default package config.
252+
*/
253+
protected function mergePackageConfig()
254+
{
255+
$this->mergeConfigFrom(__DIR__ . '/../config/json-api-errors.php', 'json-api-errors');
256+
}
257+
266258
/**
267259
* @param $key
268260
* @param $default

src/Validators/AbstractValidatorProvider.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
use CloudCreativity\JsonApi\Contracts\Validators\ResourceValidatorInterface;
2828
use CloudCreativity\JsonApi\Contracts\Validators\ValidatorProviderInterface;
2929
use CloudCreativity\JsonApi\Http\Query\ChecksQueryParameters;
30-
use CloudCreativity\JsonApi\Http\Query\ValidationQueryChecker;
3130
use CloudCreativity\JsonApi\Validators\QueryValidatorIterator;
3231
use CloudCreativity\LaravelJsonApi\Contracts\Validators\ValidatorFactoryInterface;
32+
use CloudCreativity\LaravelJsonApi\Http\Requests\RequestInterpreter;
3333
use Ill 67F4 uminate\Contracts\Validation\Validator;
3434

3535
/**
@@ -120,6 +120,11 @@ abstract class AbstractValidatorProvider implements ValidatorProviderInterface
120120
*/
121121
protected $allowedPagingParameters = null;
122122

123+
/**
124+
* @var RequestInterpreter
125+
*/
126+
protected $requestInterpreter;
127+
123128
/**
124129
* @var ApiInterface
125130
*/
@@ -166,24 +171,16 @@ abstract protected function relationshipRules(
166171
* AbstractValidatorProvider constructor.
167172
*
168173
* @param ApiInterface $api
174+
* @param RequestInterpreter $interpreter
169175
* @param FactoryInterface $factory
170176
*/
171-
public function __construct(ApiInterface $api, FactoryInterface $factory)
177+
public function __construct(ApiInterface $api, RequestInterpreter $interpreter, FactoryInterface $factory)
172178
{
173179
$this->api = $api;
180+
$this->requestInterpreter = $interpreter;
174181
$this->factory = $factory;
175182
}
176183

177-
/**
178-
* @inheritdoc
179-
*/
180-
public function resource($resourceType, $resourceId = null)
181-
{
182-
$resource = $this->validatorFactory()->resource($resourceType, $resourceId);
183-
184-
return $this->validatorFactory()->resourceDocument($resource);
185-
}
186-
187184
/**
188185
* @inheritdoc
189186
*/
@@ -357,14 +354,18 @@ protected function resourceContext($resourceType, $record = null)
357354

358355
/**
359356
* @param $resourceType
360-
* @return QueryValidatorInterface
357+
* @return QueryValidatorInterface|null
361358
*/
362359
protected function createQueryValidator($resourceType)
363360
{
364-
return new QueryValidatorIterator([
365-
$this->filterValidator($resourceType),
366-
$this->paginationValidator($resourceType)
367-
]);
361+
$validator = new QueryValidatorIterator();
362+
363+
if ($this->requestInterpreter->isIndex()) {
364+
$validator->add($this->filterValidator($resourceType));
365+
$validator->add($this->paginationValidator($resourceType));
366+
}
367+
368+
return $validator;
368369
}
369370

370371
/**

src/Validators/ValidatorFactory.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,33 @@ public function filterParams(
8787
/** @var ValidatorErrorFactoryInterface $validationErrors */
8888
$validationErrors = $this->validationErrors;
8989

90-
return new AbstractQueryValidator(
90+
return new FilterValidator(
91+
$this->validatorFactory,
92+
$validationErrors,
93+
$rules,
94+
$messages,
95+
$customAttributes,
96+
$callback
97+
);
98+
}
99+
100+
/**
101+
* @param array $rules
102+
* @param array $messages
103+
* @param array $customAttributes
104+
* @param callable|null $callback
105+
* @return PaginationValidator
106+
*/
107+
public function paginationParams(
108+
array $rules,
109+
array $messages = [],
110+
array $customAttributes = [],
111+
callable $callback = null
112+
) {
113+
/** @var ValidatorErrorFactoryInterface $validationErrors */
114+
$validationErrors = $this->validationErrors;
115+
116+
return new PaginationValidator(
91117
$this->validatorFactory,
92118
$validationErrors,
93119
$rules,

0 commit comments

Comments
 (0)
0