laravel/framework — pull request #264 by metadings (2013-02-06 03:19:14+00:00)
Title: Moving Facade::$app to Application::$Current

I really like the Facades construct, because it simplifies a call to a singleton, static instance of a Class.

I moved the Facade::$app to
```php

class Application extends Container implements HttpKernelInterface {

/**
* Singleton instance
*/
private static $Current = null;

/**
* Facade function: Get instance of Application
* Set instance of Application, returns old instance
*
* @param Application $newCurrent = null
* @return Application
*/
public static function Current($newCurrent = null) {
$current = static::$Current;

if ($newCurrent !== null) {
// Force this to be only in testing environment?
static::$Current = $newCurrent;
}

return $current; // return only current or the old current
}
```
The Current() function is also the heart of the new Facade class:
```php
namespace Illuminate\Support\Facades;

abstract class Facade {

/**
* Facade function for a Singleton, or registered component
*/
public static function Current() {
throw new \RuntimeException("Facade does not implement Current method.");
}

/**
* Handle dynamic, static calls to the Current() object.
*
* @param string $method
* @param array $args
* @return mixed
*/
public static function __callStatic($method, $args)
{
return call_user_func_array(array(static::Current(), $method), $args);
}

}
```

Now for example, in the Illuminate\Support\Facades\Router class you see, that the functions become direct aliases:

```php
class Route extends Facade {

// ...

/**
* Determine if the current route uses a given controller action.
*
* @param string $action
* @return bool
*/
public static function uses($action)
{
return static::currentRouteUses($action);
// instead of
//	return static::$app->currentRouteUses($action);
}

/**
* Get the registered component 'router'.
*
* @return Illuminate\Routing\Router
*/
public static function Current() {
return Illuminate\Foundation\Application::Current()['router'];
}
}
```