Explorar o código

QROutputInterface -> QRCode::__construct

smiley %!s(int64=10) %!d(string=hai) anos
pai
achega
3327c53ec6
Modificáronse 3 ficheiros con 18 adicións e 27 borrados
  1. 8 9
      examples/custom.php
  2. 10 11
      src/QRCode.php
  3. 0 7
      src/QROptions.php

+ 8 - 9
examples/custom.php

@@ -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
src/QRCode.php

@@ -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\\'.[

+ 0 - 7
src/QROptions.php

@@ -17,13 +17,6 @@ namespace chillerlan\QRCode;
  */
 class QROptions{
 
-	/**
-	 * mandatory
-	 *
-	 * @var \chillerlan\QRCode\Output\QROutputInterface
-	 */
-	public $output = null ;
-
 	/**
 	 * @var int
 	 */