- Added standard Laravel directory structure and configuration. - Included Svelte and Tailwind configuration for the admin interface. - Added core PHPUnit and testing scripts.
44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Themes;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\Themes\ThemeEditorCreateRequest;
|
|
use App\Services\ThemeEditorService;
|
|
use Exception;
|
|
|
|
/**
|
|
* Controller for creating a new theme file.
|
|
*/
|
|
class ThemeEditorFileCreateController extends Controller
|
|
{
|
|
/**
|
|
* Handle the file creation request.
|
|
*
|
|
* @param \App\Http\Requests\Admin\Themes\ThemeEditorCreateRequest $request
|
|
* @param \App\Services\ThemeEditorService $editorService
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function __invoke(ThemeEditorCreateRequest $request, ThemeEditorService $editorService)
|
|
{
|
|
try {
|
|
$editorService->createFile(
|
|
$request->input('theme'),
|
|
$request->input('path'),
|
|
$request->input('filename')
|
|
);
|
|
|
|
return response()->json(['success' => true]);
|
|
} catch (Exception $e) {
|
|
$statusCode = 500;
|
|
if (str_contains($e->getMessage(), 'not found')) $statusCode = 404;
|
|
if (str_contains($e->getMessage(), 'Invalid path')) $statusCode = 403;
|
|
if (str_contains($e->getMessage(), 'Invalid filename')) $statusCode = 422;
|
|
if (str_contains($e->getMessage(), 'already exists')) $statusCode = 422;
|
|
if (str_contains($e->getMessage(), 'Invalid file extension')) $statusCode = 422;
|
|
|
|
return response()->json(['error' => $e->getMessage()], $statusCode);
|
|
}
|
|
}
|
|
}
|