From 67094790d2d9db5c99e7c136f49061a78698e57d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 24 Nov 2025 04:58:38 +0900 Subject: Add vhosts/t/phpcon-kagawa-2025/ --- .../src/PhpConKagawa2025/CookieHandler.php | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 vhosts/t/phpcon-kagawa-2025/src/PhpConKagawa2025/CookieHandler.php (limited to 'vhosts/t/phpcon-kagawa-2025/src/PhpConKagawa2025/CookieHandler.php') diff --git a/vhosts/t/phpcon-kagawa-2025/src/PhpConKagawa2025/CookieHandler.php b/vhosts/t/phpcon-kagawa-2025/src/PhpConKagawa2025/CookieHandler.php new file mode 100644 index 0000000..0b9f656 --- /dev/null +++ b/vhosts/t/phpcon-kagawa-2025/src/PhpConKagawa2025/CookieHandler.php @@ -0,0 +1,92 @@ +getCookieParams(); + + $orders = []; + if (isset($cookies['order']) && $cookies['order'] !== '') { + $orders = explode(',', $cookies['order']); + } + + $setCookie = null; + + if ($request->getMethod() === 'POST') { + $postData = []; + parse_str((string) $request->getBody(), $postData); + $newOrder = $postData['udon'] ?? ''; + if ($newOrder !== '') { + $orders[] = $newOrder; + $setCookie = 'order=' . urlencode(implode(',', $orders)) . '; path=/'; + } + } + + $orderList = ''; + if (count($orders) > 0) { + $orderList = '

現在の注文

'; + $orderList .= '食べる'; + } else { + $orderList = '

まだ注文がありません。

'; + } + + $body = << + + + + + うどん店 + + +
+

うどん店

+
+
+ +
+ +
+ {$orderList} +
+ + +HTML; + + $response = $this->responseFactory->createResponse(200) + ->withHeader('Content-Type', 'text/html; charset=UTF-8') + ->withBody($this->streamFactory->createStream($body)); + + if ($setCookie !== null) { + $response = $response->withHeader('Set-Cookie', $setCookie); + } + + return $response; + } +} -- cgit v1.2.3-70-g09d2