. // }}} /** * Wrapper around Symfony's Security service, for static access * * @package GNUsocial * @category Security * * @author Hugo Sales * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace App\Core; use HtmlSanitizer\SanitizerInterface; use Symfony\Component\Security\Core\Security as SymfonySecurity; /** * Forwards method calls to either Symfony\Component\Security\Core\Security or * HtmlSanitizer\SanitizerInterface, calling the first existing method, in that order * * @codeCoverageIgnore * @mixin SymfonySecurity * @mixin SanitizerInterface */ abstract class Security { private static ?SymfonySecurity $security; private static ?SanitizerInterface $sanitizer; public static function setHelper($sec, $san): void { self::$security = $sec; self::$sanitizer = $san; } public static function __callStatic(string $name, array $args) { if (method_exists(self::$security, $name)) { return self::$security->{$name}(...$args); } else { if (method_exists(self::$sanitizer, $name)) { return self::$sanitizer->{$name}(...$args); } else { throw new \BadMethodCallException("Method Security::{$name} doesn't exist"); } } } }