Handler.php 2.0 KB

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