Skip to content

Commit

Permalink
Revered previous change to requested output detection, as this was in…
Browse files Browse the repository at this point in the history
…correct.
  • Loading branch information
jamielsharief committed Aug 30, 2020
1 parent 55b8c8c commit 49df74c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
24 changes: 8 additions & 16 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function initialize(string $url = null, array $options = []): void
* Detect the request type that it will be rendered in.
* @internal I think in future maybe this should not be here but in the controller
*/
$this->detectRequestedFormat();
$this->detectRequestedOutput();
}

/**
Expand Down Expand Up @@ -327,8 +327,8 @@ public function referer(): ?string
}

/**
* Sets and gets the request type (format) that will be rendered, if you want
* to know what was requested see contentType
* Sets and gets the request type (format) that will be rendered. If you want to know what
* the request body format is then use contentType
*
* @deprecated this will be renamed to renderType or something similar to prevent confusion
*
Expand All @@ -344,24 +344,16 @@ public function type(string $type = null)
}

/**
* Detects the how the request should be rendered
* Detects the requested output format
*
* 1. if the content-type header is set, e.g. Content-Type: application/json
* 2. if in the routing params an extension has been set
* 3. if the first available accept type is json or xml
* 4. if no matches are found just return HTML
* 1. If in the routing params an extension has been set
* 2. if the first available accept type is json or xml
* 3. if no matches are found just return HTML
*
* @return void
*/
protected function detectRequestedFormat(): void
protected function detectRequestedOutput(): void
{
$contentType = $this->contentType();
if ($contentType) {
$this->type($this->getType($contentType));

return;
}

$extension = $this->params('ext');
if ($extension && in_array($extension, ['html', 'json', 'xml'])) {
$this->type($extension);
Expand Down
9 changes: 0 additions & 9 deletions tests/TestCase/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,5 @@ public function testType()

$request = new MockRequest(null, ['server' => ['HTTP_ACCEPT' => 'application/xml']]);
$this->assertEquals('xml', $request->type());

$request = new MockRequest('/', ['server' => ['CONTENT_TYPE' => 'application/json']]);
$this->assertEquals('json', $request->type());

$request = new MockRequest('/', ['server' => ['CONTENT_TYPE' => 'application/xml']]);
$this->assertEquals('xml', $request->type());

$request = new MockRequest('/', ['server' => ['CONTENT_TYPE' => 'text/xml']]);
$this->assertEquals('xml', $request->type());
}
}

0 comments on commit 49df74c

Please sign in to comment.