Skip to content

Commit 325741b

Browse files
committed
BaseControll created, template variable typed in PHP, LoginForm created
1 parent e14e627 commit 325741b

File tree

22 files changed

+297
-26
lines changed

22 files changed

+297
-26
lines changed

app/Model/Factory/LoginFactory.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\Model\Factory;
6+
7+
use App\Module\_components\Login\Login;
8+
9+
interface LoginFactory
10+
{
11+
public function create(): Login;
12+
}

app/Model/BaseRepository.php renamed to app/Model/Repository/BaseRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Model;
5+
namespace App\Model\Repository;
66

77
use Dibi\Connection;
88

app/Model/Repository/EventRepository.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace App\Model\Repository;
66

7-
use App\Model\BaseRepository;
8-
97
class EventRepository extends BaseRepository
108
{
119
private const TABLE = 'event';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Model\Service;
4+
5+
use Nette\Security\User as NetteSecurityUser;
6+
7+
class AuthorizationService
8+
{
9+
public function __construct(
10+
private NetteSecurityUser $netteSecurityUser,
11+
) {
12+
}
13+
14+
public function isLoggedIn(): bool
15+
{
16+
return $this->netteSecurityUser->isLoggedIn();
17+
}
18+
}

app/Module/BasePresenter.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,38 @@
44

55
namespace App\Module;
66

7+
use App\Model\Factory\LoginFactory;
8+
use App\Model\Service\AuthorizationService;
9+
use App\Module\_components\Login\Login;
710
use Nette\Application\UI\Presenter;
11+
use Nette\Bridges\ApplicationLatte\Template;
12+
use stdClass;
813

9-
abstract class BasePresenter extends Presenter
14+
/**
15+
* @property-read Template|stdClass $template
16+
*/
17+
class BasePresenter extends Presenter
1018
{
19+
public function __construct(
20+
private AuthorizationService $authorizationService,
21+
private LoginFactory $loginFactory
22+
)
23+
{
24+
parent::__construct();
25+
}
26+
27+
protected function beforeRender(): void
28+
{
29+
$this->template->isLogged = $this->authorizationService->isLoggedIn();
30+
}
31+
32+
protected function createComponentLogin(): Login
33+
{
34+
return $this->loginFactory->create();
35+
}
36+
37+
public function findLayoutTemplateFile(): ?string
38+
{
39+
return __DIR__ . '/_templates/@layout.latte';
40+
}
1141
}

app/Module/ModulePresenter.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

app/Module/User/Error4xx/Error4xxPresenter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
namespace App\Module\User\Error4xx;
66

7+
use App\Module\BasePresenter;
78
use Nette;
89

9-
final class Error4xxPresenter extends Nette\Application\UI\Presenter
10+
final class Error4xxPresenter extends BasePresenter
1011
{
1112
public function startup(): void
1213
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Module\User\Register;
6+
7+
use App\Module\BasePresenter;
8+
9+
class RegisterPresenter extends BasePresenter
10+
{
11+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{block content}

app/Module/User/UserPresenter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace App\Module\User;
66

7-
use App\Module\ModulePresenter;
7+
use App\Module\BasePresenter;
88

9-
class UserPresenter extends ModulePresenter
9+
class UserPresenter extends BasePresenter
1010
{
1111
}

0 commit comments

Comments
 (0)