Application 类中设置路径的方法和调用ServiceLocator(服务定位器)加载运行时的组件的方法注释:

     /**
      * Handles the specified request.
      * 处理指定的请求--抽象方法
      * This method should return an instance of [[Response]] or its child class
      * which represents the handling result of the request.
      * 该方法应该返回一个[[Response]]实例,或者它的子类代表处理请求的结果
      *
      * @param Request $request the request to be handled
      * @return Response the resulting response
      */
     abstract public function handleRequest($request);

     private $_runtimePath;

     /**
      * Returns the directory that stores runtime files.
      * 返回存储运行时文件的路径
      * @return string the directory that stores runtime files.
      * Defaults to the "runtime" subdirectory under [[basePath]].
      * 默认返回[[basePath]]下的 "runtime"目录
      */
     public function getRuntimePath()
     {
         if ($this->_runtimePath === null) {
             $this->setRuntimePath($this->getBasePath() . DIRECTORY_SEPARATOR . 'runtime');
         }

         return $this->_runtimePath;
     }

     /**
      * Sets the directory that stores runtime files.
      * 设置存储运行时文件的路径
      * @param string $path the directory that stores runtime files.
      */
     public function setRuntimePath($path)
     {
         $this->_runtimePath = Yii::getAlias($path);
         Yii::setAlias('@runtime', $this->_runtimePath);
     }

     private $_vendorPath;

     /**
      * Returns the directory that stores vendor files.
      * 返回插件目录路径
      * @return string the directory that stores vendor files.
      * Defaults to "vendor" directory under [[basePath]].
      * 默认返回[[basePath]]下的 "vendor" 目录
      */
     public function getVendorPath()
     {
         if ($this->_vendorPath === null) {
             $this->setVendorPath($this->getBasePath() . DIRECTORY_SEPARATOR . 'vendor');
         }

         return $this->_vendorPath;
     }

     /**
      * Sets the directory that stores vendor files.
      * 设置插件目录路径,并设置别名
      * @param string $path the directory that stores vendor files.
      */
     public function setVendorPath($path)
     {
         $this->_vendorPath = Yii::getAlias($path);
         Yii::setAlias('@vendor', $this->_vendorPath);
         Yii::setAlias('@bower', $this->_vendorPath . DIRECTORY_SEPARATOR . 'bower');
         Yii::setAlias('@npm', $this->_vendorPath . DIRECTORY_SEPARATOR . 'npm');
     }

     /**
      * Returns the time zone used by this application.
      * 取得时区
      * This is a simple wrapper of PHP function date_default_timezone_get().
      * If time zone is not configured in php.ini or application config,
      * it will be set to UTC by default.
      * @return string the time zone used by this application.
      * @see http://php.net/manual/en/function.date-default-timezone-get.php
      */
     public function getTimeZone()
     {
         return date_default_timezone_get();
     }

     /**
      * Sets the time zone used by this application.
      * 设置时区
      * This is a simple wrapper of PHP function date_default_timezone_set().
      * Refer to the [php manual](http://www.php.net/manual/en/timezones.php) for available timezones.
      * @param string $value the time zone used by this application.
      * @see http://php.net/manual/en/function.date-default-timezone-set.php
      */
     public function setTimeZone($value)
     {
         date_default_timezone_set($value);
     }

     /**
      * Returns the database connection component.
      * 返回数据库连接组件
      * @return \yii\db\Connection the database connection.
      */
     public function getDb()
     {
         return $this->get('db');
     }

     /**
      * Returns the log dispatcher component.
      * 返回日志调度组件
      * @return \yii\log\Dispatcher the log dispatcher application component.
      */
     public function getLog()
     {
         return $this->get('log');
     }

     /**
      * Returns the error handler component.
      * 返回错误处理组件
      * @return \yii\web\ErrorHandler|\yii\console\ErrorHandler the error handler application component.
      */
     public function getErrorHandler()
     {
         return $this->get('errorHandler');
     }

     /**
      * Returns the cache component.
      * 返回缓存组件
      * @return \yii\caching\Cache the cache application component. Null if the component is not enabled.
      */
     public function getCache()
     {
         return $this->get('cache', false);
     }

     /**
      * Returns the formatter component.
      * 返回格式化程序组件
      * @return \yii\i18n\Formatter the formatter application component.
      */
     public function getFormatter()
     {
         return $this->get('formatter');
     }

     /**
      * Returns the request component.
      * 返回请求的组件对象
      * @return \yii\web\Request|\yii\console\Request the request component.
      */
     public function getRequest()
     {
         return $this->get('request');
     }

     /**
      * Returns the response component.
      * 返回响应组件
      * @return \yii\web\Response|\yii\console\Response the response component.
      */
     public function getResponse()
     {
         return $this->get('response');
     }

     /**
      * Returns the view object.
      * 返回视图对象
      * @return View|\yii\web\View the view application component that is used to render various view files.
      */
     public function getView()
     {
         return $this->get('view');
     }

     /**
      * Returns the URL manager for this application.
      * 返回当前应用的URL管理组件
      * @return \yii\web\UrlManager the URL manager for this application.
      */
     public function getUrlManager()
     {
         return $this->get('urlManager');
     }

     /**
      * Returns the internationalization (i18n) component
      * 返回国际化组件
      * @return \yii\i18n\I18N the internationalization application component.
      */
     public function getI18n()
     {
         return $this->get('i18n');
     }

     /**
      * Returns the mailer component.
      * 返回邮件组件
      * @return \yii\mail\MailerInterface the mailer application component.
      */
     public function getMailer()
     {
         return $this->get('mailer');
     }

     /**
      * Returns the auth manager for this application.
      * 返回该应用的权限管理组件
      * @return \yii\rbac\ManagerInterface the auth manager application component.
      * Null is returned if auth manager is not configured.
      */
     public function getAuthManager()
     {
         return $this->get('authManager', false);
     }

     /**
      * Returns the asset manager.
      * 返回资源管理组件
      * @return \yii\web\AssetManager the asset manager application component.
      */
     public function getAssetManager()
     {
         return $this->get('assetManager');
     }

     /**
      * Returns the security component.
      * 返回安全组件
      * @return \yii\base\Security the security application component.
      */
     public function getSecurity()
     {
         return $this->get('security');
     }

     /**
      * Returns the configuration of core application components.
      * 返回核心组件的配置
      * @see set()
      */
     public function coreComponents()
     {
         return [
             'log' => ['class' => 'yii\log\Dispatcher'],
             'view' => ['class' => 'yii\web\View'],
             'formatter' => ['class' => 'yii\i18n\Formatter'],
             'i18n' => ['class' => 'yii\i18n\I18N'],
             'mailer' => ['class' => 'yii\swiftmailer\Mailer'],
             'urlManager' => ['class' => 'yii\web\UrlManager'],
             'assetManager' => ['class' => 'yii\web\AssetManager'],
             'security' => ['class' => 'yii\base\Security'],
         ];
     }

     /**
      * Terminates the application.
      * 终止应用程序
      * This method replaces the `exit()` function by ensuring the application life cycle is completed
      * before terminating the application.
      * 该方法代替`exit()` 方法确认一个应用的生命周期已经结束
      * @param integer $status the exit status (value 0 means normal exit while other values mean abnormal exit).
      * @param Response $response the response to be sent. If not set, the default application [[response]] component will be used.
      * @throws ExitException if the application is in testing mode
      */
     public function end($status = 0, $response = null)
     {
         if ($this->state === self::STATE_BEFORE_REQUEST || $this->state === self::STATE_HANDLING_REQUEST) {//判断当前状态为请求前或者处理请求
             $this->state = self::STATE_AFTER_REQUEST;//则设置应用状态为请求完成后
             $this->trigger(self::EVENT_AFTER_REQUEST);//触发afterRequest事件
         }

         if ($this->state !== self::STATE_SENDING_RESPONSE && $this->state !== self::STATE_END) {//如果应用状态不是发送应答和应用结束
             $this->state = self::STATE_END;//设置状态为应用结束
             $response = $response ? : $this->getResponse();//
             $response->send();//向客户端发送应答
         }

         if (YII_ENV_TEST) {
             throw new ExitException($status);
         } else {
             exit($status);
         }
     }

Yii源码阅读笔记(二十六)的更多相关文章

  1. Yii源码阅读笔记(十六)

    Model类,集中整个应用的数据和业务逻辑—— /** * Generates a user friendly attribute label based on the give attribute ...

  2. Yii源码阅读笔记(十二)

    Action类,控制器中方法的基类: namespace yii\base; use Yii; /** * Action is the base class for all controller ac ...

  3. Yii源码阅读笔记(十八)

    View中的查找视图文件方法和渲染文件方法 /** * Finds the view file based on the given view name. * 通过view文件名查找view文件 * ...

  4. Yii源码阅读笔记(十五)

    Model类,集中整个应用的数据和业务逻辑——验证 /** * Returns the attribute labels. * 返回属性的标签 * * Attribute labels are mai ...

  5. Yii源码阅读笔记(十四)

    Model类,集中整个应用的数据和业务逻辑——场景.属性和标签: /** * Returns a list of scenarios and the corresponding active attr ...

  6. Yii源码阅读笔记(十)

    控制器类,所有控制器的基类,用于调用模型和布局,输出到视图 namespace yii\base; use Yii; /** * Controller is the base class for cl ...

  7. Yii源码阅读笔记(十九)

    View中渲染view视图文件的前置和后置方法,以及渲染动态内容的方法: /** * @return string|boolean the view file currently being rend ...

  8. Yii源码阅读笔记(一)

    今天开始阅读yii2的源码,想深入了解一下yii框架的工作原理,同时学习一下优秀的编码规范和风格.在此记录一下阅读中的小心得. 每个框架都有一个入口文件,首先从入口文件开始,yii2的入口文件位于we ...

  9. werkzeug源码阅读笔记(二) 下

    wsgi.py----第二部分 pop_path_info()函数 先测试一下这个函数的作用: >>> from werkzeug.wsgi import pop_path_info ...

  10. werkzeug源码阅读笔记(二) 上

    因为第一部分是关于初始化的部分的,我就没有发布出来~ wsgi.py----第一部分 在分析这个模块之前, 需要了解一下WSGI, 大致了解了之后再继续~ get_current_url()函数 很明 ...

随机推荐

  1. Delphi 包的设计思想及它与PAS、BPL、DCU、DLL、OXC的关系。

    DCP ,BPL分别是什么文件,起什么作用?你在DELPHI中建立一个package然后保存一下,看看. bpl和Dll比较相似.只是BPL是BORLAND自己弄出来的东西!!!调用也和调用DLL相似 ...

  2. Jenkins基础 - 常用配置操作

    1.修改jenkins的根目录,默认地在C:\Users\用户名\.jenkins下(win7) 或C:\Documents and Settings\用户名\.jenkins(xp) 修改步骤: 增 ...

  3. zookeeper定时清理log

    在zookeeper的目录下新建一个脚本,内容如下(zookeeper bin下面也有zkCleanup.sh脚本,原理一样,都是调用java类) shell_dir=$(cd ")&quo ...

  4. 【Oracle】Oracle 11g 64位安装完后,ora-12541错误和ora-12514错误的解决

    问题描述: 干净的windows2008 64位服务器上安装 oracle 11g R2 64bit服务端,安装完后,NetManager中默认的主机名为localhost,可以测试通过.但是无法在别 ...

  5. 自定义UICollectionViewLayout之瀑布流

    目标效果 因为系统给我们提供的 UICollectionViewFlowLayout 布局类不能实现瀑布流的效果,如果我们想实现 瀑布流 的效果,需要自定义一个 UICollectionViewLay ...

  6. BZOJ1950 : [Ceoi2006]Link

    显然在最优解中,添加的边都是从$1$出发的. 这个图是一个环套树的结构,对于树的部分,显然叶子节点必须加边. 因此可以自底向上确定树中哪些节点需要加边,同时得到$1$到环上每个点的距离. 对于每个环, ...

  7. Qt搭建多线程Server

    起因是MySQL在Android上没有驱动.也就是说,移动端想要访问远程数据库,必须通过一台(或多台)PC进行中转. 中转PC作为Server,接受来自移动端Socket访问数据库的要求,Server ...

  8. Mac OS X中MacPorts安装和使用

      安装 官网pkg安装   搜索索引中的软件port search name 安装新软件sudo port install name 卸载软件sudo port uninstall name 查看有 ...

  9. 【BZOJ】2212: [Poi2011]Tree Rotations

    题意 给一棵\(n(1 \le n \le 200000)\)个叶子的二叉树,可以交换每个点的左右子树,要求前序遍历叶子的逆序对最少. 分析 可以发现如果交换非叶结点的左右子树,对子树内的交换无影响, ...

  10. Java_JAVA6动态编译的问题

    摘自:http://www.iteye.com/problems/14909 在使用JAVA6动态编译时遇到的一个问题,动态编译方法已经写就.通过main方法调用的动态编译时,编译通过,并可以使用编译 ...