redireccion basica

This commit is contained in:
2026-01-03 01:44:34 -07:00
parent da8bd27d5f
commit b649fdff6b
4 changed files with 117 additions and 15 deletions

19
.gitignore vendored
View File

@@ -3,4 +3,21 @@ vendor/
app/config/config.php
composer.lock
.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

View File

@@ -1,12 +1,14 @@
<?php
use app\controllers\ApiExampleController;
use app\controllers\RedirectionController;
use app\middlewares\SecurityHeadersMiddleware;
use app\middlewares\DetectMobileDevice;
use flight\Engine;
use flight\net\Router;
/**
* @var Router $router
/**
* @var Router $router
* @var Engine $app
*/
@@ -14,17 +16,9 @@ use flight\net\Router;
$router->group('', function(Router $router) 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) {
echo '<h1>Hello world! Oh hey '.$name.'!</h1>';
});
$router->get('/@path', [ RedirectionController::class, 'redirect' ] );
$router->group('/api', function() use ($router) {
$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 ]);
}, [ SecurityHeadersMiddleware::class, DetectMobileDevice::class ]);

View 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;
}
}

View 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);
}
}