16d576906SGreg Roach<?php 26d576906SGreg Roach 36d576906SGreg Roach/** 46d576906SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 66d576906SGreg Roach * This program is free software: you can redistribute it and/or modify 76d576906SGreg Roach * it under the terms of the GNU General Public License as published by 86d576906SGreg Roach * the Free Software Foundation, either version 3 of the License, or 96d576906SGreg Roach * (at your option) any later version. 106d576906SGreg Roach * This program is distributed in the hope that it will be useful, 116d576906SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 126d576906SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 136d576906SGreg Roach * GNU General Public License for more details. 146d576906SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 166d576906SGreg Roach */ 176d576906SGreg Roach 186d576906SGreg Roachdeclare(strict_types=1); 196d576906SGreg Roach 206d576906SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 216d576906SGreg Roach 221c6adce8SGreg Roachuse Fisharebest\Webtrees\Encodings\ANSEL; 231c6adce8SGreg Roachuse Fisharebest\Webtrees\Encodings\ASCII; 241c6adce8SGreg Roachuse Fisharebest\Webtrees\Encodings\UTF16BE; 251c6adce8SGreg Roachuse Fisharebest\Webtrees\Encodings\UTF8; 261c6adce8SGreg Roachuse Fisharebest\Webtrees\Encodings\Windows1252; 276d576906SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 2869c05a6eSGreg Roachuse Fisharebest\Webtrees\Services\GedcomExportService; 291c6adce8SGreg Roachuse Fisharebest\Webtrees\Validator; 306d576906SGreg Roachuse Psr\Http\Message\ResponseInterface; 316d576906SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 326d576906SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 336d576906SGreg Roach 346d576906SGreg Roach/** 356d576906SGreg Roach * Download a GEDCOM file to the client. 366d576906SGreg Roach */ 376d576906SGreg Roachclass ExportGedcomClient implements RequestHandlerInterface 386d576906SGreg Roach{ 396d576906SGreg Roach use ViewResponseTrait; 406d576906SGreg Roach 41c4943cffSGreg Roach private GedcomExportService $gedcom_export_service; 4269c05a6eSGreg Roach 4369c05a6eSGreg Roach /** 4469c05a6eSGreg Roach * @param GedcomExportService $gedcom_export_service 4569c05a6eSGreg Roach */ 4616ecfcafSGreg Roach public function __construct(GedcomExportService $gedcom_export_service) 4716ecfcafSGreg Roach { 4869c05a6eSGreg Roach $this->gedcom_export_service = $gedcom_export_service; 4969c05a6eSGreg Roach } 5069c05a6eSGreg Roach 516d576906SGreg Roach /** 526d576906SGreg Roach * @param ServerRequestInterface $request 536d576906SGreg Roach * 546d576906SGreg Roach * @return ResponseInterface 556d576906SGreg Roach */ 566d576906SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 576d576906SGreg Roach { 58b55cbc6bSGreg Roach $tree = Validator::attributes($request)->tree(); 5916ecfcafSGreg Roach $filename = Validator::parsedBody($request)->string('filename'); 6016ecfcafSGreg Roach $format = Validator::parsedBody($request)->isInArray(['gedcom', 'zip', 'zipmedia', 'gedzip'])->string('format'); 61b55cbc6bSGreg Roach $privacy = Validator::parsedBody($request)->isInArray(['none', 'gedadmin', 'user', 'visitor'])->string('privacy'); 62b55cbc6bSGreg Roach $encoding = Validator::parsedBody($request)->isInArray([UTF8::NAME, UTF16BE::NAME, ANSEL::NAME, ASCII::NAME, Windows1252::NAME])->string('encoding'); 63b55cbc6bSGreg Roach $line_endings = Validator::parsedBody($request)->isInArray(['CRLF', 'LF'])->string('line_endings'); 646d576906SGreg Roach 6516ecfcafSGreg Roach return $this->gedcom_export_service->downloadResponse($tree, true, $encoding, $privacy, $line_endings, $filename, $format); 666d576906SGreg Roach } 676d576906SGreg Roach} 68