This commit is contained in:
lubiana 2022-03-31 08:34:30 +02:00
parent ca40fdd970
commit 4b7c281224
107 changed files with 8372 additions and 186 deletions

31
app/src/Action/Hello.php Normal file
View file

@ -0,0 +1,31 @@
<?php declare(strict_types=1);
namespace Lubian\NoFramework\Action;
use Lubian\NoFramework\Service\Time\Now;
use Lubian\NoFramework\Template\Renderer;
use Psr\Http\Message\ResponseInterface;
final class Hello
{
public function __invoke(
ResponseInterface $response,
Now $now,
Renderer $renderer,
string $name = 'Stranger',
): ResponseInterface {
$body = $response->getBody();
$data = [
'now' => $now()->format('H:i:s'),
'name' => $name,
];
$content = $renderer->render('hello', $data);
$body->write($content);
return $response
->withStatus(200)
->withBody($body);
}
}

19
app/src/Action/Other.php Normal file
View file

@ -0,0 +1,19 @@
<?php declare(strict_types=1);
namespace Lubian\NoFramework\Action;
use Psr\Http\Message\ResponseInterface;
final class Other
{
public function someFunctionName(ResponseInterface $response): ResponseInterface
{
$body = $response->getBody();
$body->write('This works too!');
return $response
->withStatus(200)
->withBody($body);
}
}

35
app/src/Action/Page.php Normal file
View file

@ -0,0 +1,35 @@
<?php declare(strict_types=1);
namespace Lubian\NoFramework\Action;
use Lubian\NoFramework\Repository\MarkdownPageRepo;
use Lubian\NoFramework\Template\Renderer;
use Parsedown;
use Psr\Http\Message\ResponseInterface;
use function preg_replace;
use function str_replace;
class Page
{
public function __invoke(
string $page,
ResponseInterface $response,
MarkdownPageRepo $repo,
Parsedown $parsedown,
Renderer $renderer,
): ResponseInterface {
$page = $repo->byTitle($page);
$content = $this->linkFilter($page->content);
$content = $parsedown->parse($content);
$html = $renderer->render('page', ['content' => $content]);
$response->getBody()->write($html);
return $response;
}
private function linkFilter(string $content): string
{
$content = preg_replace('/\(\d\d-/m', '(', $content);
return str_replace('.md)', ')', $content);
}
}