最近都没有学习PHP了,今天接着上一章的内容继续学习源文件 install.php
// 源文件 /install.php
1484
1485 install_dispatch();
1486
- 在install.php文件末尾调用了install_dispatch()函数,这个函数也是在install.php文件中定义的
// 源文件 /install.php
1392 /**
1393 * dispatch install action
1394 *
1395 */
1396 function install_dispatch()
1397 {
1398 // disable root url on cli mode
1399 if (install_is_cli()) {
1400 define('__TYPECHO_ROOT_URL__', 'http://localhost');
1401 }
1402
- 根据install_is_cli()函数的返回值来决定 '__TYPECHO_ROOT_URL__' 变量的值,下面看看install_is_cli()函数的内容
// 源文件 /install.php
61 /**
62 * detect cli mode
63 *
64 * @return bool
65 */
66 function install_is_cli(): bool
67 {
68 return \Typecho\Request::getInstance()->isCli();
69 }
70
- 函数install_is_cli()的返回值为布尔型,返回的是\Typecho\Request::getInstance()->isCli()这个函数的值,接着看这个函数是个啥
// 源文件 /var/Typecho/Request.php
440 /**
441 * @return bool
442 */
443 public function isCli(): bool
444 {
445 return php_sapi_name() == 'cli';
446 }
447
- 函数isCli()返回的是表达式 php_sapi_name() == 'cli' 的比较结果,php_sapi_name:返回 web 服务器和 PHP 之间的接口类型。继续下面继续看install_dispatch()函数
// 源文件 /install.php
1403 // init default options
1404 $options = \Widget\Options::alloc(install_get_default_options());
1405 \Widget\Init::alloc();
1406
- install_get_default_options()在install.php第237行进行了定义,\Widget\Options::alloc()在/var/Typecho/Widget.php第185行进行了定义,\Widget\Init::alloc()与\Widget\Options::alloc()相同
// 源文件 /install.php
232 /**
233 * list all default options
234 *
235 * @return array
236 */
237 function install_get_default_options(): array
238 {
239 static $options;
240
241 if (empty($options)) {
242 $options = [
'theme' => 'default',
'theme:default' => 'a:2:{s:7:"logoUrl";N;s:12:"sidebarBlock";a:5:{i:0;s:15:"ShowRecentPosts";i:1;s:18:"ShowRecentComments";i:2;s:12:"ShowCategory";i:3;s:11:"ShowArchive";i:4;s:9:"ShowOther";}}',
'timezone' => '28800',
'lang' => install_get_lang(),
'charset' => 'UTF-8',
'contentType' => 'text/html',
'gzip' => 0,
'generator' => 'Typecho ' . \Typecho\Common::VERSION,
'title' => 'Hello World',
'description' => 'Your description here.',
'keywords' => 'typecho,php,blog',
'rewrite' => 0,
'frontPage' => 'recent',
'frontArchive' => 0,
'commentsRequireMail' => 1,
'commentsWhitelist' => 0,
'commentsRequireURL' => 0,
'commentsRequireModeration' => 0,
'plugins' => 'a:0:{}',
'commentDateFormat' => 'F jS, Y \a\t h:i a',
'siteUrl' => install_get_site_url(),
'defaultCategory' => 1,
'allowRegister' => 0,
'defaultAllowComment' => 1,
'defaultAllowPing' => 1,
'defaultAllowFeed' => 1,
'pageSize' => 5,
'postsListSize' => 10,
'commentsListSize' => 10,
'commentsHTMLTagAllowed' => null,
'postDateFormat' => 'Y-m-d',
'feedFullText' => 1,
'editorSize' => 350,
'autoSave' => 0,
'markdown' => 1,
'xmlrpcMarkdown' => 0,
'commentsMaxNestingLevels' => 5,
'commentsPostTimeout' => 24 * 3600 * 30,
'commentsUrlNofollow' => 1,
'commentsShowUrl' => 1,
'commentsMarkdown' => 0,
'commentsPageBreak' => 0,
'commentsThreaded' => 1,
'commentsPageSize' => 20,
'commentsPageDisplay' => 'last',
'commentsOrder' => 'ASC',
'commentsCheckReferer' => 1,
'commentsAutoClose' => 0,
'commentsPostIntervalEnable' => 1,
'commentsPostInterval' => 60,
'commentsShowCommentOnly' => 0,
'commentsAvatar' => 1,
'commentsAvatarRating' => 'G',
'commentsAntiSpam' => 1,
'routingTable' => serialize(install_get_default_routers()),
'actionTable' => 'a:0:{}',
'panelTable' => 'a:0:{}',
'attachmentTypes' => '@image@',
'secret' => \Typecho\Common::randString(32, true),
'installed' => 0,
'allowXmlRpc' => 2
304 ];
305 }
306
// 源文件 /var/Typecho/Widget.php
177 /**
178 * alloc widget instance
179 *
180 * @param mixed $params
181 * @param mixed $request
182 * @param bool|callable $disableSandboxOrCallback
183 * @return $this
184 */
185 public static function alloc($params = null, $request = null, $disableSandboxOrCallback = true): Widget
186 {
187 return self::widget(static::class, $params, $request, $disableSandboxOrCallback);
188 }
189
- 函数返回一个widget类的实例,限于篇幅本章到此结束,下一章接着往下学习。