mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-17 16:22:44 +00:00
added QROutput*
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Class QROutputBase
|
||||
*
|
||||
* @filesource QROutputBase.php
|
||||
* @created 09.12.2015
|
||||
* @package chillerlan\QRCode\Output
|
||||
* @author Smiley <smiley@chillerlan.net>
|
||||
* @copyright 2015 Smiley
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
namespace chillerlan\QRCode\Output;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class QROutputBase{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $matrix;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $pixelCount;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @param array $matrix
|
||||
*
|
||||
* @return $this
|
||||
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
|
||||
*/
|
||||
public function setMatrix(array $matrix){
|
||||
$this->pixelCount = count($matrix);
|
||||
|
||||
// todo: specify valid range
|
||||
if($this->pixelCount < 2
|
||||
|| !isset($matrix[$this->pixelCount - 1])
|
||||
|| $this->pixelCount !== count($matrix[$this->pixelCount - 1])
|
||||
){
|
||||
throw new QRCodeOutputException('Invalid matrix!');
|
||||
}
|
||||
|
||||
$this->matrix = $matrix;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,17 +4,31 @@
|
||||
*
|
||||
* @filesource QROutputInterface.php
|
||||
* @created 02.12.2015
|
||||
* @package codemasher\QRCode\Output
|
||||
* @package chillerlan\QRCode\Output
|
||||
* @author Smiley <smiley@chillerlan.net>
|
||||
* @copyright 2015 Smiley
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
namespace codemasher\QRCode\Output;
|
||||
namespace chillerlan\QRCode\Output;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
interface QROutputInterface{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
|
||||
*/
|
||||
public function dump();
|
||||
|
||||
/**
|
||||
* @param array $matrix
|
||||
*
|
||||
* @return $this
|
||||
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
|
||||
*/
|
||||
public function setMatrix(array $matrix);
|
||||
|
||||
}
|
||||
|
||||
+36
-23
@@ -12,20 +12,22 @@
|
||||
|
||||
namespace chillerlan\QRCode;
|
||||
|
||||
use chillerlan\QRCode\Output\QROutputInterface;
|
||||
|
||||
/**
|
||||
* @link https://github.com/kazuhikoarase/qrcode-generator/tree/master/php
|
||||
*/
|
||||
class QRCode{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $pixelCount = 0;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $matrix = [];
|
||||
protected $matrix = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $pixelCount = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
@@ -37,15 +39,20 @@ class QRCode{
|
||||
*/
|
||||
protected $errorCorrectLevel;
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\BitBuffer
|
||||
*/
|
||||
protected $bitBuffer;
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\Data\QRDataInterface
|
||||
*/
|
||||
protected $qrDataInterface;
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\BitBuffer
|
||||
* @var \chillerlan\QRCode\Output\QROutputInterface
|
||||
*/
|
||||
protected $bitBuffer;
|
||||
protected $qrOutputInterface;
|
||||
|
||||
/**
|
||||
* QRCode constructor.
|
||||
@@ -55,28 +62,19 @@ class QRCode{
|
||||
*
|
||||
* @throws \chillerlan\QRCode\QRCodeException
|
||||
*/
|
||||
public function __construct($data = null, QROptions $options = null){
|
||||
public function __construct($data, QROptions $options){
|
||||
$this->bitBuffer = new BitBuffer;
|
||||
|
||||
if($data){
|
||||
|
||||
if(!$options instanceof QROptions){
|
||||
$options = new QROptions;
|
||||
}
|
||||
|
||||
$this->setOptions($options, $data);
|
||||
}
|
||||
|
||||
$this->setData($data, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \chillerlan\QRCode\QROptions $options
|
||||
* @param string $data
|
||||
* @param \chillerlan\QRCode\QROptions $options
|
||||
*
|
||||
* @return $this
|
||||
* @throws \chillerlan\QRCode\QRCodeException
|
||||
*/
|
||||
public function setOptions(QROptions $options, $data){
|
||||
public function setData($data, QROptions $options){
|
||||
$data = trim($data);
|
||||
|
||||
if(empty($data)){
|
||||
@@ -87,6 +85,12 @@ class QRCode{
|
||||
throw new QRCodeException('Invalid error correct level: '.$options->errorCorrectLevel);
|
||||
}
|
||||
|
||||
if(!$options->output instanceof QROutputInterface){
|
||||
throw new QRCodeException('$options->output is no instance of QROutputInterface');
|
||||
}
|
||||
|
||||
$this->qrOutputInterface = $options->output;
|
||||
|
||||
$mode = Util::getMode($data);
|
||||
|
||||
$qrDataInterface = __NAMESPACE__.'\\Data\\'.[
|
||||
@@ -116,11 +120,20 @@ class QRCode{
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
* @return mixed
|
||||
*/
|
||||
public function output(){
|
||||
$this->qrOutputInterface->setMatrix($this->getRawData());
|
||||
return $this->qrOutputInterface->dump();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRawData(){
|
||||
$minLostPoint = 0;
|
||||
@@ -239,7 +252,7 @@ class QRCode{
|
||||
|
||||
$this->getMatrix(false, $pattern);
|
||||
|
||||
return $this;
|
||||
return $this->matrix;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+7
-10
@@ -17,6 +17,13 @@ namespace chillerlan\QRCode;
|
||||
*/
|
||||
class QROptions{
|
||||
|
||||
/**
|
||||
* mandatory
|
||||
*
|
||||
* @var \chillerlan\QRCode\Output\QROutputInterface
|
||||
*/
|
||||
public $output = null ;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
@@ -27,14 +34,4 @@ class QROptions{
|
||||
*/
|
||||
public $typeNumber = null;
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\Output\QROutputInterface
|
||||
*/
|
||||
public $output = null ;
|
||||
|
||||
/**
|
||||
* @var \chillerlan\QRCode\Output\QROutputOptionsInterface
|
||||
*/
|
||||
public $outputOptions = null;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user