facades.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php namespace Laravel\Facades;
  2. use Laravel\IoC;
  3. /**
  4. * The Laravel framework makes thorough use of dependency injection assisted by an application
  5. * inversion of control container. This allows for great flexibility, easy testing, and better
  6. * architecture. However, most PHP framework users may be used to accessing classes through
  7. * a variety of static methods. Laravel provides "facades" to simulate this behavior while
  8. * still using heavy dependency injection.
  9. *
  10. * Each class that is commonly used by the developer has a corresponding facade defined in
  11. * this file. All of the various facades inherit from the abstract Facade class, which only
  12. * has a single __callStatic magic method. The facade simply resolves the requested class
  13. * out of the IoC container and calls the appropriate method.
  14. */
  15. abstract class Facade {
  16. /**
  17. * Magic Method for passing methods to a class registered in the IoC container.
  18. * This provides a convenient method of accessing functions on classes that
  19. * could not otherwise be accessed staticly.
  20. *
  21. * Facades allow Laravel to still have a high level of dependency injection
  22. * and testability while still accomodating the common desire to conveniently
  23. * use classes via static methods.
  24. */
  25. public static function __callStatic($method, $parameters)
  26. {
  27. return call_user_func_array(array(IoC::container()->resolve(static::$resolve), $method), $parameters);
  28. }
  29. }
  30. class Auth extends Facade { public static $resolve = 'laravel.auth'; }
  31. class Cookie extends Facade { public static $resolve = 'laravel.cookie'; }
  32. class Crypter extends Facade { public static $resolve = 'laravel.crypter'; }
  33. class Hasher extends Facade { public static $resolve = 'laravel.hasher'; }
  34. class Input extends Facade { public static $resolve = 'laravel.input'; }
  35. class Request extends Facade { public static $resolve = 'laravel.request'; }
  36. class Session extends Facade { public static $resolve = 'laravel.session'; }
  37. class URI extends Facade { public static $resolve = 'laravel.uri'; }