handlers.php 749 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. *
  4. *
  5. * @author Taddeus Kroes
  6. * @date 05-10-2012
  7. */
  8. namespace webbasics;
  9. require_once 'router.php';
  10. 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 . Inflector::capitalize(array_splice($data, 0, 1));
  17. if (method_exists($this, $method_name)) {
  18. if (count($data))
  19. $this->$method_name($data);
  20. else
  21. $this->$method_name();
  22. }
  23. // get($data) or post($data)
  24. $this->$request_type($data);
  25. }
  26. // get() or post()
  27. $this->$request_type();
  28. }
  29. }
  30. ?>