Exemple #1
0
 /**
  * Writes QR code and returns it as string.
  *
  * Content is a string which *should* be encoded in UTF-8, in case there are
  * non ASCII-characters present.
  *
  * @param  string  $content
  * @param  string  $encoding
  * @param  integer $ecLevel
  * @return string
  * @throws Exception\InvalidArgumentException
  */
 public function writeString($content, $encoding = Encoder::DEFAULT_BYTE_MODE_ECODING, $ecLevel = ErrorCorrectionLevel::L)
 {
     if (strlen($content) === 0) {
         throw new Exception\InvalidArgumentException('Found empty contents');
     }
     $qrCode = Encoder::encode($content, new ErrorCorrectionLevel($ecLevel), $encoding);
     return $this->getRenderer()->render($qrCode);
 }
Exemple #2
0
 public function testSetClass()
 {
     $content = 'foobar';
     $qrCode = Encoder::encode($content, new ErrorCorrectionLevel(ErrorCorrectionLevel::L), Encoder::DEFAULT_BYTE_MODE_ECODING);
     $this->renderer->setClass('bar');
     $this->assertEquals('bar', $this->renderer->getClass());
     $this->assertStringMatchesFormat('%aclass="bar"%a', $this->renderer->render($qrCode));
 }
Exemple #3
0
 public function testBasicRenderCustomChar()
 {
     $content = 'foobar';
     $expected = "-----------------------\n" . "-#######-#####-#######-\n" . "-#-----#--#-#--#-----#-\n" . "-#-###-#--##---#-###-#-\n" . "-#-###-#--###--#-###-#-\n" . "-#-###-#---#-#-#-###-#-\n" . "-#-----#----##-#-----#-\n" . "-#######-#-#-#-#######-\n" . "---------#####---------\n" . "-##-##-#--##-#-#-----#-\n" . "----##----##-#-#-##----\n" . "--########-#--##-#--##-\n" . "-----------##------#-#-\n" . "--##--###--#---#--#--#-\n" . "---------#-###----#-#--\n" . "-#######--##-######----\n" . "-#-----#---####---##---\n" . "-#-###-#-##-##-##-#-##-\n" . "-#-###-#-##-##--#-##---\n" . "-#-###-#---#---#-##-##-\n" . "-#-----#-###--###-####-\n" . "-#######-####---##-----\n" . "-----------------------\n";
     $qrCode = Encoder::encode($content, new ErrorCorrectionLevel(ErrorCorrectionLevel::L), Encoder::DEFAULT_BYTE_MODE_ECODING);
     $this->renderer->setFullBlock('#');
     $this->renderer->setEmptyBlock('-');
     $this->assertEquals('#', $this->renderer->getFullBlock());
     $this->assertEquals('-', $this->renderer->getEmptyBlock());
     $this->assertEquals($expected, $this->renderer->render($qrCode));
 }