protected function isLengthCorrect(&$im)
 {
     $c = strlen($this->text);
     // If we have 13 chars just flush the last one
     if ($c === 13) {
         $this->text = substr($this->text, 0, 12);
         return true;
     } elseif ($c === 12) {
         return true;
     } elseif ($c === 9 || $c === 10) {
         if ($c === 10) {
             // Before dropping it, we check if it's legal
             if (array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') {
                 return false;
             }
             $this->text = substr($this->text, 0, 9);
         }
         if ($this->gs1 === self::GS1_AUTO || $this->gs1 === self::GS1_PREFIX978) {
             $this->text = '978' . $this->text;
         } elseif ($this->gs1 === self::GS1_PREFIX979) {
             $this->text = '979' . $this->text;
         }
         // We changed the start, recalculate the offset label
         parent::setLabelOffset();
         return true;
     } else {
         if ($im !== null) {
             $this->drawError($im, 'Must provide 9, 10, 12 or 13 digits.');
         }
         return false;
     }
 }
Beispiel #2
0
 /**
  * Check correct length.
  */
 protected function checkCorrectLength()
 {
     $c = strlen($this->text);
     // If we have 13 chars just flush the last one
     if ($c === 13) {
         $this->text = substr($this->text, 0, 12);
     } elseif ($c === 9 || $c === 10) {
         if ($c === 10) {
             // Before dropping it, we check if it's legal
             if (array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') {
                 throw new BCGParseException('isbn', 'The character \'' . $this->text[9] . '\' is not allowed.');
             }
             $this->text = substr($this->text, 0, 9);
         }
         if ($this->gs1 === self::GS1_AUTO || $this->gs1 === self::GS1_PREFIX978) {
             $this->text = '978' . $this->text;
         } elseif ($this->gs1 === self::GS1_PREFIX979) {
             $this->text = '979' . $this->text;
         }
         // We changed the start, recalculate the offset label
         parent::setLabelOffset();
     } elseif ($c !== 12) {
         throw new BCGParseException('isbn', 'The code parsed must be 9, 10, 12, or 13 digits long.');
     }
 }