dbPool->get()->con->query('select 1 from `editor_doc`'); } catch (\Exception $_) { return []; // @codeCoverageIgnore } if (!\is_file($data['path'] ?? '')) { throw new PathException($data['path'] ?? ''); } $editorFile = \file_get_contents($data['path'] ?? ''); if ($editorFile === false) { throw new PathException($data['path'] ?? ''); // @codeCoverageIgnore } $editorData = \json_decode($editorFile, true) ?? []; if ($editorData === false) { throw new \Exception(); // @codeCoverageIgnore } $result = [ 'type' => [], ]; $apiApp = new class() extends ApplicationAbstract { protected string $appName = 'Api'; }; $apiApp->dbPool = $app->dbPool; $apiApp->unitId = $app->unitId; $apiApp->accountManager = $app->accountManager; $apiApp->appSettings = $app->appSettings; $apiApp->moduleManager = $app->moduleManager; $apiApp->eventManager = $app->eventManager; /** @var array{type:array} $editorData */ foreach ($editorData as $editor) { switch ($editor['type']) { case 'type': $result['type'][] = self::createType($apiApp, $editor); break; default: } } return $result; } /** * Create type. * * @param ApplicationAbstract $app Application * @param array $data Type info * * @return array * * @since 1.0.0 */ private static function createType(ApplicationAbstract $app, array $data) : array { /** @var \Modules\Editor\Controller\ApiDocTypeController $module */ $module = $app->moduleManager->get('Editor', 'ApiDocType'); $response = new HttpResponse(); $request = new HttpRequest(); $request->header->account = 1; $request->setData('name', $data['name'] ?? ''); $request->setData('title', $data['name'] ?? ''); $module->apiEditorDocTypeCreate($request, $response); $responseData = $response->getData(''); if (!\is_array($responseData)) { return []; } /** @var \phpOMS\Localization\BaseStringL11nType $type */ $type = $responseData['response']; $id = $type->id; $isFirst = true; foreach ($data['l11n'] as $lang => $l11n) { if ($isFirst) { $isFirst = false; continue; } $response = new HttpResponse(); $request = new HttpRequest(); $request->header->account = 1; $request->setData('title', $l11n); $request->setData('lang', $lang); $request->setData('type', $id); $module->apiEditorDocTypeL11nCreate($request, $response); } return $type->toArray(); } }