获取天气-步骤10-底线。。。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取天气-步骤10-底线。。。相关的知识,希望对你有一定的参考价值。

  1. //back to our "black roots"...
  2. class WeatherService{
  3.  
  4. private $cache;
  5.  
  6. public function WeatherService(){
  7. //some initialization...
  8. $cache = new DBCache(); //******** THE ONLY THING CHANGED !!!!!!!!!!!!!!!!!
  9. }
  10.  
  11. public function getWeatherInfo($city, $method){
  12.  
  13. if ($cache->get($city))
  14. return $cache->get($city);
  15.  
  16. $res = shell_exec("./getWdr.sh {$city}");
  17.  
  18. if ($methos=="CL")
  19. return convertFrToC($res);
  20.  
  21. return $res;
  22. }
  23.  
  24. private function convertFrToC($val){
  25. return (($val+40)*5/9)-40;
  26. }
  27.  
  28. }

以上是关于获取天气-步骤10-底线。。。的主要内容,如果未能解决你的问题,请参考以下文章

获取天气-步骤9-解耦

获取天气-步骤5-提高性能

获取天气-步骤4-增强封装

获取天气-步骤2-函数编程

获取天气-步骤6-更多封装-控制访问

获取天气-步骤8-添加抽象。第2部分。