controller.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php namespace Laravel;
  2. abstract class Controller {
  3. /**
  4. * A stub method that will be called before every request to the controller.
  5. *
  6. * If a value is returned by the method, it will be halt the request cycle
  7. * and will be considered the response to the request.
  8. *
  9. * @return mixed
  10. */
  11. public function before() {}
  12. /**
  13. * Magic Method to handle calls to undefined functions on the controller.
  14. *
  15. * By default, the 404 response will be returned for an calls to undefined
  16. * methods on the controller. However, this method may also be overridden
  17. * and used as a pseudo-router by the controller.
  18. */
  19. public function __call($method, $parameters)
  20. {
  21. return Response::error('404');
  22. }
  23. /**
  24. * Dynamically resolve items from the application IoC container.
  25. *
  26. * First, "laravel." will be prefixed to the requested item to see if there is
  27. * a matching Laravel core class in the IoC container. If there is not, we will
  28. * check for the item in the container using the name as-is.
  29. */
  30. public function __get($key)
  31. {
  32. if (IoC::container()->registered("laravel.{$key}"))
  33. {
  34. return IoC::container()->resolve("laravel.{$key}");
  35. }
  36. elseif (IoC::container()->registered($key))
  37. {
  38. return IoC::container()->resolve($key);
  39. }
  40. throw new \Exception("Attempting to access undefined property [$key] on controller.");
  41. }
  42. }