dbPool->get()->con->query('select 1 from `editor_doc`'); } catch (\Exception $e) { 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' => [], ]; foreach ($editorData as $editor) { switch ($editor['type']) { case 'type': $result['type'][] = self::createType($app->dbPool, $editor); break; default: } } return $result; } /** * Create type. * * @param DatabasePool $dbPool Database instance * @param array $data Type info * * @return EditorDocType * * @since 1.0.0 */ private static function createType(DatabasePool $dbPool, array $data) : EditorDocType { $type = new EditorDocType(); $type->name = $data['name'] ?? ''; $id = EditorDocTypeMapper::create($type); foreach ($data['l11n'] as $l11n) { $l11n = new EditorDocTypeL11n($l11n['title'], $l11n['lang']); $l11n->type = $id; EditorDocTypeL11nMapper::create($l11n); } return $type; } }