# .htaccess
Options +FollowSymlinks -Indexes
DirectoryIndex public/index.html public/index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /public/index.php?_url=/$1 [L,QSA]
<?php
// app.php
define('__ROOT__', __DIR__);
define('__APP__', realpath(__ROOT__ . '/app'));
$routes = require_once __APP__ . '/routes.php';
foreach ($routes as $pattern => $action) {
if (! preg_match($pattern, $_SERVER['REQUEST_URI'], $matches)) continue;
$action = array_filter(explode('/', $action));
$file = basename(array_pop($action), '.php');
array_push($action, $file);
require __APP__ . '/controllers/' . implode('/', $action) . '.php';
break;
}
<?php
// public/index.php
// strict
register_shutdown_function(function () {
$error = error_get_last();
if (! $error) return;
if (! ($error['line'] ?? null)) return;
$errno = $error['type'];
$errmsg = $error['message'];
$errfile = $error['file'];
$errline = $error['line'];
handle(new \ErrorException($errmsg, $errcode = -1, $errno, $errfile, $errline));
});
// error
set_error_handler(function ($errno, $errmsg, $errfile, $errline) {
if (! $errline) return;
throw new \ErrorException($errmsg, $errcode = -1, $errno, $errfile, $errline);
}, E_ALL);
// handle
function handle(\Throwable $e)
{
echo '<pre>';
die(var_dump($e));
}
// index.php
try {
// run application
require_once __DIR__ . '/../app.php';
} catch (\Throwable $e) { handle($e); }
<?php
// app/routes.php
$routes = [];
foreach ([
'/' => 'index',
'/foo/bar' => 'index',
'/hello/world' => 'hello/world',
] as $pattern => $action) {
$routes[ '/^' . preg_quote($pattern, '/') . '$/' ] = $action;
}
return $routes;
<?php
// app/controllers/index.php
echo 'Index';
<?php
// app/controllers/hello/world.php
echo 'Hello/World';
$param = $_POST["param"];
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; //вот это может декодировать функция
$data_json = json_encode($_POST);
json_decode($data_json);
<script>
перед закрывающим тегом </body>
, либо весь код внутрь обработчика DOMContentLoaded. по каким признакам опытные программисты могут определить, что делать с этим проектом?Ищем то, что является точкой входа и отвечает за роутинг и погнали оттуда вглубь. Если проект самописный, то эффективным может оказаться пройти весь стек вызовов через XDebug - файлов, скорее всего, будет немного.