public function edit(Request $request, ThemeHandler $themeHandler)
{
$editable = session('theme.editable');
if (!$editable) {
return \XePresenter::make('theme.edit-auth');
}
$themeId = $request->get('theme');
$fileName = $request->get('file');
// TODO: validate themeid, fileName
if ($themeId === null) {
$e = new InvalidArgumentHttpException();
$e->setMessage('잘못된 요청입니다.');
throw $e;
}
$theme = \XeTheme::getTheme($themeId);
/** @var ThemeEntityInterface $theme */
$files = $theme->getEditFiles();
if (empty($files)) {
return \XePresenter::make('theme.edit', ['theme' => $theme, 'files' => $files]);
}
if ($fileName === null) {
$fileName = key($files);
}
$filePath = realpath($files[$fileName]);
$editFile = ['fileName' => $fileName, 'path' => $filePath];
if ($themeHandler->hasCache($filePath)) {
$editFile['hasCache'] = true;
$fileContent = file_get_contents($themeHandler->getCachePath($filePath));
} else {
$editFile['hasCache'] = false;
$fileContent = file_get_contents($filePath);
}
$editFile['content'] = $fileContent;
return \XePresenter::make('theme.edit', ['theme' => $theme, 'files' => $files, 'editFile' => $editFile]);
}