Library.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Heanup\Frame;
  3. /**
  4. * Library的父类, 基础类库
  5. */
  6. class Library
  7. {
  8. protected $configClass = null;
  9. protected $configSection = null;
  10. /**
  11. * 构造函数
  12. * @param null $configClass
  13. * @param null $configSection
  14. */
  15. public function __construct($configClass = null, $configSection = null)
  16. {
  17. if ($configClass) {
  18. // 判断是否是全路径
  19. if(substr($configClass, 0, strlen(Dispatcher::CONFIG_PREFIX)) != Dispatcher::CONFIG_PREFIX){
  20. $this->configClass = Dispatcher::CONFIG_PREFIX . '\\' . trim($configClass, '\\');
  21. }else{
  22. $this->configClass = $configClass;
  23. }
  24. }
  25. // 设置配置文件内容片段
  26. if (!is_null($configSection)) {
  27. $this->configSection = $configSection;
  28. }
  29. }
  30. /**
  31. * 根据索引取出详细配置信息
  32. */
  33. protected function getConfig()
  34. {
  35. $class = $this->configClass;
  36. if (class_exists($class) && method_exists($class, 'getData')) {
  37. return $class::getData($this->configSection);
  38. }
  39. return array();
  40. }
  41. /**
  42. * 获取一组标识
  43. * @param $flag
  44. * @return string
  45. */
  46. protected function getFlag($flag = false)
  47. {
  48. $flag = $this->configClass . ':' . $this->configSection . ':' . intval($flag);
  49. return $flag;
  50. }
  51. }