Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | n/a |
0 / 0 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
|||
| Security | n/a |
0 / 0 |
n/a |
0 / 0 |
4 | n/a |
0 / 0 |
|||
| setHelper | n/a |
0 / 0 |
1 | n/a |
0 / 0 |
|||||
| __callStatic | n/a |
0 / 0 |
3 | n/a |
0 / 0 |
|||||
| 1 | <?php |
| 2 | |
| 3 | // {{{ License |
| 4 | // This file is part of GNU social - https://www.gnu.org/software/social |
| 5 | // |
| 6 | // GNU social is free software: you can redistribute it and/or modify |
| 7 | // it under the terms of the GNU Affero General Public License as published by |
| 8 | // the Free Software Foundation, either version 3 of the License, or |
| 9 | // (at your option) any later version. |
| 10 | // |
| 11 | // GNU social is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU Affero General Public License for more details. |
| 15 | // |
| 16 | // You should have received a copy of the GNU Affero General Public License |
| 17 | // along with GNU social. If not, see <http://www.gnu.org/licenses/>. |
| 18 | // }}} |
| 19 | |
| 20 | /** |
| 21 | * Wrapper around Symfony's Security service, for static access |
| 22 | * |
| 23 | * @package GNUsocial |
| 24 | * @category Security |
| 25 | * |
| 26 | * @author Hugo Sales <hugo@hsal.es> |
| 27 | * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org |
| 28 | * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later |
| 29 | */ |
| 30 | |
| 31 | namespace App\Core; |
| 32 | |
| 33 | use HtmlSanitizer\SanitizerInterface; |
| 34 | use Symfony\Component\Security\Core\Security as SSecurity; |
| 35 | |
| 36 | /** |
| 37 | * Forwards method calls to either Symfony\Component\Security\Core\Security or |
| 38 | * HtmlSanitizer\SanitizerInterface, calling the first existing method, in that order |
| 39 | * |
| 40 | * @codeCoverageIgnore |
| 41 | */ |
| 42 | abstract class Security |
| 43 | { |
| 44 | private static ?SSecurity $security; |
| 45 | private static ?SanitizerInterface $sanitizer; |
| 46 | |
| 47 | public static function setHelper($sec, $san): void |
| 48 | { |
| 49 | self::$security = $sec; |
| 50 | self::$sanitizer = $san; |
| 51 | } |
| 52 | |
| 53 | public static function __callStatic(string $name, array $args) |
| 54 | { |
| 55 | if (method_exists(self::$security, $name)) { |
| 56 | return self::$security->{$name}(...$args); |
| 57 | } else { |
| 58 | if (method_exists(self::$sanitizer, $name)) { |
| 59 | return self::$sanitizer->{$name}(...$args); |
| 60 | } else { |
| 61 | throw new \BadMethodCallException("Method Security::{$name} doesn't exist"); |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |