Behavior.class.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2012 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. /**
  12. * ThinkPHP Behavior基础类
  13. * @category Think
  14. * @package Think
  15. * @subpackage Core
  16. * @author liu21st <liu21st@gmail.com>
  17. */
  18. abstract class Behavior {
  19. // 行为参数 和配置参数设置相同
  20. protected $options = array();
  21. /**
  22. * 架构函数
  23. * @access public
  24. */
  25. public function __construct() {
  26. if(!empty($this->options)) {
  27. foreach ($this->options as $name=>$val){
  28. if(NULL !== C($name)) { // 参数已设置 则覆盖行为参数
  29. $this->options[$name] = C($name);
  30. }else{ // 参数未设置 则传入默认值到配置
  31. C($name,$val);
  32. }
  33. }
  34. array_change_key_case($this->options);
  35. }
  36. }
  37. // 获取行为参数
  38. public function __get($name){
  39. return $this->options[strtolower($name)];
  40. }
  41. /**
  42. * 执行行为 run方法是Behavior唯一的接口
  43. * @access public
  44. * @param mixed $params 行为参数
  45. * @return void
  46. */
  47. abstract public function run(&$params);
  48. }