MAPG-3 create basic contoller functionality
This commit is contained in:
1 parent
c63f05295e
commit
555984caf5
5 files changed
+70
-1
No files matched your search
@@ -0,0 +1,24 @@
|
||||
<?php namespace MapGuesser\Controller;
|
||||
|
||||
abstract class BaseController
|
||||
{
|
||||
protected string $view;
|
||||
|
||||
protected array $variables = [];
|
||||
|
||||
public function render() : string
|
||||
{
|
||||
$this->operate();
|
||||
|
||||
extract($this->variables);
|
||||
|
||||
ob_start();
|
||||
require ROOT . '/views/' . $this->view . '.php';
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
abstract protected function operate() : void;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php namespace MapGuesser\Controller;
|
||||
|
||||
use MapGuesser\Util\Geo\Bounds;
|
||||
use MapGuesser\Util\Geo\Position;
|
||||
|
||||
class GuessController extends BaseController
|
||||
{
|
||||
protected string $view = 'guess';
|
||||
|
||||
protected function operate() : void
|
||||
{
|
||||
// demo position
|
||||
$realPosition = new Position(47.85239, 13.35101);
|
||||
|
||||
// demo bounds
|
||||
$bounds = new Bounds($realPosition);
|
||||
$bounds->extend(new Position(48.07683,7.35758));
|
||||
$bounds->extend(new Position(47.57496, 19.08077));
|
||||
|
||||
$this->variables = compact('realPosition', 'bounds');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user