Base.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace Widget;
  3. use Typecho\Config;
  4. use Typecho\Db;
  5. use Typecho\Widget;
  6. if (!defined('__TYPECHO_ROOT_DIR__')) {
  7. exit;
  8. }
  9. /**
  10. * 纯数据抽象组件
  11. *
  12. * @category typecho
  13. * @package Widget
  14. * @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
  15. * @license GNU General Public License 2.0
  16. */
  17. abstract class Base extends Widget
  18. {
  19. /**
  20. * init db
  21. */
  22. protected const INIT_DB = 0b0001;
  23. /**
  24. * init user widget
  25. */
  26. protected const INIT_USER = 0b0010;
  27. /**
  28. * init security widget
  29. */
  30. protected const INIT_SECURITY = 0b0100;
  31. /**
  32. * init options widget
  33. */
  34. protected const INIT_OPTIONS = 0b1000;
  35. /**
  36. * init all widgets
  37. */
  38. protected const INIT_ALL = 0b1111;
  39. /**
  40. * init none widget
  41. */
  42. protected const INIT_NONE = 0;
  43. /**
  44. * 全局选项
  45. *
  46. * @var Options
  47. */
  48. protected $options;
  49. /**
  50. * 用户对象
  51. *
  52. * @var User
  53. */
  54. protected $user;
  55. /**
  56. * 安全模块
  57. *
  58. * @var Security
  59. */
  60. protected $security;
  61. /**
  62. * 数据库对象
  63. *
  64. * @var Db
  65. */
  66. protected $db;
  67. /**
  68. * init method
  69. */
  70. protected function init()
  71. {
  72. $components = self::INIT_ALL;
  73. $this->initComponents($components);
  74. if ($components != self::INIT_NONE) {
  75. $this->db = Db::get();
  76. }
  77. if ($components & self::INIT_USER) {
  78. $this->user = User::alloc();
  79. }
  80. if ($components & self::INIT_OPTIONS) {
  81. $this->options = Options::alloc();
  82. }
  83. if ($components & self::INIT_SECURITY) {
  84. $this->security = Security::alloc();
  85. }
  86. $this->initParameter($this->parameter);
  87. }
  88. /**
  89. * @param int $components
  90. */
  91. protected function initComponents(int &$components)
  92. {
  93. }
  94. /**
  95. * @param Config $parameter
  96. */
  97. protected function initParameter(Config $parameter)
  98. {
  99. }
  100. }