cms/app/Http/Controllers/Admin/Themes/ThemeEditorFileReadController.php
Funky Waddle 37ed997989 feat(cms): initialize Laravel project structure and core CMS files
- Added standard Laravel directory structure and configuration.

- Included Svelte and Tailwind configuration for the admin interface.

- Added core PHPUnit and testing scripts.
2026-04-13 12:48:06 -05:00

45 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\Themes;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Themes\ThemeFileReadRequest;
use App\Services\ThemeEditorService;
use Illuminate\Support\Facades\File;
use Exception;
/**
* Controller for reading the content of a theme file.
*/
class ThemeEditorFileReadController extends Controller
{
/**
* Handle the file read request.
*
* @param \App\Http\Requests\Admin\Themes\ThemeFileReadRequest $request
* @param \App\Services\ThemeEditorService $editorService
* @return \Illuminate\Http\JsonResponse
*/
public function __invoke(ThemeFileReadRequest $request, ThemeEditorService $editorService)
{
$theme = $request->query('theme');
$path = $request->query('path');
try {
$content = $editorService->readFile($theme, $path);
// We need the full path to get the extension for the response
$basePath = realpath(base_path('themes/' . $theme));
$fullPath = realpath($basePath . '/' . $path);
return response()->json([
'content' => $content,
'extension' => File::extension($fullPath)
]);
} catch (Exception $e) {
$statusCode = str_contains($e->getMessage(), 'Unauthorized') ? 403 : 404;
return response()->json(['error' => $e->getMessage()], $statusCode);
}
}
}