Add an async handler update
This commit is contained in:
parent
f5e599c75d
commit
9dc3d9bdf2
88
app/composer.lock
generated
88
app/composer.lock
generated
@ -127,16 +127,16 @@
|
||||
},
|
||||
{
|
||||
"name": "cakephp/core",
|
||||
"version": "5.2.1",
|
||||
"version": "5.2.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cakephp/core.git",
|
||||
"reference": "ba182a1410f1b06e8d1ab4d874b6f9797fbee165"
|
||||
"reference": "a0a92ee7fbb7b7555dbf4ea7ff3fd4e779693da6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/cakephp/core/zipball/ba182a1410f1b06e8d1ab4d874b6f9797fbee165",
|
||||
"reference": "ba182a1410f1b06e8d1ab4d874b6f9797fbee165",
|
||||
"url": "https://api.github.com/repos/cakephp/core/zipball/a0a92ee7fbb7b7555dbf4ea7ff3fd4e779693da6",
|
||||
"reference": "a0a92ee7fbb7b7555dbf4ea7ff3fd4e779693da6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -190,20 +190,20 @@
|
||||
"issues": "https://github.com/cakephp/cakephp/issues",
|
||||
"source": "https://github.com/cakephp/core"
|
||||
},
|
||||
"time": "2025-04-02T12:02:03+00:00"
|
||||
"time": "2025-04-19T12:34:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "cakephp/database",
|
||||
"version": "5.2.1",
|
||||
"version": "5.2.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cakephp/database.git",
|
||||
"reference": "f356a3fc78ff1c746d78786806f67ef22505cd76"
|
||||
"reference": "8aa2df292e8b0e0c27e50bd6ed808fbf32f9c25a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/cakephp/database/zipball/f356a3fc78ff1c746d78786806f67ef22505cd76",
|
||||
"reference": "f356a3fc78ff1c746d78786806f67ef22505cd76",
|
||||
"url": "https://api.github.com/repos/cakephp/database/zipball/8aa2df292e8b0e0c27e50bd6ed808fbf32f9c25a",
|
||||
"reference": "8aa2df292e8b0e0c27e50bd6ed808fbf32f9c25a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -257,20 +257,20 @@
|
||||
"issues": "https://github.com/cakephp/cakephp/issues",
|
||||
"source": "https://github.com/cakephp/database"
|
||||
},
|
||||
"time": "2025-04-05T04:18:59+00:00"
|
||||
"time": "2025-04-22T19:16:58+00:00"
|
||||
},
|
||||
{
|
||||
"name": "cakephp/datasource",
|
||||
"version": "5.2.1",
|
||||
"version": "5.2.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cakephp/datasource.git",
|
||||
"reference": "2b4f33fcc8c5d13261b851e8299c9fa85ff11b6e"
|
||||
"reference": "a1e9d639d1e6ae28b32c57966373250c8b9f6d8b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/cakephp/datasource/zipball/2b4f33fcc8c5d13261b851e8299c9fa85ff11b6e",
|
||||
"reference": "2b4f33fcc8c5d13261b851e8299c9fa85ff11b6e",
|
||||
"url": "https://api.github.com/repos/cakephp/datasource/zipball/a1e9d639d1e6ae28b32c57966373250c8b9f6d8b",
|
||||
"reference": "a1e9d639d1e6ae28b32c57966373250c8b9f6d8b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -324,20 +324,20 @@
|
||||
"issues": "https://github.com/cakephp/cakephp/issues",
|
||||
"source": "https://github.com/cakephp/datasource"
|
||||
},
|
||||
"time": "2025-04-05T02:12:27+00:00"
|
||||
"time": "2025-04-18T03:47:06+00:00"
|
||||
},
|
||||
{
|
||||
"name": "cakephp/utility",
|
||||
"version": "5.2.1",
|
||||
"version": "5.2.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cakephp/utility.git",
|
||||
"reference": "8b97361c71d30a9f1df2c8e98469d20af78d6ed6"
|
||||
"reference": "76dcd5c20e46aaf5bfdf9ad51e9f5313abffe104"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/cakephp/utility/zipball/8b97361c71d30a9f1df2c8e98469d20af78d6ed6",
|
||||
"reference": "8b97361c71d30a9f1df2c8e98469d20af78d6ed6",
|
||||
"url": "https://api.github.com/repos/cakephp/utility/zipball/76dcd5c20e46aaf5bfdf9ad51e9f5313abffe104",
|
||||
"reference": "76dcd5c20e46aaf5bfdf9ad51e9f5313abffe104",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -388,7 +388,7 @@
|
||||
"issues": "https://github.com/cakephp/cakephp/issues",
|
||||
"source": "https://github.com/cakephp/utility"
|
||||
},
|
||||
"time": "2025-04-05T02:12:27+00:00"
|
||||
"time": "2025-04-19T12:34:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dflydev/dot-access-data",
|
||||
@ -1504,16 +1504,16 @@
|
||||
},
|
||||
{
|
||||
"name": "php-di/php-di",
|
||||
"version": "7.0.9",
|
||||
"version": "7.0.10",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/PHP-DI/PHP-DI.git",
|
||||
"reference": "d8480267f5cf239650debba704f3ecd15b638cde"
|
||||
"reference": "0d1ed64126577e9a095b3204dcaee58cf76432c2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/d8480267f5cf239650debba704f3ecd15b638cde",
|
||||
"reference": "d8480267f5cf239650debba704f3ecd15b638cde",
|
||||
"url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/0d1ed64126577e9a095b3204dcaee58cf76432c2",
|
||||
"reference": "0d1ed64126577e9a095b3204dcaee58cf76432c2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -1529,7 +1529,7 @@
|
||||
"friendsofphp/php-cs-fixer": "^3",
|
||||
"friendsofphp/proxy-manager-lts": "^1",
|
||||
"mnapoli/phpunit-easymock": "^1.3",
|
||||
"phpunit/phpunit": "^9.6",
|
||||
"phpunit/phpunit": "^9.6 || ^10 || ^11",
|
||||
"vimeo/psalm": "^5|^6"
|
||||
},
|
||||
"suggest": {
|
||||
@ -1561,7 +1561,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/PHP-DI/PHP-DI/issues",
|
||||
"source": "https://github.com/PHP-DI/PHP-DI/tree/7.0.9"
|
||||
"source": "https://github.com/PHP-DI/PHP-DI/tree/7.0.10"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@ -1573,7 +1573,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-02-28T12:46:35+00:00"
|
||||
"time": "2025-04-22T08:53:15+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoption/phpoption",
|
||||
@ -2829,16 +2829,16 @@
|
||||
},
|
||||
{
|
||||
"name": "robmorgan/phinx",
|
||||
"version": "0.16.6",
|
||||
"version": "0.16.7",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cakephp/phinx.git",
|
||||
"reference": "5bad10934336e8cf45d50d529cabfcbe7fe287c5"
|
||||
"reference": "edd61785fe6b57a5992afafcc8cfdf5ea612d50d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/cakephp/phinx/zipball/5bad10934336e8cf45d50d529cabfcbe7fe287c5",
|
||||
"reference": "5bad10934336e8cf45d50d529cabfcbe7fe287c5",
|
||||
"url": "https://api.github.com/repos/cakephp/phinx/zipball/edd61785fe6b57a5992afafcc8cfdf5ea612d50d",
|
||||
"reference": "edd61785fe6b57a5992afafcc8cfdf5ea612d50d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -2850,8 +2850,8 @@
|
||||
"symfony/console": "^6.0|^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"cakephp/cakephp": "^5.0.2",
|
||||
"cakephp/cakephp-codesniffer": "^5.0",
|
||||
"cakephp/i18n": "^5.0",
|
||||
"ext-json": "*",
|
||||
"ext-pdo": "*",
|
||||
"phpunit/phpunit": "^9.5.19",
|
||||
@ -2910,9 +2910,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/cakephp/phinx/issues",
|
||||
"source": "https://github.com/cakephp/phinx/tree/0.16.6"
|
||||
"source": "https://github.com/cakephp/phinx/tree/0.16.7"
|
||||
},
|
||||
"time": "2024-12-20T23:02:54+00:00"
|
||||
"time": "2025-04-17T17:32:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "slim/flash",
|
||||
@ -5365,16 +5365,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpunit/phpunit",
|
||||
"version": "11.5.17",
|
||||
"version": "11.5.18",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||
"reference": "fd2e863a2995cdfd864fb514b5e0b28b09895b5c"
|
||||
"reference": "fc3e887c7f3f9917e1bf61e523413d753db00a17"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fd2e863a2995cdfd864fb514b5e0b28b09895b5c",
|
||||
"reference": "fd2e863a2995cdfd864fb514b5e0b28b09895b5c",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fc3e887c7f3f9917e1bf61e523413d753db00a17",
|
||||
"reference": "fc3e887c7f3f9917e1bf61e523413d753db00a17",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@ -5446,7 +5446,7 @@
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
||||
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.17"
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.18"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@ -5457,12 +5457,20 @@
|
||||
"url": "https://github.com/sebastianbergmann",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://liberapay.com/sebastianbergmann",
|
||||
"type": "liberapay"
|
||||
},
|
||||
{
|
||||
"url": "https://thanks.dev/u/gh/sebastianbergmann",
|
||||
"type": "thanks_dev"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-04-08T07:59:11+00:00"
|
||||
"time": "2025-04-22T06:09:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/cli-parser",
|
||||
|
@ -29,7 +29,6 @@ use Psr\Log\LoggerInterface;
|
||||
use Slim\App;
|
||||
use Slim\Factory\AppFactory;
|
||||
use Slim\Psr7\Factory\ResponseFactory;
|
||||
use Slovocast\Configuration\FileSystemSchema;
|
||||
use Slovocast\Middleware\SessionMiddleware;
|
||||
use Twig\Error\LoaderError;
|
||||
|
||||
|
@ -12,16 +12,12 @@ abstract class AsyncHandler extends Handler
|
||||
*/
|
||||
public function prepareResponse(array $data, string $template = ""): ResponseInterface
|
||||
{
|
||||
$acceptsHeader = $this->request->getHeader('Accept');
|
||||
$acceptsHeaders = $this->request->getHeader('Accept');
|
||||
|
||||
switch ($acceptsHeader) {
|
||||
case 'text/html':
|
||||
if (in_array('text/html', $acceptsHeaders)) {
|
||||
return $this->renderInline($template, $data);
|
||||
break;
|
||||
case 'application/json':
|
||||
default:
|
||||
}
|
||||
|
||||
return $this->json($data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
34
app/tests/Handler/AsyncHandlerTest.php
Normal file
34
app/tests/Handler/AsyncHandlerTest.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Slovocast\Tests\Controller;
|
||||
|
||||
use Slovocast\Tests\TestCase;
|
||||
use Slovocast\Handler\AsyncHandler;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
|
||||
class AsyncHandlerTest extends TestCase
|
||||
{
|
||||
public function testHtmlAcceptHeader(): void
|
||||
{
|
||||
$asyncHtmlHandler = new class extends AsyncHandler {
|
||||
public function handle(): Response
|
||||
{
|
||||
$template = "<ul>
|
||||
{% for item in list %}
|
||||
<li>{{ item }}</li>
|
||||
{% endfor %}
|
||||
</ul>";
|
||||
|
||||
return $this->prepareResponse([ 'list' => [ 1, 2, 3 ]], $template);
|
||||
}
|
||||
};
|
||||
|
||||
$app = $this->getAppInstance();
|
||||
$app->get('/test', $asyncHtmlHandler);
|
||||
|
||||
$request = $this->createRequest('GET', '/test', [ 'Accept' => 'text/html' ]);
|
||||
$response = $app->handle($request);
|
||||
|
||||
$this->assertStringContainsString('<li>1</li>', $response->getBody());
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ use Slovocast\Handler\Handler;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Odan\Session\SessionInterface;
|
||||
|
||||
class HandlerTest extends TestCase
|
||||
final class HandlerTest extends TestCase
|
||||
{
|
||||
public function testHtmlInlineResponse(): void
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user