docodeit /
wechat
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the docodeit/wechat. |
||
| 5 | * |
||
| 6 | * (c) docodeit <[email protected]> |
||
| 7 | * |
||
| 8 | * This source file is subject to the MIT license that is bundled |
||
| 9 | * with this source code in the file LICENSE. |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace JinWeChat\Kernel\Console; |
||
| 13 | |||
| 14 | use PHPQRCode\QRcode as QrCodeConsole; |
||
| 15 | use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
||
| 16 | use Symfony\Component\Console\Output\ConsoleOutput; |
||
| 17 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 18 | |||
| 19 | class QrCode extends Console |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * show qrCode on console. |
||
| 23 | * |
||
| 24 | * @param $text |
||
| 25 | */ |
||
| 26 | 1 | public function show($text) |
|
| 27 | { |
||
| 28 | 1 | $output = new ConsoleOutput(); |
|
| 29 | 1 | static::initQrcodeStyle($output); |
|
| 30 | |||
| 31 | 1 | $pxMap[0] = Console::isWin() ? '<whitec>mm</whitec>' : '<whitec> </whitec>'; |
|
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 32 | // $pxMap[0] = true ? '<whitec>mm</whitec>' : '<whitec> </whitec>'; |
||
| 33 | 1 | $pxMap[1] = '<blackc> </blackc>'; |
|
| 34 | |||
| 35 | 1 | $text = QrCodeConsole::text($text); |
|
| 36 | |||
| 37 | 1 | $length = strlen($text[0]); |
|
| 38 | |||
| 39 | 1 | $output->write("\n"); |
|
| 40 | 1 | foreach ($text as $line) { |
|
| 41 | 1 | $output->write($pxMap[0]); |
|
| 42 | 1 | for ($i = 0; $i < $length; ++$i) { |
|
| 43 | 1 | $type = substr($line, $i, 1); |
|
| 44 | 1 | $output->write($pxMap[$type]); |
|
| 45 | } |
||
| 46 | 1 | $output->writeln($pxMap[0]); |
|
| 47 | } |
||
| 48 | 1 | } |
|
| 49 | |||
| 50 | /** |
||
| 51 | * init qrCode style. |
||
| 52 | * |
||
| 53 | * @param OutputInterface $output |
||
| 54 | */ |
||
| 55 | 1 | private static function initQrcodeStyle(OutputInterface $output) |
|
| 56 | { |
||
| 57 | 1 | $style = new OutputFormatterStyle('black', 'black', ['bold']); |
|
| 58 | 1 | $output->getFormatter()->setStyle('blackc', $style); |
|
| 59 | 1 | $style = new OutputFormatterStyle('white', 'white', ['bold']); |
|
| 60 | 1 | $output->getFormatter()->setStyle('whitec', $style); |
|
| 61 | 1 | } |
|
| 62 | } |
||
| 63 |