AbstractIncrement.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Model\Entity\Increment;
  7. /**
  8. * Properties:
  9. * - prefix
  10. * - pad_length
  11. * - pad_char
  12. * - last_id
  13. *
  14. * @api
  15. * @since 100.0.2
  16. */
  17. abstract class AbstractIncrement extends \Magento\Framework\DataObject implements
  18. \Magento\Eav\Model\Entity\Increment\IncrementInterface
  19. {
  20. /**
  21. * Get pad length
  22. *
  23. * @return int
  24. */
  25. public function getPadLength()
  26. {
  27. $padLength = $this->getData('pad_length');
  28. if (empty($padLength)) {
  29. $padLength = 8;
  30. }
  31. return $padLength;
  32. }
  33. /**
  34. * Get pad char
  35. *
  36. * @return string
  37. */
  38. public function getPadChar()
  39. {
  40. $padChar = $this->getData('pad_char');
  41. if (empty($padChar)) {
  42. $padChar = '0';
  43. }
  44. return $padChar;
  45. }
  46. /**
  47. * Pad format
  48. *
  49. * @param mixed $id
  50. * @return string
  51. */
  52. public function format($id)
  53. {
  54. $result = $this->getPrefix();
  55. $result .= str_pad((string)$id, $this->getPadLength(), $this->getPadChar(), STR_PAD_LEFT);
  56. return $result;
  57. }
  58. /**
  59. * Frontend format
  60. *
  61. * @param mixed $id
  62. * @return mixed
  63. * @codeCoverageIgnore
  64. */
  65. public function frontendFormat($id)
  66. {
  67. return $id;
  68. }
  69. }