1
0

HookHelper.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test;
  9. use OC\Files\Filesystem;
  10. /**
  11. * Helper class to register hooks on
  12. */
  13. class HookHelper {
  14. public static $hookCalls;
  15. public static function setUpHooks() {
  16. self::clear();
  17. \OCP\Util::connectHook(
  18. Filesystem::CLASSNAME,
  19. Filesystem::signal_create,
  20. '\Test\HookHelper',
  21. 'createCallback'
  22. );
  23. \OCP\Util::connectHook(
  24. Filesystem::CLASSNAME,
  25. Filesystem::signal_update,
  26. '\Test\HookHelper',
  27. 'updateCallback'
  28. );
  29. \OCP\Util::connectHook(
  30. Filesystem::CLASSNAME,
  31. Filesystem::signal_write,
  32. '\Test\HookHelper',
  33. 'writeCallback'
  34. );
  35. \OCP\Util::connectHook(
  36. Filesystem::CLASSNAME,
  37. Filesystem::signal_post_create,
  38. '\Test\HookHelper',
  39. 'postCreateCallback'
  40. );
  41. \OCP\Util::connectHook(
  42. Filesystem::CLASSNAME,
  43. Filesystem::signal_post_update,
  44. '\Test\HookHelper',
  45. 'postUpdateCallback'
  46. );
  47. \OCP\Util::connectHook(
  48. Filesystem::CLASSNAME,
  49. Filesystem::signal_post_write,
  50. '\Test\HookHelper',
  51. 'postWriteCallback'
  52. );
  53. }
  54. public static function clear() {
  55. self::$hookCalls = [];
  56. }
  57. public static function createCallback($params) {
  58. self::$hookCalls[] = [
  59. 'signal' => Filesystem::signal_create,
  60. 'params' => $params
  61. ];
  62. }
  63. public static function updateCallback($params) {
  64. self::$hookCalls[] = [
  65. 'signal' => Filesystem::signal_update,
  66. 'params' => $params
  67. ];
  68. }
  69. public static function writeCallback($params) {
  70. self::$hookCalls[] = [
  71. 'signal' => Filesystem::signal_write,
  72. 'params' => $params
  73. ];
  74. }
  75. public static function postCreateCallback($params) {
  76. self::$hookCalls[] = [
  77. 'signal' => Filesystem::signal_post_create,
  78. 'params' => $params
  79. ];
  80. }
  81. public static function postUpdateCallback($params) {
  82. self::$hookCalls[] = [
  83. 'signal' => Filesystem::signal_post_update,
  84. 'params' => $params
  85. ];
  86. }
  87. public static function postWriteCallback($params) {
  88. self::$hookCalls[] = [
  89. 'signal' => Filesystem::signal_post_write,
  90. 'params' => $params
  91. ];
  92. }
  93. /**
  94. * Callback that sets the run parameter to false
  95. */
  96. public static function cancellingCallback($params) {
  97. $params[Filesystem::signal_param_run] = false;
  98. }
  99. }