filter.php 812 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php namespace System\Routing;
  2. class Filter {
  3. /**
  4. * The loaded route filters.
  5. *
  6. * @var array
  7. */
  8. public static $filters;
  9. /**
  10. * Call a set of route filters.
  11. *
  12. * @param string $filter
  13. * @param array $parameters
  14. * @param bool $override
  15. * @return mixed
  16. */
  17. public static function call($filters, $parameters = array(), $override = false)
  18. {
  19. if (is_null(static::$filters))
  20. {
  21. static::$filters = require APP_PATH.'filters'.EXT;
  22. }
  23. foreach (explode(', ', $filters) as $filter)
  24. {
  25. if ( ! isset(static::$filters[$filter]))
  26. {
  27. throw new \Exception("Route filter [$filter] is not defined.");
  28. }
  29. $response = call_user_func_array(static::$filters[$filter], $parameters);
  30. if ( ! is_null($response) and $override)
  31. {
  32. return $response;
  33. }
  34. }
  35. }
  36. }