Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Alphanum.php
Go to the documentation of this file.
1 <?php
17 
18 class Alphanum extends \Magento\Eav\Model\Entity\Increment\AbstractIncrement
19 {
26  public function getAllowedChars()
27  {
28  return '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
29  }
30 
37  public function getNextId()
38  {
39  $lastId = $this->getLastId();
40 
41  if (strpos($lastId, $this->getPrefix()) === 0) {
42  $lastId = substr($lastId, strlen($this->getPrefix()));
43  }
44 
45  $lastId = str_pad((string)$lastId, $this->getPadLength(), $this->getPadChar(), STR_PAD_LEFT);
46 
47  $nextId = '';
48  $bumpNextChar = true;
49  $chars = $this->getAllowedChars();
50  $lchars = strlen($chars);
51  $lid = strlen($lastId) - 1;
52 
53  for ($i = $lid; $i >= 0; $i--) {
54  $p = strpos($chars, $lastId[$i]);
55  if (false === $p) {
56  throw new \Magento\Framework\Exception\LocalizedException(
57  __('Invalid character encountered in increment ID: %1', $lastId)
58  );
59  }
60  if ($bumpNextChar) {
61  $p++;
62  $bumpNextChar = false;
63  }
64  if ($p === $lchars) {
65  $p = 0;
66  $bumpNextChar = true;
67  }
68  $nextId = $chars[$p] . $nextId;
69  }
70 
71  return $this->format($nextId);
72  }
73 }
__()
Definition: __.php:13
$i
Definition: gallery.phtml:31