/libraries/joomla/log/logger/callback.php

https://bitbucket.org/eternaware/joomus · PHP · 68 lines · 22 code · 5 blank · 41 comment · 2 complexity · c3d9c3f2f0d5bdfdd01d4ad5cc497e25 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Log
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. /**
  11. * Joomla! Callback Log class
  12. *
  13. * This class allows logging to be handled by a callback function.
  14. * This allows unprecedented flexibility in the way logging can be handled.
  15. *
  16. * @package Joomla.Platform
  17. * @subpackage Log
  18. * @since 12.2
  19. */
  20. class JLoggerCallback extends JLogLogger
  21. {
  22. /**
  23. * @var callback The function to call when an entry is added - should return True on success
  24. * @since 12.2
  25. */
  26. protected $callback;
  27. /**
  28. * Constructor.
  29. *
  30. * @param array &$options Log object options.
  31. *
  32. * @since 12.2
  33. */
  34. public function __construct(array &$options)
  35. {
  36. // Call the parent constructor.
  37. parent::__construct($options);
  38. // Throw an exception if there is not a valid callback
  39. if (isset($this->options['callback']) && is_callable($this->options['callback']))
  40. {
  41. $this->callback = $this->options['callback'];
  42. }
  43. else
  44. {
  45. throw new JLogException(JText::_('JLoggerCallback created without valid callback function.'));
  46. }
  47. }
  48. /**
  49. * Method to add an entry to the log.
  50. *
  51. * @param JLogEntry $entry The log entry object to add to the log.
  52. *
  53. * @return boolean True on success.
  54. *
  55. * @since 12.2
  56. * @throws LogException
  57. */
  58. public function addEntry(JLogEntry $entry)
  59. {
  60. // Pass the log entry to the callback function
  61. call_user_func($this->callback, $entry);
  62. }
  63. }