typecho源代码注释(六)
好久没有学习PHP了,今天继续学习源文件 install.php
// 源文件 /install.php
1407 // display version
1408 if (install_is_cli()) {
1409 echo $options->generator . "\n";
1410 echo 'PHP ' . PHP_VERSION . "\n";
1411 }
- 如果是在使用客户端运行网站代码就输出typecho和PHP的版本
// 源文件 /install.php
1413 // install finished yet
1414 if (
1415 install_check('config')
1416 && install_check('db_structure')
1417 && install_check('db_data')
1418 ) {
1419 // redirect to siteUrl if not cli
1420 if (!install_is_cli()) {
1421 install_redirect($options->siteUrl);
1422 }
1423
1424 exit(1);
1425 }
- 如果三个install_check()函数的返回值都为真,并且不是在用php客户端运行网站代码就执行install_redirect()函数,不管是不是在用PHP客户端运行网站代码都不会再往下执行后面的代码。
// 源文件 /install.php
440 /**
441 * check install
442 *
443 * @param string $type
444 * @return bool
445 */
446 function install_check(string $type): bool
447 {
448 switch ($type) {
449 case 'config':
450 return file_exists(__TYPECHO_ROOT_DIR__ . '/config.inc.php');
451 case 'db_structure':
452 case 'db_data':
453 global $installDb;
454
455 if (empty($installDb)) {
456 return false;
457 }
458
459 try {
460 // check if table exists
461 $installed = $installDb->fetchRow($installDb->select()->from('table.options')
462 ->where('user = 0 AND name = ?', 'installed'));
463
464 if ($type == 'db_data' && empty($installed['value'])) {
465 return false;
466 }
467 } catch (\Typecho\Db\Adapter\ConnectionException $e) {
468 return true;
469 } catch (\Typecho\Db\Adapter\SQLException $e) {
470 return false;
471 }
472
473 return true;
474 default:
475 return false;
476 }
477 }
- 由于还未安装完毕case 'config'的返回值为假,case 'db_structure'内无代码,会执行default返回假,case 'db_data':因为$installDb为空返回值为假