8000 [Feature] Update view encoder to use new default API · tekord/laravel-json-api@d63fd8d · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

Commit d63fd8d

Browse files
committed
[Feature] Update view encoder to use new default API
1 parent 679274d commit d63fd8d

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

docs/features/views.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ For example:
2121
@jsonapi('v1', JSON_PRETTY_PRINT, 250)
2222
```
2323

24-
Note that if you do not call the `@jsonapi` directive in your templates, then the JSON API named `default` will be
25-
used.
24+
Note that if you do not call the `@jsonapi` directive in your templates, then the default API will be used.
2625

2726
### Encoding Data
2827

src/View/Renderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(JsonApiService $service)
7373
* @param int $options
7474
* @param int $depth
7575
*/
76-
public function with($apiName, $options = 0, $depth = 512)
76+
public function with($apiName = null, $options = 0, $depth = 512)
7777
{
7878
$this->encoder = $this->service->api($apiName)->encoder($options, $depth);
7979
}
@@ -87,7 +87,7 @@ public function with($apiName, $options = 0, $depth = 512)
8787
public function encode($data, $includePaths = null, $fieldSets = null)
8888
{
8989
if (!$this->encoder) {
90-
$this->with('default');
90+
$this->with();
9191
}
9292

9393
$params = null;

tests/lib/Unit/View/RendererTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function testCompileEncoderUsingOptions()
9191

9292
public function testEncodeWithDefaultApi()
9393
{
94-
$post = $this->withEncoder('default');
94+
$post = $this->withEncoder();
9595
$this->renderer->encode($post);
9696
}
9797

@@ -112,7 +112,7 @@ public function testEncodeWithOptions()
112112
public function testEncodeWithParameters()
113113
{
114114
$params = new EncodingParameters(['comments'], ['author' => ['name']]);
115-
$post = $this->withEncoder('default', 0, 512, $params);
115+
$post = $this->withEncoder(null, 0, 512, $params);
116116
$this->renderer->encode($post, 'comments', ['author' => ['name']]);
117117
}
118118

@@ -123,7 +123,7 @@ public function testEncodeWithParameters()
123123
* @param $parameters
124124
* @return object
125125
*/
126-
private function withEncoder($name, $options = 0, $depth = 512, $parameters = null)
126+
private function withEncoder($name = null, $options = 0, $depth = 512, $parameters = null)
127127
{
128128
$post = (object) ['type' => 'posts', 'id' => '1'];
129129

0 commit comments

Comments
 (0)
0