Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
52 lines (46 loc) · 1.37 KB

File metadata and controls

52 lines (46 loc) · 1.37 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace App\Controllers;
use MaplePHP\Core\Render\StaticRenderer;
use MaplePHP\Core\Support\Twig;
use MaplePHP\DTO\Format\Clock;
use Psr\Http\Message\ResponseInterface;
use MaplePHP\Core\Routing\DefaultController;
use MaplePHP\Http\Interfaces\PathInterface;
class HelloWorldController extends DefaultController
{
/**
* Default route example.
*
* The response body is written to using the PSR-7 stream and the
* modified response is returned to the framework.
*
* @param ResponseInterface $response Response instance used to write output
* @param StaticRenderer $render
* @return ResponseInterface
*/
public function index(ResponseInterface $response, StaticRenderer $render): ResponseInterface
{
$html = $render->welcome();
$response->getBody()->write($html);
return $response;
}
/**
* Twig-rendered example page.
* Renders resources/views/hello.twig with a set of props passed as template variables.
*
* @param Twig $twig
* @param PathInterface $path
* @throws \Exception
*/
public function show(Twig $twig, PathInterface $path): void
{
$name = $path->select("name")->last() ?: 'World';
$twig->render('views/hello.twig', [
'title' => 'Hello from Twig',
'name' => $name,
'rendered_at' => Clock::value('now')->dateTime(),
'items' => ['Twig templates', 'PSR-7 responses', 'Dependency injection'],
]);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.