PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/yii/requirements/index.php

https://github.com/ashie1287/headfirst
PHP | 231 lines | 186 code | 21 blank | 24 comment | 26 complexity | 8d28b6e1db76cb7247c6d1a589f2a44d MD5 | raw file
Possible License(s): BSD-2-Clause, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * Yii Requirement Checker script
  4. *
  5. * This script will check if your system meets the requirements for running
  6. * Yii-powered Web applications.
  7. *
  8. * @author Qiang Xue <qiang.xue@gmail.com>
  9. * @link http://www.yiiframework.com/
  10. * @copyright Copyright &copy; 2008-2010 Yii Software LLC
  11. * @license http://www.yiiframework.com/license/
  12. * @version $Id: index.php 1678 2010-01-07 21:02:00Z qiang.xue $
  13. * @package system
  14. * @since 1.0
  15. */
  16. /**
  17. * @var array List of requirements (name, required or not, result, used by, memo)
  18. */
  19. $requirements = array(
  20. array(
  21. t('yii','PHP version'),
  22. true,
  23. version_compare(PHP_VERSION,"5.1.0",">="),
  24. '<a href="http://www.yiiframework.com">Yii Framework</a>',
  25. t('yii','PHP 5.1.0 or higher is required.')),
  26. array(
  27. t('yii','$_SERVER variable'),
  28. true,
  29. ($message=checkServerVar())==='',
  30. '<a href="http://www.yiiframework.com">Yii Framework</a>',
  31. $message),
  32. array(
  33. t('yii','Reflection extension'),
  34. true,
  35. class_exists('Reflection',false),
  36. '<a href="http://www.yiiframework.com">Yii Framework</a>',
  37. ''),
  38. array(
  39. t('yii','PCRE extension'),
  40. true,
  41. extension_loaded("pcre"),
  42. '<a href="http://www.yiiframework.com">Yii Framework</a>',
  43. ''),
  44. array(
  45. t('yii','SPL extension'),
  46. true,
  47. extension_loaded("SPL"),
  48. '<a href="http://www.yiiframework.com">Yii Framework</a>',
  49. ''),
  50. array(
  51. t('yii','DOM extension'),
  52. false,
  53. class_exists("DOMDocument",false),
  54. '<a href="http://www.yiiframework.com/doc/api/CWsdlGenerator">CWsdlGenerator</a>',
  55. ''),
  56. array(
  57. t('yii','PDO extension'),
  58. false,
  59. extension_loaded('pdo'),
  60. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  61. ''),
  62. array(
  63. t('yii','PDO SQLite extension'),
  64. false,
  65. extension_loaded('pdo_sqlite'),
  66. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  67. t('yii','This is required if you are using SQLite database.')),
  68. array(
  69. t('yii','PDO MySQL extension'),
  70. false,
  71. extension_loaded('pdo_mysql'),
  72. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  73. t('yii','This is required if you are using MySQL database.')),
  74. array(
  75. t('yii','PDO PostgreSQL extension'),
  76. false,
  77. extension_loaded('pdo_pgsql'),
  78. t('yii','All <a href="http://www.yiiframework.com/doc/api/#system.db">DB-related classes</a>'),
  79. t('yii','This is required if you are using PostgreSQL database.')),
  80. array(
  81. t('yii','Memcache extension'),
  82. false,
  83. extension_loaded("memcache"),
  84. '<a href="http://www.yiiframework.com/doc/api/CMemCache">CMemCache</a>',
  85. ''),
  86. array(
  87. t('yii','APC extension'),
  88. false,
  89. extension_loaded("apc"),
  90. '<a href="http://www.yiiframework.com/doc/api/CApcCache">CApcCache</a>',
  91. ''),
  92. array(
  93. t('yii','Mcrypt extension'),
  94. false,
  95. extension_loaded("mcrypt"),
  96. '<a href="http://www.yiiframework.com/doc/api/CSecurityManager">CSecurityManager</a>',
  97. t('yii','This is required by encrypt and decrypt methods.')),
  98. array(
  99. t('yii','SOAP extension'),
  100. false,
  101. extension_loaded("soap"),
  102. '<a href="http://www.yiiframework.com/doc/api/CWebService">CWebService</a>, <a href="http://www.yiiframework.com/doc/api/CWebServiceAction">CWebServiceAction</a>',
  103. ''),
  104. array(
  105. t('yii','GD extension'),
  106. false,
  107. extension_loaded('gd'),
  108. '<a href="http://www.yiiframework.com/doc/api/CCaptchaAction">CCaptchaAction</a>',
  109. ''),
  110. );
  111. function checkServerVar()
  112. {
  113. $vars=array('HTTP_HOST', 'SERVER_NAME', 'SERVER_PORT', 'SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF', 'HTTP_ACCEPT', 'HTTP_USER_AGENT');
  114. $missing=array();
  115. foreach($vars as $var)
  116. {
  117. if(!isset($_SERVER[$var]))
  118. $missing[]=$var;
  119. }
  120. if(!empty($missing))
  121. return t('yii','$_SERVER does not have {vars}.',array('{vars}'=>implode(', ',$missing)));
  122. if(realpath($_SERVER["SCRIPT_FILENAME"])!==realpath(__FILE__))
  123. return t('yii','$_SERVER["SCRIPT_FILENAME"] must be the same as the entry script file path.');
  124. if(!isset($_SERVER["REQUEST_URI"]) && isset($_SERVER["QUERY_STRING"]))
  125. return t('yii','Either $_SERVER["REQUEST_URI"] or $_SERVER["QUERY_STRING"] must exist.');
  126. if(!isset($_SERVER["PATH_INFO"]) && strpos($_SERVER["PHP_SELF"],$_SERVER["SCRIPT_NAME"])!==0)
  127. return t('yii','Unable to determine URL path info. Please make sure $_SERVER["PATH_INFO"] (or $_SERVER["PHP_SELF"] and $_SERVER["SCRIPT_NAME"]) contains proper value.');
  128. return '';
  129. }
  130. function getYiiVersion()
  131. {
  132. $coreFile=dirname(__FILE__).'/../framework/YiiBase.php';
  133. if(is_file($coreFile))
  134. {
  135. $contents=file_get_contents($coreFile);
  136. $matches=array();
  137. if(preg_match('/public static function getVersion.*?return \'(.*?)\'/ms',$contents,$matches)>0)
  138. return $matches[1];
  139. }
  140. return '';
  141. }
  142. /**
  143. * Returns a localized message according to user preferred language.
  144. * @param string message category
  145. * @param string message to be translated
  146. * @param array parameters to be applied to the translated message
  147. * @return string translated message
  148. */
  149. function t($category,$message,$params=array())
  150. {
  151. static $messages;
  152. if($messages===null)
  153. {
  154. $messages=array();
  155. if(($lang=getPreferredLanguage())!==false)
  156. {
  157. $file=dirname(__FILE__)."/messages/$lang/yii.php";
  158. if(is_file($file))
  159. $messages=include($file);
  160. }
  161. }
  162. if(empty($message))
  163. return $message;
  164. if(isset($messages[$message]) && $messages[$message]!=='')
  165. $message=$messages[$message];
  166. return $params!==array() ? strtr($message,$params) : $message;
  167. }
  168. function getPreferredLanguage()
  169. {
  170. if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && ($n=preg_match_all('/([\w\-]+)\s*(;\s*q\s*=\s*(\d*\.\d*))?/',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches))>0)
  171. {
  172. $languages=array();
  173. for($i=0;$i<$n;++$i)
  174. $languages[$matches[1][$i]]=empty($matches[3][$i]) ? 1.0 : floatval($matches[3][$i]);
  175. arsort($languages);
  176. foreach($languages as $language=>$pref)
  177. return strtolower(str_replace('-','_',$language));
  178. }
  179. return false;
  180. }
  181. function getServerInfo()
  182. {
  183. $info[]=isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : '';
  184. $info[]='<a href="http://www.yiiframework.com/">Yii Framework</a>/'.getYiiVersion();
  185. $info[]=@strftime('%Y-%m-%d %H:%M',time());
  186. return implode(' ',$info);
  187. }
  188. function renderFile($_file_,$_params_=array())
  189. {
  190. extract($_params_);
  191. require($_file_);
  192. }
  193. $result=1; // 1: all pass, 0: fail, -1: pass with warnings
  194. foreach($requirements as $i=>$requirement)
  195. {
  196. if($requirement[1] && !$requirement[2])
  197. $result=0;
  198. else if($result>0 && !$requirement[1] && !$requirement[2])
  199. $result=-1;
  200. if($requirement[4]==='')
  201. $requirements[$i][4]='&nbsp;';
  202. }
  203. $lang=getPreferredLanguage();
  204. $viewFile=dirname(__FILE__)."/views/$lang/index.php";
  205. if(!is_file($viewFile))
  206. $viewFile=dirname(__FILE__).'/views/index.php';
  207. renderFile($viewFile,array(
  208. 'requirements'=>$requirements,
  209. 'result'=>$result,
  210. 'serverInfo'=>getServerInfo()));