Provider.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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_NoSpam
  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\Config\Source;
  21. use Magento\Framework\Option\ArrayInterface;
  22. use MSP\TwoFactorAuth\Api\TfaInterface;
  23. class Provider implements ArrayInterface
  24. {
  25. /**
  26. * @var TfaInterface
  27. */
  28. private $tfa;
  29. public function __construct(
  30. TfaInterface $tfa
  31. ) {
  32. $this->tfa = $tfa;
  33. }
  34. /**
  35. * Options getter
  36. *
  37. * @return array
  38. */
  39. public function toOptionArray()
  40. {
  41. $providers = $this->tfa->getAllProviders();
  42. $res = [];
  43. foreach ($providers as $provider) {
  44. $res[] = [
  45. 'value' => $provider->getCode(),
  46. 'label' => $provider->getName(),
  47. ];
  48. }
  49. return $res;
  50. }
  51. /**
  52. * Get options in "key-value" format
  53. *
  54. * @return array
  55. */
  56. public function toArray()
  57. {
  58. $options = $this->toOptionArray();
  59. $return = [];
  60. foreach ($options as $option) {
  61. $return[$option['value']] = $option['label'];
  62. }
  63. return $return;
  64. }
  65. }