ProviderPool.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * MageSpecialist
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to info@magespecialist.it so we can send you a copy immediately.
  14. *
  15. * @category MSP
  16. * @package MSP_TwoFactorAuth
  17. * @copyright Copyright (c) 2017 Skeeller srl (http://www.magespecialist.it)
  18. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  19. */
  20. namespace MSP\TwoFactorAuth\Model;
  21. use Magento\Framework\Exception\NoSuchEntityException;
  22. use MSP\TwoFactorAuth\Api\ProviderPoolInterface;
  23. class ProviderPool implements ProviderPoolInterface
  24. {
  25. /**
  26. * @var \MSP\TwoFactorAuth\Api\ProviderInterface[]
  27. */
  28. private $providers = [];
  29. public function __construct(
  30. $providers = []
  31. ) {
  32. $this->providers = $providers;
  33. }
  34. /**
  35. * Get a list of providers
  36. * @return \MSP\TwoFactorAuth\Api\ProviderInterface[]
  37. */
  38. public function getProviders()
  39. {
  40. return $this->providers;
  41. }
  42. /**
  43. * Get provider by code
  44. * @param string $code
  45. * @return \MSP\TwoFactorAuth\Api\ProviderInterface
  46. * @throws \Magento\Framework\Exception\NoSuchEntityException
  47. */
  48. public function getProviderByCode($code)
  49. {
  50. if ($code) {
  51. $providers = $this->getProviders();
  52. if (isset($providers[$code])) {
  53. return $providers[$code];
  54. }
  55. }
  56. throw new NoSuchEntityException(__('Unknown provider %1', $code));
  57. }
  58. }