リーリー
以上就介绍了YII 的源码分析(-),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
<spanmicrosoft yahei font-size:><span>abstract</span> <span>public</span> <span>function</span> processRequest(); 这个方法在当前类中是抽象的,所以肯定在它的子类中实现了。回去找CWebApplication:
<span>public</span> <span>function</span><span> processRequest()
{
</span><span>if</span>(<span>is_array</span>(<span>$this</span>->catchAllRequest) && <span>isset</span>(<span>$this</span>->catchAllRequest[0<span>]))
{
</span><span>$route</span>=<span>$this</span>->catchAllRequest[0<span>];
</span><span>foreach</span>(<span>array_splice</span>(<span>$this</span>->catchAllRequest,1) <span>as</span> <span>$name</span>=><span>$value</span><span>)
</span><span>$_GET</span>[<span>$name</span>]=<span>$value</span><span>;
}
</span><span>else</span>
<span>$route</span>=<span>$this</span>->getUrlManager()->parseUrl(<span>$this</span>-><span>getRequest());
</span><span>$this</span>->runController(<span>$route</span><span>);
}</span></spanmicrosoft>
<spanmicrosoft yahei font-size:><span>public</span> <span>function</span> runController(<span>$route</span><span>)
{
</span><span>if</span>((<span>$ca</span>=<span>$this</span>->createController(<span>$route</span>))!==<span>null</span><span>)
{
</span><span>list</span>(<span>$controller</span>,<span>$actionID</span>)=<span>$ca</span><span>;
</span><span>$oldController</span>=<span>$this</span>-><span>_controller;
</span><span>$this</span>->_controller=<span>$controller</span><span>;
</span><span>$controller</span>-><span>init();
</span><span>$controller</span>->run(<span>$actionID</span><span>);
</span><span>$this</span>->_controller=<span>$oldController</span><span>;
}
</span><span>else</span>
<span>throw</span> <span>new</span> CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".',
<span>array</span>('{route}'=><span>$route</span>===''?<span>$this</span>->defaultController:<span>$route</span><span>)));
}</span></spanmicrosoft>
<spanmicrosoft yahei font-size:><span>public</span> <span>function</span> run(<span>$actionID</span><span>)
{
</span><span>if</span>((<span>$action</span>=<span>$this</span>->createAction(<span>$actionID</span>))!==<span>null</span><span>)
{
</span><span>if</span>((<span>$parent</span>=<span>$this</span>->getModule())===<span>null</span><span>){
</span><span>$parent</span>=Yii::<span>app();
}
</span><span>if</span>(<span>$parent</span>->beforeControllerAction(<span>$this</span>,<span>$action</span><span>))
{
</span><span>$this</span>->runActionWithFilters(<span>$action</span>,<span>$this</span>-><span>filters());
</span><span>$parent</span>->afterControllerAction(<span>$this</span>,<span>$action</span><span>);
}
}
</span><span>else</span>
<span>$this</span>->missingAction(<span>$actionID</span><span>);
}
</span></spanmicrosoft>
<spanmicrosoft yahei font-size:><span>public</span> <span>function</span> runActionWithFilters(<span>$action</span>,<span>$filters</span><span>)
{
</span><span>if</span>(<span>empty</span>(<span>$filters</span><span>)){
</span><span>$this</span>->runAction(<span>$action</span><span>);
}
</span><span>else</span><span>
{
</span><span>$priorAction</span>=<span>$this</span>-><span>_action;
</span><span>$this</span>->_action=<span>$action</span><span>;
CFilterChain</span>::create(<span>$this</span>,<span>$action</span>,<span>$filters</span>)-><span>run();
</span><span>$this</span>->_action=<span>$priorAction</span><span>;
}
}</span></spanmicrosoft>
<spanmicrosoft yahei font-size:><span>public</span> <span>function</span> runAction(<span>$action</span><span>)
{
</span><span>$priorAction</span>=<span>$this</span>-><span>_action;
</span><span>$this</span>->_action=<span>$action</span><span>;
</span><span>if</span>(<span>$this</span>->beforeAction(<span>$action</span><span>))
{
</span><span>if</span>(<span>$action</span>->runWithParams(<span>$this</span>->getActionParams())===<span>false</span><span>){
</span><span>$this</span>->invalidActionParams(<span>$action</span><span>);
}
</span><span>else</span><span>{
</span><span>$this</span>->afterAction(<span>$action</span><span>);
}
}
</span><span>$this</span>->_action=<span>$priorAction</span><span>;
}</span></spanmicrosoft>
<spanmicrosoft yahei font-size:> <span>public</span> <span>function</span> runWithParams(<span>$params</span><span>)
{
</span><span>$methodName</span>='action'.<span>$this</span>-><span>getId();
</span><span>$controller</span>=<span>$this</span>-><span>getController();
</span><span>$method</span>=<span>new</span> ReflectionMethod(<span>$controller</span>, <span>$methodName</span><span>);
</span><span>if</span>(<span>$method</span>->getNumberOfParameters()>0<span>)
</span><span>return</span> <span>$this</span>->runWithParamsInternal(<span>$controller</span>, <span>$method</span>, <span>$params</span><span>);
</span><span>else</span>
<span>return</span> <span>$controller</span>-><span>$methodName</span><span>();
}</span></spanmicrosoft>
<spanmicrosoft yahei font-size:> <span>public</span> <span>function</span><span> actionIndex()
{
</span><span>echo</span> 'Hello World'<span>;
}</span></spanmicrosoft>