8000 [Cleanup] Remove deprecated Eloquent features · jpaniorte/laravel-json-api@69ee08d · GitHub
[go: up one dir, main page]

Skip to content

Commit 69ee08d

Browse files
committed
[Cleanup] Remove deprecated Eloquent features
This removes features that were marked for deprecation in 1.0. Refer to the changelog for a complete list.
1 parent ad00072 commit 69ee08d

File tree

12 files changed

+80
-215
lines changed

12 files changed

+80
-215
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
All notable changes to this project will be documented in this file. This project adheres to
33
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
44

5+
## Unreleased
6+
7+
### Removed
8+
- The deprecated `EloquentController` was removed - extend `JsonApiController` directly.
9+
- The `Store\EloquentAdapter` was removed - extend `Eloquent\AbstractAdapter` directly.
10+
- The following previously deprecated methods/properties were removed from the `EloquentAdapter`:
11+
- public method `queryRelation()`: renamed `queryToMany()`.
12+
- protected property `$with`: renamed `$defaultWith`.
13+
- protected method `keyForAttribute()`: renamed `modelKeyForField()`.
14+
- protected method `columnForField()`: renamed `getSortColumn()`.
15+
- protected method `all()`: renamed `searchAll()`.
16+
- protected method `extractIncludePaths()`: overload the `getQueryParameters()` method instead.
17+
- protected method `extractFilters()`: overload the `getQueryParameters()` method instead.
18+
- protected method `extractPagination()`: overload the `getQueryParameters()` method instead.
19+
- The previously deprecated `Eloquent\Concerns\AbstractRelation` class was removed.
20+
Extend `Adapter\AbstractRelationshipAdapter` and use the `Eloquent\Concerns\QueriesRelations` trait.
21+
522
## [1.0.0-beta.6] - 2019-01-03
623

724
### Added

docs/upgrade.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ return [
100100

101101
### Controllers
102102

103+
#### Eloquent
104+
105+
The `Http\Controllers\EloquentController` class has been removed. This has been deprecated for
106+
some time, and had no code in it. You can extend `Http\Controllers\JsonApiController` directly.
107+
103108
#### Searching Hook
104109

105110
As before the `searching` hook now occurs *before* records are queried with the resource's adapter.
@@ -129,6 +134,16 @@ We have changed the type-hinting of some protected methods so that they now type
129134
instance of `ValidatedRequest`. This will only affect your application if you have overloaded any
130135
of the protected methods.
131136

137+
### Adapters
138+
139+
If any of your adapters were extending `Store\EloquentAdapter`, you now need to extend
140+
`Eloquent\AbstractAdapter` instead.
141+
142+
We have removed deprecated properties and methods from the Eloquent adapter. A lot of these have
143+
been deprecated for some time, so are unlikely to affect your application unless you have Eloquent
144+
adapters that have not been changed for some time. If in doubt, check the changelog that lists
145+
the removals.
146+
132147
## 1.0.0-beta.5 to 1.0.0-beta.6
133148

134149
### Adapters

src/Eloquent/AbstractAdapter.php

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ abstract class AbstractAdapter extends AbstractResourceAdapter
8787
*/
8888
protected $defaultPagination = null;
8989

90-
/**
91-
* The model relationships to eager load on every query.
92-
*
93-
* @var string[]|null
94-
* @deprecated 1.0.0 use `$defaultWith` instead.
95-
*/
96-
protected $with = null;
97-
9890
/**
9991
* Apply the supplied filters to the builder instance.
10092
*
@@ -114,10 +106,6 @@ public function __construct(Model $model, PagingStrategyInterface $paging = null
114106
{
115107
$this->model = $model;
116108
$this->paging = $paging;
117-
118-
if ($this->with) {
119-
$this->defaultWith = array_merge($this->defaultWith, $this->with);
120-
}
121109
}
122110

123111
/**
@@ -167,17 +155,6 @@ public function queryToOne($relation, EncodingParametersInterface $parameters)
167155
);
168156
}
169157

170-
/**
171-
* @param $relation
172-
* @param EncodingParametersInterface $parameters
173-
* @return mixed
174-
* @deprecated 1.0.0 use `queryToMany` directly.
175-
*/
176-
public function queryRelation($relation, EncodingParametersInterface $parameters)
177-
{
178-
return $this->queryToMany($relation, $parameters);
179-
}
180-
181158
/**
182159
* @inheritDoc
183160
*/
@@ -419,18 +396,6 @@ protected function searchOne($query)
419396
return $query->first();
420397
}
421398

422-
/**
423-
* Return the result for query that is not paginated.
424-
*
425-
* @param Builder $query
426-
* @return mixed
427-
* @deprecated 1.0.0 use `searchAll`, renamed to avoid collisions with relation names.
428-
*/
429-
protected function all($query)
430-
{
431-
return $this->searchAll($query);
432-
}
433-
434399
/**
435400
* Return the result for query that is not paginated.
436401
*
@@ -492,41 +457,6 @@ protected function getQualifiedKeyName()
492457
return $this->model->qualifyColumn($this->getKeyName());
493458
}
494459

495-
/**
496-
* @param EncodingParametersInterface $parameters
497-
* @return Collection
498-
* @deprecated 1.0.0
499-
* overload the `getQueryParameters` method as needed.
500-
*/
501-
protected function extractIncludePaths(EncodingParametersInterface $parameters)
502-
{
503-
return collect($parameters->getIncludePaths());
504-
}
505-
506-
/**
507-
* @param EncodingParametersInterface $parameters
508-
* @return Collection
509-
* @deprecated 1.0.0
510-
* overload the `getQueryParameters` method as needed.
511-
*/
512-
protected function extractFilters(EncodingParametersInterface $parameters)
513-
{
514-
return collect($parameters->getFilteringParameters());
515-
}
516-
517-
/**
518-
* @param EncodingParametersInterface $parameters
519-
* @return Collection
520-
* @deprecated 1.0.0
521-
* overload the `getQueryParameters` method as needed.
522-
*/
523-
protected function extractPagination(EncodingParametersInterface $parameters)
524-
{
525-
$pagination = (array) $parameters->getPaginationParameters();
526-
527-
return collect($pagination ?: $this->defaultPagination());
528-
}
529-
530460
/**
531461
* Get pagination parameters to use when the client has not provided paging parameters.
532462
*
@@ -639,7 +569,7 @@ protected function queryAll($query, EncodingParametersInterface $parameters)
639569
$pagination = collect($parameters->getPaginationParameters());
640570

641571
return $pagination->isEmpty() ?
642-
$this->all($query) :
572+
$this->searchAll($query) :
643573
$this->paginate($query, $parameters);
644574
}
645575

@@ -676,11 +606,11 @@ protected function queryOne($query, EncodingParametersInterface $parameters)
676606
protected function getQueryParameters(EncodingParametersInterface $parameters)
677607
{
678608
return new EncodingParameters(
679-
$this->extractIncludePaths($parameters)->all(),
609+
$parameters->getIncludePaths(),
680610
$parameters->getFieldSets(),
681611
$parameters->getSortParameters() ?: $this->defaultSort(),
682-
$this->extractPagination($parameters)->all(),
683-
$this->extractFilters($parameters)->all(),
612+
$parameters->getPaginationParameters() ?: $this->defaultPagination(),
613+
$parameters->getFilteringParameters(),
684614
$parameters->getUnrecognizedParameters()
685615
);
686616
}

src/Eloquent/AbstractManyRelation.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace CloudCreativity\LaravelJsonApi\Eloquent;
1919

20+
use CloudCreativity\LaravelJsonApi\Adapter\AbstractRelationshipAdapter;
2021
use CloudCreativity\LaravelJsonApi\Contracts\Adapter\HasManyAdapterInterface;
2122
use Illuminate\Database\Eloquent\Model;
2223
use Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
@@ -26,9 +27,26 @@
2627
*
2728
* @package CloudCreativity\LaravelJsonApi
2829
*/
29-
abstract class AbstractManyRelation extends AbstractRelation implements HasManyAdapterInterface
B41A 30+
abstract class AbstractManyRelation extends AbstractRelationshipAdapter implements HasManyAdapterInterface
3031
{
3132

33+
use Concerns\QueriesRelations;
34+
35+
/**
36+
* @var string
37+
*/
38+
protected $key;
39+
40+
/**
41+
* AbstractManyRelation constructor.
42+
*
43+
* @param string $key
44+
*/
45+
public function __construct($key)
46+
{
47+
$this->key = $key;
48+
}
49+
3250
/**
3351
* @param Model $record
3452
* @param EncodingParametersInterface $parameters

src/Eloquent/AbstractRelation.php

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

src/Eloquent/BelongsTo.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace CloudCreativity\LaravelJsonApi\Eloquent;
1919

20+
use CloudCreativity\LaravelJsonApi\Adapter\AbstractRelationshipAdapter;
2021
use Illuminate\Database\Eloquent\Model;
2122
use Illuminate\Database\Eloquent\Relations;
2223
use Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface;
@@ -26,9 +27,26 @@
2627
*
2728
* @package CloudCreativity\LaravelJsonApi
2829
*/
29-
class BelongsTo extends AbstractRelation
30+
class BelongsTo extends AbstractRelationshipAdapter
3031
{
3132

33+
use Concerns\QueriesRelations;
34+
35+
/**
36+
* @var string
37+
*/
38+
protected $key;
39+
40+
/**
41+
* BelongsTo constructor.
42+
*
43+
* @param string $key
44+
*/
45+
public function __construct($key)
46+
{
47+
$this->key = $key;
48+
}
49+
3250
/**
3351
* @param Model $record
3452
* @param EncodingParametersInterface $parameters

src/Eloquent/Concerns/DeserializesAttributes.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,6 @@ protected function modelKeyForField($field, $model)
9494
return $this->attributes[$field] = $key;
9595
}
9696

97-
/**
98-
* Convert a JSON API attribute key into a model attribute key.
99-
*
100-
* @param $resourceKey
101-
* @param Model $model
102-
* @return string
103-
* @deprecated 1.0.0 use `modelKeyForField`
104-
*/
105-
protected function keyForAttribute($resourceKey, Model $model)
106-
{
107-
return $this->modelKeyForField($resourceKey, $model);
108-
}
109-
11097
/**
11198
* Deserialize fillable attributes.
11299
*
@@ -119,7 +106,7 @@ protected function deserializeAttributes($attributes, $record)
119106
return collect($attributes)->reject(function ($v, $field) use ($record) {
120107
return $this->isNotFillable($field, $record);
121108
})->mapWithKeys(function ($value, $field) use ($record) {
122-
$key = $this->keyForAttribute($field, $record);
109+
$key = $this->modelKeyForField($field, $record);
123110

124111
return [$key => $this->deserializeAttribute($value, $field, $record)];
125112
})->all();

src/Eloquent/Concerns/SortsModels.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected function sortBy($query, SortParameterInterface $param)
117117
*/
118118
protected function getQualifiedSortColumn($query, $field)
119119
{
120-
$key = $this->columnForField($field, $query->getModel());
120+
$key = $this->getSortColumn($field, $query->getModel());
121121

122122
return $query->qualifyColumn($key);
123123
}
@@ -139,16 +139,4 @@ protected function getSortColumn($field, Model $model)
139139
return $model::$snakeAttributes ? Str::underscore($field) : Str::camelize($field);
140140
}
141141

142-
/**
143-
* Get the table column to use for the specified search field.
144-
*
145-
* @param string $field
146-
* @param Model $model
147-
* @return string
148-
* @deprecated 1.0.0 use `getSortColumn`
149-
*/
150-
protected function columnForField($field, Model $model)
151-
{
152-
return $this->getSortColumn($field, $model);
153-
}
154142
}

src/Http/Controllers/EloquentController.php

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

0 commit comments

Comments
 (0)
0