Generator.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /*
  3. * The RandomLib library for securely generating random numbers and strings in PHP
  4. *
  5. * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
  6. * @copyright 2011 The Authors
  7. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  8. * @version Build @@version@@
  9. */
  10. /**
  11. * The Mixer strategy interface.
  12. *
  13. * All mixing strategies must implement this interface
  14. *
  15. * PHP version 5.3
  16. *
  17. * @category PHPPasswordLib
  18. * @package Random
  19. *
  20. * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
  21. * @copyright 2011 The Authors
  22. * @license http://opensource.org/licenses/bsd-license.php New BSD License
  23. * @license http://www.gnu.org/licenses/lgpl-2.1.html LGPL v 2.1
  24. */
  25. namespace RandomLibtest\Mocks\Random;
  26. /**
  27. * The Mixer strategy interface.
  28. *
  29. * All mixing strategies must implement this interface
  30. *
  31. * @category PHPPasswordLib
  32. * @package Random
  33. *
  34. * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
  35. */
  36. class Generator extends \RandomLib\Generator
  37. {
  38. protected $callbacks = array();
  39. public static function init()
  40. {
  41. }
  42. public function __construct(array $callbacks = array())
  43. {
  44. $this->callbacks = $callbacks;
  45. }
  46. public function __call($name, array $args = array())
  47. {
  48. if (isset($this->callbacks[$name])) {
  49. return call_user_func_array($this->callbacks[$name], $args);
  50. }
  51. return null;
  52. }
  53. public function addSource(\PasswordLib\Random\Source $source)
  54. {
  55. return $this->__call('addSource', array($source));
  56. }
  57. public function generate($size)
  58. {
  59. return $this->__call('generate', array($size));
  60. }
  61. public function generateInt($min = 0, $max = \PHP_INT_MAX)
  62. {
  63. return $this->__call('generateInt', array($min, $max));
  64. }
  65. public function generateString($length, $chars = '')
  66. {
  67. return $this->__call('generateString', array($length, $chars));
  68. }
  69. }