Template.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\facade;
  12. if (class_exists('think\Facade')) {
  13. class Facade extends \think\Facade
  14. {}
  15. } else {
  16. class Facade
  17. {
  18. /**
  19. * 始终创建新的对象实例
  20. * @var bool
  21. */
  22. protected static $alwaysNewInstance;
  23. protected static $instance;
  24. /**
  25. * 获取当前Facade对应类名
  26. * @access protected
  27. * @return string
  28. */
  29. protected static function getFacadeClass()
  30. {}
  31. /**
  32. * 创建Facade实例
  33. * @static
  34. * @access protected
  35. * @return object
  36. */
  37. protected static function createFacade()
  38. {
  39. $class = static::getFacadeClass() ?: 'think\Template';
  40. if (static::$alwaysNewInstance) {
  41. return new $class();
  42. }
  43. if (!self::$instance) {
  44. self::$instance = new $class();
  45. }
  46. return self::$instance;
  47. }
  48. // 调用实际类的方法
  49. public static function __callStatic($method, $params)
  50. {
  51. return call_user_func_array([static::createFacade(), $method], $params);
  52. }
  53. }
  54. }
  55. /**
  56. * @see \think\Template
  57. * @mixin \think\Template
  58. */
  59. class Template extends Facade
  60. {
  61. protected static $alwaysNewInstance = true;
  62. /**
  63. * 获取当前Facade对应类名(或者已经绑定的容器对象标识)
  64. * @access protected
  65. * @return string
  66. */
  67. protected static function getFacadeClass()
  68. {
  69. return 'think\Template';
  70. }
  71. }