activitymanager.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Thomas Müller thomas.mueller@tmit.eu
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. *
  8. */
  9. namespace OC;
  10. use OCP\Activity\IConsumer;
  11. use OCP\Activity\IManager;
  12. class ActivityManager implements IManager {
  13. private $consumers = array();
  14. /**
  15. * @param $app
  16. * @param $subject
  17. * @param $subjectParams
  18. * @param $message
  19. * @param $messageParams
  20. * @param $file
  21. * @param $link
  22. * @param $affectedUser
  23. * @param $type
  24. * @param $priority
  25. * @return mixed
  26. */
  27. function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) {
  28. foreach($this->consumers as $consumer) {
  29. $c = $consumer();
  30. if ($c instanceof IConsumer) {
  31. try {
  32. $c->receive(
  33. $app,
  34. $subject,
  35. $subjectParams,
  36. $message,
  37. $messageParams,
  38. $file,
  39. $link,
  40. $affectedUser,
  41. $type,
  42. $priority);
  43. } catch (\Exception $ex) {
  44. // TODO: log the excepetion
  45. }
  46. }
  47. }
  48. }
  49. /**
  50. * In order to improve lazy loading a closure can be registered which will be called in case
  51. * activity consumers are actually requested
  52. *
  53. * $callable has to return an instance of OCA\Activity\IConsumer
  54. *
  55. * @param string $key
  56. * @param \Closure $callable
  57. */
  58. function registerConsumer(\Closure $callable) {
  59. array_push($this->consumers, $callable);
  60. }
  61. }