Add a page handler class.
This commit is contained in:
parent
bec39c3c8b
commit
7e0285f9b5
7
app/src/Exception/TemplateNotSetException.php
Normal file
7
app/src/Exception/TemplateNotSetException.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Slovocast\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class TemplateNotSetException extends Exception { }
|
@ -2,14 +2,9 @@
|
||||
|
||||
namespace Slovocast\Handler\Channel\Page;
|
||||
|
||||
use Odan\Session\SessionInterface;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Slovocast\Handler\Handler;
|
||||
use Slovocast\Handler\Page;
|
||||
|
||||
class CreateChannelPage extends Handler
|
||||
class CreateChannelPage extends Page
|
||||
{
|
||||
public function handle(): Response
|
||||
{
|
||||
return $this->render('channel/create.twig');
|
||||
}
|
||||
protected string $template = "channel/create.twig";
|
||||
}
|
||||
|
24
app/src/Handler/Page.php
Normal file
24
app/src/Handler/Page.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Slovocast\Handler;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Slovocast\Exception\TemplateNotSetException;
|
||||
|
||||
abstract class Page extends Handler
|
||||
{
|
||||
protected string $template = '';
|
||||
protected array $pageProps = [];
|
||||
|
||||
/**
|
||||
* @throws TemplateNotSetException
|
||||
*/
|
||||
public function handle(): ResponseInterface
|
||||
{
|
||||
if (!$this->template) {
|
||||
throw new TemplateNotSetException("No template set.");
|
||||
}
|
||||
|
||||
return $this->render($this->template, $this->pageProps);
|
||||
}
|
||||
}
|
@ -8,10 +8,12 @@ use Psr\Log\LoggerInterface;
|
||||
use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface;
|
||||
use Slovocast\Domain\Repository\User\UserRepositoryInterface;
|
||||
use Slovocast\Exception\EntityNotFoundException;
|
||||
use Slovocast\Handler\Handler;
|
||||
use Slovocast\Handler\Page;
|
||||
|
||||
class DashboardPage extends Handler
|
||||
class DashboardPage extends Page
|
||||
{
|
||||
protected string $template = "dashboard";
|
||||
|
||||
public function __construct(
|
||||
protected UserRepositoryInterface $userRepository,
|
||||
protected ChannelRepositoryInterface $channelRepository,
|
||||
@ -33,6 +35,7 @@ class DashboardPage extends Handler
|
||||
$channel = null;
|
||||
}
|
||||
|
||||
return $this->render('dashboard.twig', [ 'channel' => $channel ]);
|
||||
$this->pageProps = [ 'channel' => $channel ];
|
||||
return parent::handle();
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,9 @@
|
||||
|
||||
namespace Slovocast\Handler\Page;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Slovocast\Handler\Handler;
|
||||
use Slovocast\Handler\Page;
|
||||
|
||||
class HomePage extends Handler
|
||||
class HomePage extends Page
|
||||
{
|
||||
public function handle(): Response
|
||||
{
|
||||
return $this->render('home.twig');
|
||||
}
|
||||
protected string $template = "home.twig";
|
||||
}
|
||||
|
@ -2,14 +2,9 @@
|
||||
|
||||
namespace Slovocast\Handler\User\Page;
|
||||
|
||||
use Odan\Session\SessionInterface;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Slovocast\Handler\Handler;
|
||||
use Slovocast\Handler\Page;
|
||||
|
||||
class LoginUserPage extends Handler
|
||||
class LoginUserPage extends Page
|
||||
{
|
||||
public function handle(): Response
|
||||
{
|
||||
return $this->render('user/login.twig');
|
||||
}
|
||||
protected string $template = "user/login.twig";
|
||||
}
|
||||
|
@ -2,14 +2,9 @@
|
||||
|
||||
namespace Slovocast\Handler\User\Page;
|
||||
|
||||
use Odan\Session\SessionInterface;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Slovocast\Handler\Handler;
|
||||
use Slovocast\Handler\Page;
|
||||
|
||||
class RegisterUserPage extends Handler
|
||||
class RegisterUserPage extends Page
|
||||
{
|
||||
public function handle(): Response
|
||||
{
|
||||
return $this->render('user/register.twig');
|
||||
}
|
||||
protected string $template = "user/register.twig";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user