controller.php 1.58 KB
Newer Older
1 2
<?php namespace Laravel;

3 4 5
abstract class Controller {

	/**
6 7
	 * A stub method that will be called before every request to the controller.
	 *
8
	 * If a value is returned by the method, it will be halt the request cycle
9 10 11 12
	 * and will be considered the response to the request.
	 *
	 * @return mixed
	 */
13 14 15
	public function before() {}

	/**
16
	 * Magic Method to handle calls to undefined functions on the controller.
Taylor Otwell committed
17 18 19 20
	 *
	 * By default, the 404 response will be returned for an calls to undefined
	 * methods on the controller. However, this method may also be overridden
	 * and used as a pseudo-router by the controller.
21
	 */
Taylor Otwell committed
22 23
	public function __call($method, $parameters)
	{
24
		return IoC::container()->resolve('laravel.response')->error('404');
Taylor Otwell committed
25
	}
26

27
	/**
28
	 * Dynamically resolve items from the application IoC container.
29 30 31 32 33 34 35 36 37 38 39 40 41
	 *
	 * First, "laravel." will be prefixed to the requested item to see if there is
	 * a matching Laravel core class in the IoC container. If there is not, we will
	 * check for the item in the container using the name as-is.
	 *
	 * <code>
	 *		// Resolve the "laravel.input" instance from the IoC container
	 *		$input = $this->input;
	 *
	 *		// Resolve the "mailer" instance from the IoC container
	 *		$mongo = $this->mailer;
	 * </code>
	 *
42 43 44
	 */
	public function __get($key)
	{
45 46 47 48 49 50 51 52 53 54 55 56
		$container = IoC::container();

		if ($container->registered('laravel.'.$key))
		{
			return $container->resolve('laravel.'.$key);
		}
		elseif ($container->registered($key))
		{
			return $container->resolve($key);
		}

		throw new \Exception("Attempting to access undefined property [$key] on controller.");
57 58
	}

59
}