CollectionFactory.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Security\Model\ResourceModel\PasswordResetRequestEvent;
  7. use Magento\Security\Model\Config\Source\ResetMethod;
  8. use Magento\Security\Model\ConfigInterface;
  9. /**
  10. * Factory class for @see \Magento\Security\Model\ResourceModel\PasswordResetRequestEvent\Collection
  11. *
  12. * @api
  13. * @since 100.1.0
  14. */
  15. class CollectionFactory
  16. {
  17. /**
  18. * Object Manager instance
  19. *
  20. * @var \Magento\Framework\ObjectManagerInterface
  21. * @since 100.1.0
  22. */
  23. protected $objectManager = null;
  24. /**
  25. * Instance name to create
  26. *
  27. * @var string
  28. * @since 100.1.0
  29. */
  30. protected $instanceName = null;
  31. /**
  32. * @var ConfigInterface
  33. * @since 100.1.0
  34. */
  35. protected $securityConfig;
  36. /**
  37. * CollectionFactory constructor.
  38. *
  39. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  40. * @param ConfigInterface $securityConfig
  41. * @param string $instanceName
  42. */
  43. public function __construct(
  44. \Magento\Framework\ObjectManagerInterface $objectManager,
  45. ConfigInterface $securityConfig,
  46. $instanceName = Collection::class
  47. ) {
  48. $this->objectManager = $objectManager;
  49. $this->securityConfig = $securityConfig;
  50. $this->instanceName = $instanceName;
  51. }
  52. /**
  53. * Create class instance with specified parameters
  54. *
  55. * @param int $securityEventType
  56. * @param string $accountReference
  57. * @param string $longIp
  58. * @return Collection
  59. * @since 100.1.0
  60. */
  61. public function create(
  62. $securityEventType = null,
  63. $accountReference = null,
  64. $longIp = null
  65. ) {
  66. /** @var Collection $collection */
  67. $collection = $this->objectManager->create($this->instanceName);
  68. if (null !== $securityEventType) {
  69. $collection->filterByRequestType($securityEventType);
  70. switch ($this->securityConfig->getPasswordResetProtectionType()) {
  71. case ResetMethod::OPTION_BY_EMAIL:
  72. $collection->filterByAccountReference($accountReference);
  73. break;
  74. case ResetMethod::OPTION_BY_IP:
  75. $collection->filterByIp($longIp);
  76. break;
  77. case ResetMethod::OPTION_BY_IP_AND_EMAIL:
  78. $collection->filterByIpOrAccountReference($longIp, $accountReference);
  79. break;
  80. default:
  81. }
  82. }
  83. return $collection;
  84. }
  85. }