xref: /webtrees/app/Http/RequestHandlers/EmptyClipboard.php (revision 9927f70f86c91b9b1fe6c77b5647841190d87ca9)
1*9927f70fSGreg Roach<?php
2*9927f70fSGreg Roach
3*9927f70fSGreg Roach/**
4*9927f70fSGreg Roach * webtrees: online genealogy
5*9927f70fSGreg Roach * Copyright (C) 2021 webtrees development team
6*9927f70fSGreg Roach * This program is free software: you can redistribute it and/or modify
7*9927f70fSGreg Roach * it under the terms of the GNU General Public License as published by
8*9927f70fSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9*9927f70fSGreg Roach * (at your option) any later version.
10*9927f70fSGreg Roach * This program is distributed in the hope that it will be useful,
11*9927f70fSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*9927f70fSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*9927f70fSGreg Roach * GNU General Public License for more details.
14*9927f70fSGreg Roach * You should have received a copy of the GNU General Public License
15*9927f70fSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16*9927f70fSGreg Roach */
17*9927f70fSGreg Roach
18*9927f70fSGreg Roachdeclare(strict_types=1);
19*9927f70fSGreg Roach
20*9927f70fSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
21*9927f70fSGreg Roach
22*9927f70fSGreg Roachuse Fisharebest\Webtrees\Auth;
23*9927f70fSGreg Roachuse Fisharebest\Webtrees\Registry;
24*9927f70fSGreg Roachuse Fisharebest\Webtrees\Services\ClipboardService;
25*9927f70fSGreg Roachuse Fisharebest\Webtrees\Tree;
26*9927f70fSGreg Roachuse Psr\Http\Message\ResponseInterface;
27*9927f70fSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
28*9927f70fSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
29*9927f70fSGreg Roach
30*9927f70fSGreg Roachuse function assert;
31*9927f70fSGreg Roachuse function is_string;
32*9927f70fSGreg Roachuse function redirect;
33*9927f70fSGreg Roach
34*9927f70fSGreg Roach/**
35*9927f70fSGreg Roach * Empty the clipboard.
36*9927f70fSGreg Roach */
37*9927f70fSGreg Roachclass EmptyClipboard implements RequestHandlerInterface
38*9927f70fSGreg Roach{
39*9927f70fSGreg Roach    private ClipboardService $clipboard_service;
40*9927f70fSGreg Roach
41*9927f70fSGreg Roach    /**
42*9927f70fSGreg Roach     * PasteFact constructor.
43*9927f70fSGreg Roach     *
44*9927f70fSGreg Roach     * @param ClipboardService $clipboard_service
45*9927f70fSGreg Roach     */
46*9927f70fSGreg Roach    public function __construct(ClipboardService $clipboard_service)
47*9927f70fSGreg Roach    {
48*9927f70fSGreg Roach        $this->clipboard_service = $clipboard_service;
49*9927f70fSGreg Roach    }
50*9927f70fSGreg Roach
51*9927f70fSGreg Roach    /**
52*9927f70fSGreg Roach     * Paste a fact from the clipboard into a record.
53*9927f70fSGreg Roach     *
54*9927f70fSGreg Roach     * @param ServerRequestInterface $request
55*9927f70fSGreg Roach     *
56*9927f70fSGreg Roach     * @return ResponseInterface
57*9927f70fSGreg Roach     */
58*9927f70fSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
59*9927f70fSGreg Roach    {
60*9927f70fSGreg Roach        $params = (array) $request->getParsedBody();
61*9927f70fSGreg Roach
62*9927f70fSGreg Roach        $url = $params['url'] ?? $request->getHeaderLine('Referer');
63*9927f70fSGreg Roach
64*9927f70fSGreg Roach        $this->clipboard_service->emptyClipboard();
65*9927f70fSGreg Roach
66*9927f70fSGreg Roach        return redirect($url);
67*9927f70fSGreg Roach    }
68*9927f70fSGreg Roach}
69