AbstractWriter.php
3 years ago
BinaryWriter.php
3 years ago
DebugWriter.php
3 years ago
EpsWriter.php
3 years ago
FpdfWriter.php
3 years ago
PngWriter.php
3 years ago
SvgWriter.php
3 years ago
WriterInterface.php
3 years ago
DebugWriter.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | /* |
| 5 | * (c) Jeroen van den Enden <info@endroid.nl> |
| 6 | * |
| 7 | * This source file is subject to the MIT license that is bundled |
| 8 | * with this source code in the file LICENSE. |
| 9 | */ |
| 10 | namespace WP2FA_Vendor\Endroid\QrCode\Writer; |
| 11 | |
| 12 | use WP2FA_Vendor\Endroid\QrCode\QrCodeInterface; |
| 13 | use Exception; |
| 14 | use ReflectionClass; |
| 15 | class DebugWriter extends AbstractWriter |
| 16 | { |
| 17 | public function writeString(QrCodeInterface $qrCode) : string |
| 18 | { |
| 19 | $data = []; |
| 20 | $skip = ['getData']; |
| 21 | $reflectionClass = new ReflectionClass($qrCode); |
| 22 | foreach ($reflectionClass->getMethods() as $method) { |
| 23 | $methodName = $method->getShortName(); |
| 24 | if (0 === \strpos($methodName, 'get') && 0 == $method->getNumberOfParameters() && !\in_array($methodName, $skip)) { |
| 25 | $value = $qrCode->{$methodName}(); |
| 26 | if (\is_array($value) && !\is_object(\current($value))) { |
| 27 | $value = '[' . \implode(', ', $value) . ']'; |
| 28 | } elseif (\is_bool($value)) { |
| 29 | $value = $value ? 'true' : 'false'; |
| 30 | } elseif (\is_string($value)) { |
| 31 | $value = '"' . $value . '"'; |
| 32 | } elseif (\is_null($value)) { |
| 33 | $value = 'null'; |
| 34 | } |
| 35 | try { |
| 36 | $data[] = $methodName . ': ' . $value; |
| 37 | } catch (Exception $exception) { |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | $string = \implode(" \n", $data); |
| 42 | return $string; |
| 43 | } |
| 44 | public static function getContentType() : string |
| 45 | { |
| 46 | return 'text/plain'; |
| 47 | } |
| 48 | public function getName() : string |
| 49 | { |
| 50 | return 'debug'; |
| 51 | } |
| 52 | } |
| 53 |