Add an async handler update

This commit is contained in:
Dave Smith-Hayes 2025-04-29 02:51:55 +00:00
parent f5e599c75d
commit 9dc3d9bdf2
5 changed files with 87 additions and 50 deletions

88
app/composer.lock generated
View File

@ -127,16 +127,16 @@
}, },
{ {
"name": "cakephp/core", "name": "cakephp/core",
"version": "5.2.1", "version": "5.2.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/cakephp/core.git", "url": "https://github.com/cakephp/core.git",
"reference": "ba182a1410f1b06e8d1ab4d874b6f9797fbee165" "reference": "a0a92ee7fbb7b7555dbf4ea7ff3fd4e779693da6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/cakephp/core/zipball/ba182a1410f1b06e8d1ab4d874b6f9797fbee165", "url": "https://api.github.com/repos/cakephp/core/zipball/a0a92ee7fbb7b7555dbf4ea7ff3fd4e779693da6",
"reference": "ba182a1410f1b06e8d1ab4d874b6f9797fbee165", "reference": "a0a92ee7fbb7b7555dbf4ea7ff3fd4e779693da6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -190,20 +190,20 @@
"issues": "https://github.com/cakephp/cakephp/issues", "issues": "https://github.com/cakephp/cakephp/issues",
"source": "https://github.com/cakephp/core" "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", "name": "cakephp/database",
"version": "5.2.1", "version": "5.2.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/cakephp/database.git", "url": "https://github.com/cakephp/database.git",
"reference": "f356a3fc78ff1c746d78786806f67ef22505cd76" "reference": "8aa2df292e8b0e0c27e50bd6ed808fbf32f9c25a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/cakephp/database/zipball/f356a3fc78ff1c746d78786806f67ef22505cd76", "url": "https://api.github.com/repos/cakephp/database/zipball/8aa2df292e8b0e0c27e50bd6ed808fbf32f9c25a",
"reference": "f356a3fc78ff1c746d78786806f67ef22505cd76", "reference": "8aa2df292e8b0e0c27e50bd6ed808fbf32f9c25a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -257,20 +257,20 @@
"issues": "https://github.com/cakephp/cakephp/issues", "issues": "https://github.com/cakephp/cakephp/issues",
"source": "https://github.com/cakephp/database" "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", "name": "cakephp/datasource",
"version": "5.2.1", "version": "5.2.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/cakephp/datasource.git", "url": "https://github.com/cakephp/datasource.git",
"reference": "2b4f33fcc8c5d13261b851e8299c9fa85ff11b6e" "reference": "a1e9d639d1e6ae28b32c57966373250c8b9f6d8b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/cakephp/datasource/zipball/2b4f33fcc8c5d13261b851e8299c9fa85ff11b6e", "url": "https://api.github.com/repos/cakephp/datasource/zipball/a1e9d639d1e6ae28b32c57966373250c8b9f6d8b",
"reference": "2b4f33fcc8c5d13261b851e8299c9fa85ff11b6e", "reference": "a1e9d639d1e6ae28b32c57966373250c8b9f6d8b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -324,20 +324,20 @@
"issues": "https://github.com/cakephp/cakephp/issues", "issues": "https://github.com/cakephp/cakephp/issues",
"source": "https://github.com/cakephp/datasource" "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", "name": "cakephp/utility",
"version": "5.2.1", "version": "5.2.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/cakephp/utility.git", "url": "https://github.com/cakephp/utility.git",
"reference": "8b97361c71d30a9f1df2c8e98469d20af78d6ed6" "reference": "76dcd5c20e46aaf5bfdf9ad51e9f5313abffe104"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/cakephp/utility/zipball/8b97361c71d30a9f1df2c8e98469d20af78d6ed6", "url": "https://api.github.com/repos/cakephp/utility/zipball/76dcd5c20e46aaf5bfdf9ad51e9f5313abffe104",
"reference": "8b97361c71d30a9f1df2c8e98469d20af78d6ed6", "reference": "76dcd5c20e46aaf5bfdf9ad51e9f5313abffe104",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -388,7 +388,7 @@
"issues": "https://github.com/cakephp/cakephp/issues", "issues": "https://github.com/cakephp/cakephp/issues",
"source": "https://github.com/cakephp/utility" "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", "name": "dflydev/dot-access-data",
@ -1504,16 +1504,16 @@
}, },
{ {
"name": "php-di/php-di", "name": "php-di/php-di",
"version": "7.0.9", "version": "7.0.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/PHP-DI/PHP-DI.git", "url": "https://github.com/PHP-DI/PHP-DI.git",
"reference": "d8480267f5cf239650debba704f3ecd15b638cde" "reference": "0d1ed64126577e9a095b3204dcaee58cf76432c2"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/d8480267f5cf239650debba704f3ecd15b638cde", "url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/0d1ed64126577e9a095b3204dcaee58cf76432c2",
"reference": "d8480267f5cf239650debba704f3ecd15b638cde", "reference": "0d1ed64126577e9a095b3204dcaee58cf76432c2",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1529,7 +1529,7 @@
"friendsofphp/php-cs-fixer": "^3", "friendsofphp/php-cs-fixer": "^3",
"friendsofphp/proxy-manager-lts": "^1", "friendsofphp/proxy-manager-lts": "^1",
"mnapoli/phpunit-easymock": "^1.3", "mnapoli/phpunit-easymock": "^1.3",
"phpunit/phpunit": "^9.6", "phpunit/phpunit": "^9.6 || ^10 || ^11",
"vimeo/psalm": "^5|^6" "vimeo/psalm": "^5|^6"
}, },
"suggest": { "suggest": {
@ -1561,7 +1561,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/PHP-DI/PHP-DI/issues", "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": [ "funding": [
{ {
@ -1573,7 +1573,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2025-02-28T12:46:35+00:00" "time": "2025-04-22T08:53:15+00:00"
}, },
{ {
"name": "phpoption/phpoption", "name": "phpoption/phpoption",
@ -2829,16 +2829,16 @@
}, },
{ {
"name": "robmorgan/phinx", "name": "robmorgan/phinx",
"version": "0.16.6", "version": "0.16.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/cakephp/phinx.git", "url": "https://github.com/cakephp/phinx.git",
"reference": "5bad10934336e8cf45d50d529cabfcbe7fe287c5" "reference": "edd61785fe6b57a5992afafcc8cfdf5ea612d50d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/cakephp/phinx/zipball/5bad10934336e8cf45d50d529cabfcbe7fe287c5", "url": "https://api.github.com/repos/cakephp/phinx/zipball/edd61785fe6b57a5992afafcc8cfdf5ea612d50d",
"reference": "5bad10934336e8cf45d50d529cabfcbe7fe287c5", "reference": "edd61785fe6b57a5992afafcc8cfdf5ea612d50d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2850,8 +2850,8 @@
"symfony/console": "^6.0|^7.0" "symfony/console": "^6.0|^7.0"
}, },
"require-dev": { "require-dev": {
"cakephp/cakephp": "^5.0.2",
"cakephp/cakephp-codesniffer": "^5.0", "cakephp/cakephp-codesniffer": "^5.0",
"cakephp/i18n": "^5.0",
"ext-json": "*", "ext-json": "*",
"ext-pdo": "*", "ext-pdo": "*",
"phpunit/phpunit": "^9.5.19", "phpunit/phpunit": "^9.5.19",
@ -2910,9 +2910,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/cakephp/phinx/issues", "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", "name": "slim/flash",
@ -5365,16 +5365,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "11.5.17", "version": "11.5.18",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "fd2e863a2995cdfd864fb514b5e0b28b09895b5c" "reference": "fc3e887c7f3f9917e1bf61e523413d753db00a17"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fd2e863a2995cdfd864fb514b5e0b28b09895b5c", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fc3e887c7f3f9917e1bf61e523413d753db00a17",
"reference": "fd2e863a2995cdfd864fb514b5e0b28b09895b5c", "reference": "fc3e887c7f3f9917e1bf61e523413d753db00a17",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -5446,7 +5446,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy", "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": [ "funding": [
{ {
@ -5457,12 +5457,20 @@
"url": "https://github.com/sebastianbergmann", "url": "https://github.com/sebastianbergmann",
"type": "github" "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", "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit",
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2025-04-08T07:59:11+00:00" "time": "2025-04-22T06:09:49+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",

View File

@ -29,7 +29,6 @@ use Psr\Log\LoggerInterface;
use Slim\App; use Slim\App;
use Slim\Factory\AppFactory; use Slim\Factory\AppFactory;
use Slim\Psr7\Factory\ResponseFactory; use Slim\Psr7\Factory\ResponseFactory;
use Slovocast\Configuration\FileSystemSchema;
use Slovocast\Middleware\SessionMiddleware; use Slovocast\Middleware\SessionMiddleware;
use Twig\Error\LoaderError; use Twig\Error\LoaderError;

View File

@ -12,16 +12,12 @@ abstract class AsyncHandler extends Handler
*/ */
public function prepareResponse(array $data, string $template = ""): ResponseInterface public function prepareResponse(array $data, string $template = ""): ResponseInterface
{ {
$acceptsHeader = $this->request->getHeader('Accept'); $acceptsHeaders = $this->request->getHeader('Accept');
switch ($acceptsHeader) { if (in_array('text/html', $acceptsHeaders)) {
case 'text/html':
return $this->renderInline($template, $data); return $this->renderInline($template, $data);
break; }
case 'application/json':
default:
return $this->json($data); return $this->json($data);
break;
}
} }
} }

View 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());
}
}

View File

@ -7,7 +7,7 @@ use Slovocast\Handler\Handler;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Odan\Session\SessionInterface; use Odan\Session\SessionInterface;
class HandlerTest extends TestCase final class HandlerTest extends TestCase
{ {
public function testHtmlInlineResponse(): void public function testHtmlInlineResponse(): void
{ {