:octocat: simplified output mode selection

This commit is contained in:
codemasher
2018-01-21 14:50:27 +01:00
parent de1890855d
commit 79af50a6fa
4 changed files with 32 additions and 23 deletions
+6 -10
View File
@@ -23,17 +23,9 @@ class QRString extends QROutputAbstract{
* @return string
*/
public function dump():string{
$data = $this->options->outputType === QRCode::OUTPUT_STRING_JSON
? json_encode($this->matrix->matrix())
: $this->toString();
$data = call_user_func([$this, $this->outputMode ?? QRCode::OUTPUT_STRING_TEXT]);
if($this->options->cachefile !== null){
if(!is_writable(dirname($this->options->cachefile))){
throw new QRCodeOutputException('Could not write data to cache file: '.$this->options->cachefile);
}
$this->saveToFile($data);
}
@@ -43,7 +35,7 @@ class QRString extends QROutputAbstract{
/**
* @return string
*/
protected function toString():string{
protected function text():string{
$str = [];
foreach($this->matrix->matrix() as $row){
@@ -68,4 +60,8 @@ class QRString extends QROutputAbstract{
return implode($this->options->eol, $str);
}
protected function json(){
return json_encode($this->matrix->matrix());
}
}