handlers.php 792 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. *
  4. *
  5. * @author Taddeus Kroes
  6. * @date 05-10-2012
  7. */
  8. namespace webbasics;
  9. require_once 'router.php';
  10. abstract class BaseHandler implements RouteHandler {
  11. function handleRequest(array $data) {
  12. $request_type = strtolower($_SERVER['REQUEST_METHOD']);
  13. // Try to use first match value as method name, e.g. getAction() if
  14. // first match value is "action"
  15. if (count($data)) {
  16. $method_name = $request_type . camelize($data[0], true);
  17. if (method_exists($this, $method_name)) {
  18. array_shift($data);
  19. if (count($data))
  20. return $this->$method_name($data);
  21. else
  22. return $this->$method_name();
  23. }
  24. // get($data) or post($data)
  25. return $this->$request_type($data);
  26. }
  27. // get() or post()
  28. return $this->$request_type();
  29. }
  30. }
  31. ?>