mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-11-05 10:35:23 +00:00
refactoring
This commit is contained in:
+54
-43
@@ -17,7 +17,7 @@ use chillerlan\QRCode\QRCode;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class QRString extends QROutputBase implements QROutputInterface{
|
||||
class QRString extends QROutputAbstract{
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\Output\QRStringOptions
|
||||
@@ -46,50 +46,61 @@ class QRString extends QROutputBase implements QROutputInterface{
|
||||
*/
|
||||
public function dump(){
|
||||
|
||||
if($this->options->type === QRCode::OUTPUT_STRING_JSON){
|
||||
return json_encode($this->matrix);
|
||||
}
|
||||
|
||||
else if($this->options->type === QRCode::OUTPUT_STRING_TEXT){
|
||||
$text = '';
|
||||
|
||||
foreach($this->matrix as $row){
|
||||
foreach($row as $col){
|
||||
$text .= $col
|
||||
? $this->options->textDark
|
||||
: $this->options->textLight;
|
||||
}
|
||||
|
||||
$text .= $this->options->textNewline;
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
else if($this->options->type === QRCode::OUTPUT_STRING_HTML){
|
||||
$html = '';
|
||||
|
||||
foreach($this->matrix as $row){
|
||||
// in order to not bloat the output too much, we use the shortest possible valid HTML tags
|
||||
$html .= '<'.$this->options->htmlRowTag.'>';
|
||||
foreach($row as $col){
|
||||
$tag = $col
|
||||
? 'b' // dark
|
||||
: 'i'; // light
|
||||
|
||||
$html .= '<'.$tag.'></'.$tag.'>';
|
||||
}
|
||||
|
||||
if(!(bool)$this->options->htmlOmitEndTag){
|
||||
$html .= '</'.$this->options->htmlRowTag.'>';
|
||||
}
|
||||
|
||||
$html .= PHP_EOL;
|
||||
}
|
||||
|
||||
return $html;
|
||||
switch($this->options->type){
|
||||
case QRCode::OUTPUT_STRING_JSON: return json_encode($this->matrix);
|
||||
case QRCode::OUTPUT_STRING_TEXT: return $this->toString();
|
||||
case QRCode::OUTPUT_STRING_HTML:
|
||||
default:
|
||||
return $this->toHTML();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function toString(){
|
||||
$str = '';
|
||||
|
||||
foreach($this->matrix as $row){
|
||||
foreach($row as $col){
|
||||
$str .= $col
|
||||
? $this->options->textDark
|
||||
: $this->options->textLight;
|
||||
}
|
||||
|
||||
$str .= $this->options->textNewline;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function toHTML(){
|
||||
$html = '';
|
||||
|
||||
foreach($this->matrix as $row){
|
||||
// in order to not bloat the output too much, we use the shortest possible valid HTML tags
|
||||
$html .= '<'.$this->options->htmlRowTag.'>';
|
||||
|
||||
foreach($row as $col){
|
||||
$tag = $col
|
||||
? 'b' // dark
|
||||
: 'i'; // light
|
||||
|
||||
$html .= '<'.$tag.'></'.$tag.'>';
|
||||
}
|
||||
|
||||
if(!(bool)$this->options->htmlOmitEndTag){
|
||||
$html .= '</'.$this->options->htmlRowTag.'>';
|
||||
}
|
||||
|
||||
$html .= PHP_EOL;
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user