Guest User

Untitled

a guest
Jun 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. Index: model/factory.php
  2. ===================================================================
  3. --- model/factory.php (revision 11512)
  4. +++ model/factory.php (working copy)
  5. @@ -11,6 +11,9 @@
  6. * The result will be an object of api_model with the given named params.
  7. */
  8. class api_model_factory {
  9. +
  10. + private static $interceptors = array();
  11. +
  12. /**
  13. * Model Factory
  14. *
  15. @@ -23,6 +26,13 @@
  16. if (class_exists($namespace . '_model_' . $name)) {
  17. $name = $namespace . '_model_' . $name;
  18. }
  19. +
  20. + foreach ( self::$interceptors as $interceptor ) {
  21. + if ( $interceptor->intercepts($name) ) {
  22. + return $interceptor->get($name, $params, $namespace);
  23. + }
  24. + }
  25. +
  26. if (count($params) == 0) {
  27. return new $name;
  28. } else {
  29. @@ -30,4 +40,16 @@
  30. return $class->newInstanceArgs($params);
  31. }
  32. }
  33. +
  34. + /**
  35. + * Register an object that can intercept the request made to
  36. + * api_model_factory::get() and return a different object.
  37. + * An interceptor should provide two methods;
  38. + * - an "intercepts" method takes a class name and returns boolean
  39. + * (true if the interceptor want to intercept)
  40. + * - a "get" method which returns the object, given it's class name
  41. + */
  42. + public static function registerInterceptor($interceptor) {
  43. + self::$interceptors[] = $interceptor;
  44. + }
  45. }
Add Comment
Please, Sign In to add comment