Skip to content

Commit 8107bc8

Browse files
committed
added copy of Web Project 3.0 https://github.com/nette/web-project
1 parent e447872 commit 8107bc8

25 files changed

+436
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
app/config/local.neon

.htaccess

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Require all denied

app/Booting.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App;
6+
7+
use Nette\Configurator;
8+
9+
10+
class Booting
11+
{
12+
public static function boot(): Configurator
13+
{
14+
$configurator = new Configurator;
15+
16+
//$configurator->setDebugMode('23.75.345.200'); // enable for your remote IP
17+
$configurator->enableTracy(__DIR__ . '/../log');
18+
19+
$configurator->setTimeZone('Europe/Prague');
20+
$configurator->setTempDirectory(__DIR__ . '/../temp');
21+
22+
$configurator->createRobotLoader()
23+
->addDirectory(__DIR__)
24+
->register();
25+
26+
$configurator->addConfig(__DIR__ . '/config/common.neon');
27+
$configurator->addConfig(__DIR__ . '/config/local.neon');
28+
29+
return $configurator;
30+
}
31+
}

app/config/common.neon

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
parameters:
2+
3+
4+
application:
5+
errorPresenter: Error
6+
mapping:
7+
*: App\*Module\Presenters\*Presenter
8+
9+
10+
session:
11+
expiration: 14 days
12+
13+
14+
services:
15+
router: App\RouterFactory::createRouter

app/presenters/Error4xxPresenter.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Presenters;
6+
7+
use Nette;
8+
9+
10+
final class Error4xxPresenter extends Nette\Application\UI\Presenter
11+
{
12+
public function startup(): void
13+
{
14+
parent::startup();
15+
if (!$this->getRequest()->isMethod(Nette\Application\Request::FORWARD)) {
16+
$this->error();
17+
}
18+
}
19+
20+
21+
public function renderDefault(Nette\Application\BadRequestException $exception): void
22+
{
23+
// load template 403.latte or 404.latte or ... 4xx.latte
24+
$file = __DIR__ . "/templates/Error/{$exception->getCode()}.latte";
25+
$this->template->setFile(is_file($file) ? $file : __DIR__ . '/templates/Error/4xx.latte');
26+
}
27+
}

app/presenters/ErrorPresenter.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Presenters;
6+
7+
use Nette;
8+
use Nette\Application\Responses;
9+
use Nette\Http;
10+
use Tracy\ILogger;
11+
12+
13+
final class ErrorPresenter implements Nette\Application\IPresenter
14+
{
15+
use Nette\SmartObject;
16+
17+
/** @var ILogger */
18+
private $logger;
19+
20+
21+
public function __construct(ILogger $logger)
22+
{
23+
$this->logger = $logger;
24+
}
25+
26+
27+
public function run(Nette\Application\Request $request): Nette\Application\IResponse
28+
{
29+
$exception = $request->getParameter('exception');
30+
31+
if ($exception instanceof Nette\Application\BadRequestException) {
32+
[$module, , $sep] = Nette\Application\Helpers::splitName($request->getPresenterName());
33+
return new Responses\ForwardResponse($request->setPresenterName($module . $sep . 'Error4xx'));
34+
}
35+
36+
$this->logger->log($exception, ILogger::EXCEPTION);
37+
return new Responses\CallbackResponse(function (Http\IRequest $httpRequest, Http\IResponse $httpResponse): void {
38+
if (preg_match('#^text/html(?:;|$)#', (string) $httpResponse->getHeader('Content-Type'))) {
39+
require __DIR__ . '/templates/Error/500.phtml';
40+
}
41+
});
42+
}
43+
}

app/presenters/HomepagePresenter.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Presenters;
6+
7+
use Nette;
8+
9+
10+
final class HomepagePresenter extends Nette\Application\UI\Presenter
11+
{
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
7+
<title>{ifset title}{include title|stripHtml} | {/ifset}Nette Web</title>
8+
</head>
9+
10+
<body>
11+
<div n:foreach="$flashes as $flash" n:class="flash, $flash->type">{$flash->message}</div>
12+
13+
{include content}
14+
15+
{block scripts}
16+
<script src="https://nette.github.io/resources/js/3/netteForms.min.js"></script>
17+
{/block}
18+
</body>
19+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{block content}
2+
<h1 n:block=title>Access Denied</h1>
3+
4+
<p>You do not have permission to view this page. Please try contact the web
5+
site administrator if you believe you should be able to view this page.</p>
6+
7+
<p><small>error 403</small></p>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{block content}
2+
<h1 n:block=title>Page Not Found</h1>
3+
4+
<p>The page you requested could not be found. It is possible that the address is
5+
incorrect, or that the page no longer exists. Please use a search engine to find
6+
what you are looking for.</p>
7+
8+
<p><small>error 404</small></p>

0 commit comments

Comments
 (0)