BinaryWriter.php 962 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * (c) Jeroen van den Enden <info@endroid.nl>
  5. *
  6. * This source file is subject to the MIT license that is bundled
  7. * with this source code in the file LICENSE.
  8. */
  9. namespace Endroid\QrCode\Writer;
  10. use Endroid\QrCode\QrCodeInterface;
  11. class BinaryWriter extends AbstractWriter
  12. {
  13. public function writeString(QrCodeInterface $qrCode): string
  14. {
  15. $rows = [];
  16. $data = $qrCode->getData();
  17. foreach ($data['matrix'] as $row) {
  18. $values = '';
  19. foreach ($row as $value) {
  20. $values .= $value;
  21. }
  22. $rows[] = $values;
  23. }
  24. return implode("\n", $rows);
  25. }
  26. public static function getContentType(): string
  27. {
  28. return 'text/plain';
  29. }
  30. public static function getSupportedExtensions(): array
  31. {
  32. return ['bin', 'txt'];
  33. }
  34. public function getName(): string
  35. {
  36. return 'binary';
  37. }
  38. }