mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
Correzioni per retro-compatibilità API
This commit is contained in:
@@ -5,19 +5,30 @@ namespace App\Http\Controllers;
|
||||
use App\Exceptions\LegacyExitException;
|
||||
use App\Exceptions\LegacyRedirectException;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class LegacyController extends Controller
|
||||
{
|
||||
public function index($path = 'index.php')
|
||||
public function index(Request $request, $path = 'index.php')
|
||||
{
|
||||
$base_path = base_path('legacy');
|
||||
|
||||
// Fix per redirect all'API
|
||||
$api_request = false;
|
||||
if (in_array($path, ['api', 'api/', 'api/index.php'])) {
|
||||
$path = 'api/index.php';
|
||||
$api_request = true;
|
||||
}
|
||||
|
||||
// Ricerca del file interessato
|
||||
$file = realpath($base_path.'/'.$path);
|
||||
if (strpos($file, $base_path) === false) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
// Inclusione diretta del file
|
||||
ob_start();
|
||||
try {
|
||||
require $file;
|
||||
@@ -26,13 +37,17 @@ class LegacyController extends Controller
|
||||
return Redirect::to($e->getMessage());
|
||||
}
|
||||
|
||||
// Gestione dell'output
|
||||
$output = ob_get_clean();
|
||||
|
||||
$response = response($output);
|
||||
|
||||
// Fix content-type per contenuti non HTML
|
||||
if (ends_with($path, '.js')) {
|
||||
$response = $response->header('Content-Type', 'application/javascript');
|
||||
} elseif (string_contains($path, 'pdfgen.php')) {
|
||||
$response = $response->header('Content-Type', 'application/pdf');
|
||||
} elseif ($api_request) {
|
||||
$response = $response->header('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
Reference in New Issue
Block a user