Nonce.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Model\Oauth;
  7. /**
  8. * Nonce model
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. * @method string getNonce()
  11. * @method \Magento\Integration\Model\Oauth\Nonce setNonce() setNonce(string $nonce)
  12. * @method int getConsumerId()
  13. * @method \Magento\Integration\Model\Oauth\Nonce setConsumerId() setConsumerId(int $consumerId)
  14. * @method string getTimestamp()
  15. * @method \Magento\Integration\Model\Oauth\Nonce setTimestamp() setTimestamp(string $timestamp)
  16. */
  17. class Nonce extends \Magento\Framework\Model\AbstractModel
  18. {
  19. /**
  20. * Oauth data
  21. *
  22. * @var \Magento\Integration\Helper\Oauth\Data
  23. */
  24. protected $_oauthData;
  25. /**
  26. * @param \Magento\Framework\Model\Context $context
  27. * @param \Magento\Framework\Registry $registry
  28. * @param \Magento\Integration\Helper\Oauth\Data $oauthData
  29. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  30. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  31. * @param array $data
  32. */
  33. public function __construct(
  34. \Magento\Framework\Model\Context $context,
  35. \Magento\Framework\Registry $registry,
  36. \Magento\Integration\Helper\Oauth\Data $oauthData,
  37. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  38. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  39. array $data = []
  40. ) {
  41. parent::__construct($context, $registry, $resource, $resourceCollection, $data);
  42. $this->_oauthData = $oauthData;
  43. }
  44. /**
  45. * Initialize resource model
  46. *
  47. * @return void
  48. */
  49. protected function _construct()
  50. {
  51. $this->_init(\Magento\Integration\Model\ResourceModel\Oauth\Nonce::class);
  52. }
  53. /**
  54. * The "After save" actions
  55. *
  56. * @return $this
  57. */
  58. public function afterSave()
  59. {
  60. parent::afterSave();
  61. if ($this->_oauthData->isCleanupProbability()) {
  62. $this->getResource()->deleteOldEntries($this->_oauthData->getCleanupExpirationPeriod());
  63. }
  64. return $this;
  65. }
  66. /**
  67. * Load given a composite key consisting of a nonce string and a consumer id
  68. *
  69. * @param string $nonce - The nonce string
  70. * @param int $consumerId - The consumer id
  71. * @return $this
  72. */
  73. public function loadByCompositeKey($nonce, $consumerId)
  74. {
  75. $data = $this->getResource()->selectByCompositeKey($nonce, $consumerId);
  76. $this->setData($data);
  77. return $this;
  78. }
  79. }