MAPG-3 create basic contoller functionality
This commit is contained in:
parent
c63f05295e
commit
555984caf5
4
main.php
4
main.php
@ -2,7 +2,9 @@
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||
const ROOT = __DIR__;
|
||||
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(ROOT);
|
||||
$dotenv->load();
|
||||
|
||||
if (!empty($_ENV['DEV'])) {
|
||||
|
5
public/.htaccess
Normal file
5
public/.htaccess
Normal file
@ -0,0 +1,5 @@
|
||||
RewriteEngine On
|
||||
RewriteBase /
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^ index.php [L]
|
16
public/index.php
Normal file
16
public/index.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
require '../main.php';
|
||||
|
||||
// very basic routing
|
||||
$url = $_SERVER['REQUEST_URI'];
|
||||
switch($url) {
|
||||
case '/':
|
||||
$controller = new MapGuesser\Controller\GuessController();
|
||||
break;
|
||||
default:
|
||||
echo 'Error 404';
|
||||
die;
|
||||
}
|
||||
|
||||
echo $controller->render();
|
24
src/Controller/BaseController.php
Normal file
24
src/Controller/BaseController.php
Normal file
@ -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;
|
||||
}
|
22
src/Controller/GuessController.php
Normal file
22
src/Controller/GuessController.php
Normal file
@ -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');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user