gem-diamond
schmarty
·
2024-07-29
·
via Feed of "schmarty/gem-diamond"
共有 3 个文件被更改,包括 41 次插入 和 7 次删除
|
|
|
|
@ -6,20 +6,19 @@ use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
|
|
|
|
|
|
use Schmarty\Micropubkit\Controllers\Common\{ResponseAware,ResponseAwareTrait};
|
|
|
|
|
use Schmarty\Micropubkit\Controllers\Common\{TemplatesAware,TemplatesAwareTrait};
|
|
|
|
|
|
|
|
|
|
class Controller implements ResponseAware {
|
|
|
|
|
class Controller implements ResponseAware, TemplatesAware {
|
|
|
|
|
|
|
|
|
|
use ResponseAwareTrait;
|
|
|
|
|
use TemplatesAwareTrait;
|
|
|
|
|
|
|
|
|
|
private \League\Plates\Engine $templates;
|
|
|
|
|
private \App\Model\Site $site;
|
|
|
|
|
private \App\Model\SiteCheck $siteCheck;
|
|
|
|
|
|
|
|
|
|
public function __construct(\League\Plates\Engine $templates, \App\Model\Site $site, \App\Model\SiteCheck $siteCheck) {
|
|
|
|
|
$this->templates = $templates;
|
|
|
|
|
public function __construct(\App\Model\Site $site, \App\Model\SiteCheck $siteCheck) {
|
|
|
|
|
$this->site = $site;
|
|
|
|
|
$this->siteCheck = $siteCheck;
|
|
|
|
|
$this->templates->addData(['hostname' => $_SERVER['SERVER_NAME']]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index(ServerRequestInterface $request): ResponseInterface {
|
|
|
|
|
|
|
|
|
|
@ -0,0 +1,31 @@
|
|
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
|
|
|
|
use Psr\Http\Server\MiddlewareInterface;
|
|
|
|
|
|
|
|
|
|
use Schmarty\Micropubkit\Controllers\Common\{TemplatesAware,TemplatesAwareTrait};
|
|
|
|
|
|
|
|
|
|
class TemplatesCommonMiddleware implements MiddlewareInterface, TemplatesAware
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
use TemplatesAwareTrait;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
|
|
|
|
{
|
|
|
|
|
// add common bits that our temlpates need to know
|
|
|
|
|
$this->templates->addData([
|
|
|
|
|
'hostname' => $_SERVER['SERVER_NAME']
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// and pass along
|
|
|
|
|
return $handler->handle($request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -24,12 +24,16 @@ $app->container->addShared(App\Model\SiteCheck::class)->addArgument(App\DB::clas
|
|
|
|
|
|
|
|
|
|
// set up controller for welcome and forms
|
|
|
|
|
$app->container->addShared(App\Controller::class)
|
|
|
|
|
->addArgument(League\Plates\Engine::class)
|
|
|
|
|
->addArgument(App\Model\Site::class)
|
|
|
|
|
->addArgument(App\Model\SiteCheck::class);
|
|
|
|
|
|
|
|
|
|
// set up middleware
|
|
|
|
|
$app->container->add(App\TemplatesCommonMiddleware::class);
|
|
|
|
|
|
|
|
|
|
// allow login everywhere but be chill about it
|
|
|
|
|
$app->route->middleware($app->optionalAuthMiddleware);
|
|
|
|
|
$app->route
|
|
|
|
|
->middleware($app->optionalAuthMiddleware)
|
|
|
|
|
->middleware($app->container->get(App\TemplatesCommonMiddleware::class));
|
|
|
|
|
|
|
|
|
|
// set up app-specific routes
|
|
|
|
|
$app->route->get('/', 'App\\Controller::index')->setName('loginForm');
|
|
|
|
|
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。