mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-04 06:32:42 +00:00
QROutputInterface -> QRCode::__construct
This commit is contained in:
+8
-9
@@ -10,22 +10,21 @@ use chillerlan\QRCode\Output\QRStringOptions;
|
||||
|
||||
$starttime = microtime(true);
|
||||
|
||||
$qrOptions = new QROptions;
|
||||
$qrOptions->typeNumber = QRConst::TYPE_05;
|
||||
$qrOptions->errorCorrectLevel = QRConst::ERROR_CORRECT_LEVEL_M;
|
||||
|
||||
$qrStringOptions = new QRStringOptions;
|
||||
$qrStringOptions->type = QRConst::OUTPUT_STRING_TEXT;
|
||||
$qrStringOptions->textDark = '+';
|
||||
$qrStringOptions->textLight = '-';
|
||||
|
||||
$qrOptions = new QROptions;
|
||||
$qrOptions->typeNumber = QRConst::TYPE_05;
|
||||
$qrOptions->errorCorrectLevel = QRConst::ERROR_CORRECT_LEVEL_M;
|
||||
$qrOptions->output = new QRString($qrStringOptions);
|
||||
|
||||
// google authenticator
|
||||
// https://chart.googleapis.com/chart?chs=200x200&chld=M%7C0&cht=qr&chl=otpauth%3A%2F%2Ftotp%2Ftest%3Fsecret%3DB3JX4VCVJDVNXNZ5%26issuer%3Dchillerlan.net
|
||||
$qrcode = new QRCode('otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=buildwars.net', $qrOptions);
|
||||
var_dump($qrcode->getRawData());
|
||||
|
||||
$qrcode->setData('otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', $qrOptions);
|
||||
$qrcode = new QRCode('otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net', new QRString($qrStringOptions), $qrOptions);
|
||||
var_dump($qrcode->output());
|
||||
|
||||
$qrcode->setData('otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=buildwars.net', $qrOptions);
|
||||
var_dump($qrcode->getRawData());
|
||||
|
||||
echo 'QRCode: '.round((microtime(true)-$starttime), 5).PHP_EOL;
|
||||
|
||||
+10
-11
@@ -57,13 +57,18 @@ class QRCode{
|
||||
/**
|
||||
* QRCode constructor.
|
||||
*
|
||||
* @param string $data
|
||||
* @param \chillerlan\QRCode\QROptions $options
|
||||
*
|
||||
* @throws \chillerlan\QRCode\QRCodeException
|
||||
* @param string $data
|
||||
* @param \chillerlan\QRCode\Output\QROutputInterface $output
|
||||
* @param \chillerlan\QRCode\QROptions $options
|
||||
*/
|
||||
public function __construct($data, QROptions $options){
|
||||
public function __construct($data, QROutputInterface $output, QROptions $options = null){
|
||||
$this->qrOutputInterface = $output;
|
||||
$this->bitBuffer = new BitBuffer;
|
||||
|
||||
if(!$options instanceof QROptions){
|
||||
$options = new QROptions;
|
||||
}
|
||||
|
||||
$this->setData($data, $options);
|
||||
}
|
||||
|
||||
@@ -85,12 +90,6 @@ 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\\'.[
|
||||
|
||||
@@ -17,13 +17,6 @@ namespace chillerlan\QRCode;
|
||||
*/
|
||||
class QROptions{
|
||||
|
||||
/**
|
||||
* mandatory
|
||||
*
|
||||
* @var \chillerlan\QRCode\Output\QROutputInterface
|
||||
*/
|
||||
public $output = null ;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user