Commit f5b053b4 authored by nahakyuu's avatar nahakyuu

add demo

parent 932c2b76
...@@ -6,18 +6,16 @@ use Yiisoft\Router\Group; ...@@ -6,18 +6,16 @@ use Yiisoft\Router\Group;
use Yiisoft\Router\Route; use Yiisoft\Router\Route;
use Yiisoft\DataResponse\Middleware\FormatDataResponseAsJson; use Yiisoft\DataResponse\Middleware\FormatDataResponseAsJson;
use Yiisoft\DataResponse\Middleware\FormatDataResponseAsHtml;
use NMForce\PHPDTS\Controller\HomeController; use NMForce\PHPDTS\Controller\HomeController;
return [ return [
Group::create() Group::create()
->middleware(FormatDataResponseAsJson::class) ->middleware(FormatDataResponseAsHtml::class)
->routes( ->routes(
Route::get('[/]') Route::get('[/]')
->action([HomeController::class, 'index']) ->action([HomeController::class, 'index'])
->name('default'), ->name('/acdts/index'),
Route::get('/home')
->action([HomeController::class, 'index'])
->name('home'),
), ),
]; ];
...@@ -16,6 +16,9 @@ if (PHP_SAPI === 'cli-server') { ...@@ -16,6 +16,9 @@ if (PHP_SAPI === 'cli-server') {
return false; return false;
} }
if (is_file(dirname(__DIR__) . $path)) {
return false;
}
// Explicitly set for URLs with dot. // Explicitly set for URLs with dot.
$_SERVER['SCRIPT_NAME'] = '/index.php'; $_SERVER['SCRIPT_NAME'] = '/index.php';
} }
......
...@@ -5,22 +5,29 @@ declare(strict_types=1); ...@@ -5,22 +5,29 @@ declare(strict_types=1);
namespace NMForce\PHPDTS\Controller; namespace NMForce\PHPDTS\Controller;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Yiisoft\DataResponse\DataResponseFactoryInterface; use Yiisoft\Yii\View\ViewRenderer;
final class HomeController final class HomeController
{ {
public function __construct( public function __construct(
private StreamFactoryInterface $streamFactory, private ViewRenderer $viewRenderer,
private DataResponseFactoryInterface $responseFactory,
) { ) {
} }
public function index(): ResponseInterface public function index(): ResponseInterface
{ {
return $this->responseFactory->createResponse([ $now = time() + 8 * 3600 + 0 * 60;
'message' => 'hello', list($sec, $min, $hour, $day, $month, $year, $wday) = explode(',', date("s,i,H,j,n,Y,w", $now));
return $this->viewRenderer->render('index', [
'sec' => $sec,
'min' => $min,
'hour' => $hour,
'day' => $day,
'month' => $month,
'year' => $year,
'wday' => $wday,
'now' => $now,
]); ]);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment