redireccion basica
This commit is contained in:
19
.gitignore
vendored
19
.gitignore
vendored
@@ -3,4 +3,21 @@ vendor/
|
|||||||
app/config/config.php
|
app/config/config.php
|
||||||
composer.lock
|
composer.lock
|
||||||
.vagrant/
|
.vagrant/
|
||||||
.runway-creds.json
|
.runway-creds.json
|
||||||
|
.cursor/
|
||||||
|
.gemini/
|
||||||
|
.github/
|
||||||
|
.windsurfrules
|
||||||
|
LICENSE
|
||||||
|
Vagrantfile
|
||||||
|
app/config/config_sample.php
|
||||||
|
app/log/
|
||||||
|
docker-compose.yml
|
||||||
|
app/controllers/ApiExampleController.php
|
||||||
|
index-simple.php
|
||||||
|
runway
|
||||||
|
app/commands/SampleDatabaseCommand.php
|
||||||
|
app/views/welcome.php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use app\controllers\ApiExampleController;
|
use app\controllers\ApiExampleController;
|
||||||
|
use app\controllers\RedirectionController;
|
||||||
use app\middlewares\SecurityHeadersMiddleware;
|
use app\middlewares\SecurityHeadersMiddleware;
|
||||||
|
use app\middlewares\DetectMobileDevice;
|
||||||
use flight\Engine;
|
use flight\Engine;
|
||||||
use flight\net\Router;
|
use flight\net\Router;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Router $router
|
* @var Router $router
|
||||||
* @var Engine $app
|
* @var Engine $app
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -14,17 +16,9 @@ use flight\net\Router;
|
|||||||
$router->group('', function(Router $router) use ($app) {
|
$router->group('', function(Router $router) use ($app) {
|
||||||
|
|
||||||
$router->get('/', function() use ($app) {
|
$router->get('/', function() use ($app) {
|
||||||
$app->render('welcome', [ 'message' => 'You are gonna do great things!' ]);
|
$app->redirect('https://google.com/maps');
|
||||||
});
|
} );
|
||||||
|
|
||||||
$router->get('/hello-world/@name', function($name) {
|
$router->get('/@path', [ RedirectionController::class, 'redirect' ] );
|
||||||
echo '<h1>Hello world! Oh hey '.$name.'!</h1>';
|
|
||||||
});
|
|
||||||
|
|
||||||
$router->group('/api', function() use ($router) {
|
}, [ SecurityHeadersMiddleware::class, DetectMobileDevice::class ]);
|
||||||
$router->get('/users', [ ApiExampleController::class, 'getUsers' ]);
|
|
||||||
$router->get('/users/@id:[0-9]', [ ApiExampleController::class, 'getUser' ]);
|
|
||||||
$router->post('/users/@id:[0-9]', [ ApiExampleController::class, 'updateUser' ]);
|
|
||||||
});
|
|
||||||
|
|
||||||
}, [ SecurityHeadersMiddleware::class ]);
|
|
||||||
65
app/controllers/RedirectionController.php
Normal file
65
app/controllers/RedirectionController.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\controllers;
|
||||||
|
|
||||||
|
use flight\Engine;
|
||||||
|
|
||||||
|
class RedirectionController {
|
||||||
|
|
||||||
|
protected Engine $app;
|
||||||
|
|
||||||
|
public function __construct($app) {
|
||||||
|
$this->app = $app;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function redirect( string $path)
|
||||||
|
{
|
||||||
|
$data = $this->getRedirections();
|
||||||
|
$path_lower = strtolower($path);
|
||||||
|
|
||||||
|
if (array_key_exists($path_lower, $data)) {
|
||||||
|
$data = $data[$path_lower];
|
||||||
|
$website = $this->app->get('is_apple') ? $data['website1'] : $data['website2'];
|
||||||
|
|
||||||
|
if (!empty($website)) {
|
||||||
|
$this->app->redirect($website);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Fallback if path not found or website1 is empty
|
||||||
|
$this->app->redirect('https://google.com/maps');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRedirections() {
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'malecon' => [
|
||||||
|
'website1' => 'https://maps.apple/p/-ezVTdQ8aSUs.n',
|
||||||
|
'website2' => 'https://maps.app.goo.gl/n1betgNTZgx4RoEJ8'
|
||||||
|
],
|
||||||
|
'puntacerritos' => [
|
||||||
|
'website1' => '',
|
||||||
|
'website2' => 'https://maps.app.goo.gl/NSDoQZXnFWDcEgor5'
|
||||||
|
],
|
||||||
|
'zonadorada' => [
|
||||||
|
'website1' => '',
|
||||||
|
'website2' => 'https://maps.app.goo.gl/CDt7vRw2M6oEqgBA8'
|
||||||
|
],
|
||||||
|
'galeron' => [
|
||||||
|
'website1' => '',
|
||||||
|
'website2' => 'https://maps.app.goo.gl/CjkXvvNd2aA4ftiKA'
|
||||||
|
],
|
||||||
|
'monosbichis' => [
|
||||||
|
'website1' => '',
|
||||||
|
'website2' => 'https://maps.app.goo.gl/M1dHZoRANfgCH9f67'
|
||||||
|
],
|
||||||
|
'pinchisplebes' => [
|
||||||
|
'website1' => '',
|
||||||
|
'website2' => 'https://maps.app.goo.gl/o2uq6qQQiLxAkw7f6'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
app/middlewares/DetectMobileDevice.php
Normal file
26
app/middlewares/DetectMobileDevice.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace app\middlewares;
|
||||||
|
|
||||||
|
use flight\Engine;
|
||||||
|
use Tracy\Debugger;
|
||||||
|
|
||||||
|
class DetectMobileDevice
|
||||||
|
{
|
||||||
|
protected Engine $app;
|
||||||
|
|
||||||
|
public function __construct(Engine $app)
|
||||||
|
{
|
||||||
|
$this->app = $app;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function before(array $params): void
|
||||||
|
{
|
||||||
|
$userAgent = $this->app->request()->user_agent;
|
||||||
|
|
||||||
|
$is_apple = preg_match('/iPhone|iPad|iPod/i', $userAgent);
|
||||||
|
|
||||||
|
$this->app->set('is_apple', $is_apple);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user