PHP Yii Framework Source Reading (ii) overall implementation process analysis

Source: Internet
Author: User
Tags autoload config php file yii

A procedure entrance

<?php
    
//change the following paths if necessary 
$yii =dirname (__file__). ' /http://www.cnblogs.com/framework/yii.php ';
$config =dirname (__file__). ' /protected/config/main.php ';
    
Remove the following line when in production mode
//defined (' Yii_debug ') or define (' Yii_debug ', true);
    
Require_once ($yii);
Yii::createwebapplication ($config)->run ();

The require_once ($YII) statement contains the yii.php file, which is a yii bootstrap file that contains the base class for Yiibase, and Yii fully inherits the Yiibase

<?php
/**
 * Yii bootstrap file.
 * *
 @author Qiang xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
 * @copyright Copyright &copy; 2008-2011 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 * @version $Id: yii.php 2799 2011-01-01 19:31:13z Qiang.xue $
 * @package System
 * @since 1.0
    
/require (dirname). ' /yiibase.php ');
    
/**
 * Yii is a helper class serving common framework functionalities.
 *
 * * It encapsulates {@link Yiibase} which provides the actual implementation.
 * By writing your own Yii class, you can customize some functionalities of yiibase.
 *
 * @author Qiang xue <qiang.xue@gmail.com>
 * @version $Id: yii.php 2799 2011-01-01 19:31:13z qiang.xue $< c21/>* @package System
 * @since 1.0
 /
class Yii extends Yiibase
{
}

Some of the yiibase classes are defined as:

public static function Createwebapplication ($config =null)//Create startup public
    
static function import ($alias, $ Forceinclude=false)//class Import public
    
static function createcomponent ($config)//Create component public
    
static function Setapplication ($app)  //Create Instance of Class Yii::app ()

Two automatic loading mechanism

There are more important yii automatic loading mechanism, at the end of Yiibase referenced PHP standard library function Spl_autoload_register (array (' yiibase ', ' autoload ')) invoke the AutoLoad method in the frame

/** * Class autoload loader.
     * This are provided to be invoked within a __autoload () Magic method. * @param string $className class name * @return Boolean whether the class has been loaded successfully/PU Blic static function AutoLoad ($className) {//use include So, the error PHP file may appear if
        Set (self:: $classMap [$className])) include (self:: $classMap [$className]);
        else if (isset (self::$_coreclasses[$className)) include (yii_path.self::$_coreclasses[$className]);  else {//include class file relying on Include_path if (Strpos ($className, ' \ \ ') ===false)
                    Class without namespace {if (self:: $enableIncludePath ===false) { foreach (self::$_includepaths as $path) {$classFile = $path. Directory_separator. $className.
                        PHP '; if (iS_file ($classFile)) {include ($classFile);
                        Break else include ($className. ').
            php '); else//class name with namespace in PHP 5.3 {$namespace =str_replace (' \ \ ', '. ')
                , LTrim ($className, ' \ n ')); if ($path =self::getpathofalias ($namespace))!==false) include ($path. ').
                php ');
            else return false; Return Class_exists ($className, false) | |
        Interface_exists ($className, false);
    return true; }

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.