加载配置类的意思就是改变一个配置的时候不需要找到他而是在一个单独的配置中修改,
我们用了二个方法
<ol start="1" class="dp-c"><li class="alt"><span> <span class="keyword">static</span><span> </span><span class="keyword">public</span><span> </span><span class="vars">$conf</span><span>=</span><span class="keyword">array</span><span>(); </span></span></li><li><span> <span class="keyword">static</span><span> </span><span class="keyword">public</span><span> </span><span class="keyword">function</span><span> get(</span><span class="vars">$name</span><span>,</span><span class="vars">$file</span><span>) </span></span></li><li class="alt"><span> { </span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> <span class="keyword">if</span><span>(isset(self::</span><span class="vars">$conf</span><span>[</span><span class="vars">$file</span><span>])) </span></span></li><li class="alt"><span> { </span></li><li><span> <span class="keyword">return</span><span> self::</span><span class="vars">$conf</span><span>[</span><span class="vars">$file</span><span>][</span><span class="vars">$name</span><span>]; </span></span></li><li class="alt"><span> } </span></li><li><span> <span class="keyword">else</span><span> </span></span></li><li class="alt"><span> { </span></li><li><span> <span class="vars">$path</span><span>=mvc.</span><span class="string">'\core\config\\'.$file.'</span><span>.php'; </span></span></li><li class="alt"><span> <span class="keyword">if</span><span>(</span><span class="func">is_file</span><span>(</span><span class="vars">$path</span><span>)) </span></span></li><li><span> { </span></li><li class="alt"><span> <span class="vars">$conf</span><span> = </span><span class="keyword">include</span><span> </span><span class="vars">$path</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span> <span class="keyword">if</span><span>(isset(</span><span class="vars">$conf</span><span>[</span><span class="vars">$name</span><span>])) </span></span></li><li><span> { </span></li><li class="alt"><span> self::<span class="vars">$conf</span><span>[</span><span class="vars">$file</span><span>]=</span><span class="vars">$conf</span><span>; </span></span></li><li><span> </span></li><li class="alt"><span> <span class="keyword">return</span><span> </span><span class="vars">$conf</span><span>[</span><span class="vars">$name</span><span>]; </span></span></li><li><span> } </span></li><li class="alt"><span> <span class="keyword">else</span><span> </span></span></li><li><span> { </span></li><li class="alt"><span> <span class="keyword">throw</span><span> </span><span class="keyword">new</span><span> \Exception(</span><span class="string">'没有这个配置项'</span><span>,</span><span class="vars">$file</span><span>); </span></span></li><li><span> } </span></li><li class="alt"><span> } </span></li><li><span> } </span></li><li class="alt"><span> </span></li><li><span> </span></li><li class="alt"><span> </span></li><li><span> }
</span></li></ol>
第二个方法
static public function all($file)
{
if(isset(self::$conf[$file]))
{
return self::$conf[$file];
}
else
{
$path=mvc.'\core\config\\'.$file.'.php';
if(is_file($path))
{
$conf =include $path;
self::$conf['$file']=$conf;
return $conf;
}
else
{
throw new \Exception('没有这个配置项',$file);
}
}
}
}
主要就是
判断配置文件是否存在
判断配置是否存在
缓存配置
日志类
存在我config里
设置好日志后加载驱动即可
return array(
'DRIVE'=>'file',
'OPTION'=>array(
'PATH'=>mvc.'/log/'
)
);
未完成 待补充