~horux-dev/horux-webcli/thfo

« back to all changes in this revision

Viewing changes to yii/requirements/index.php

  • Committer: Thierry Forchelet
  • Date: 2011-02-25 13:30:15 UTC
  • Revision ID: thierry.forchelet@letux.ch-20110225133015-zxyj9w7sqv8ly971
Initial commit

Show diffs side-by-side

added added

removed removed

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