InitHookBehavior.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. // +---------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +---------------------------------------------------------------------
  5. // | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
  6. // +---------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +---------------------------------------------------------------------
  9. // | Author: Dean <zxxjjforever@163.com>
  10. // +---------------------------------------------------------------------
  11. namespace cmf\behavior;
  12. use think\Hook;
  13. use think\Db;
  14. class InitHookBehavior
  15. {
  16. // 行为扩展的执行入口必须是run
  17. public function run(&$param)
  18. {
  19. if (!cmf_is_installed()) {
  20. return;
  21. }
  22. $plugins = cache('init_hook_plugins');
  23. if (empty($plugins)) {
  24. $plugins = Db::name('hook_plugin')->field('hook,plugin')->where('status', 1)
  25. ->order('list_order ASC')
  26. ->select();
  27. cache('init_hook_plugins', $plugins);
  28. }
  29. if (!empty($plugins)) {
  30. foreach ($plugins as $hookPlugin) {
  31. Hook::add($hookPlugin['hook'], cmf_get_plugin_class($hookPlugin['plugin']));
  32. }
  33. }
  34. }
  35. }