1
0

Handler.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @file
  4. * TeamSpeak 3 PHP Framework
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @package TeamSpeak3
  20. * @author Sven 'ScP' Paulsen
  21. * @copyright Copyright (c) Planet TeamSpeak. All rights reserved.
  22. */
  23. /**
  24. * @class TeamSpeak3_Helper_Signal_Handler
  25. * @brief Helper class providing handler functions for signals.
  26. */
  27. class TeamSpeak3_Helper_Signal_Handler
  28. {
  29. /**
  30. * Stores the name of the subscribed signal.
  31. *
  32. * @var string
  33. */
  34. protected $signal = null;
  35. /**
  36. * Stores the callback function for the subscribed signal.
  37. *
  38. * @var mixed
  39. */
  40. protected $callback = null;
  41. /**
  42. * The TeamSpeak3_Helper_Signal_Handler constructor.
  43. *
  44. * @param string $signal
  45. * @param mixed $callback
  46. * @throws TeamSpeak3_Helper_Signal_Exception
  47. * @return TeamSpeak3_Helper_Signal_Handler
  48. */
  49. public function __construct($signal, $callback)
  50. {
  51. $this->signal = (string) $signal;
  52. if(!is_callable($callback))
  53. {
  54. throw new TeamSpeak3_Helper_Signal_Exception("invalid callback specified for signal '" . $signal . "'");
  55. }
  56. $this->callback = $callback;
  57. }
  58. /**
  59. * Invoke the signal handler.
  60. *
  61. * @param array $args
  62. * @return mixed
  63. */
  64. public function call(array $args = array())
  65. {
  66. return call_user_func_array($this->callback, $args);
  67. }
  68. }