Yii2 Framework Essay 21

Source: Internet
Author: User

Take a look at baseyii.php today.

<?PHP/** * @linkhttp://www.yiiframework.com/* @copyright Copyright (c) Yii software LLC * @licensehttp://www.yiiframework.com/license/ */namespaceYii;use yii\Base\invalidconfigexception;use yii\Base\invalidparamexception;use yii\Base\unknownclassexception;use yii\log\logger;use Yii\di\container;/** Gets the application start timestamp. * Define when the project starts*/defined ('Yii_begin_time') or define ('Yii_begin_time', Microtime (true));/** * This constant defines the framework installation directory. * Define the file address of the YII2 project*/defined ('Yii2_path') or define ('Yii2_path', __dir__);/** * This constant defines whether the application should is in debug mode or not. Defaults to False. * Defines if the Debug of Yii is turned on*/defined ('Yii_debug') or define ('Yii_debug',false);/** * This constant defines in which environment the application is running. Defaults to ' prod ', meaning production environment. * Define this constant in the bootstrap script. The value could be ' prod ' (production), ' Dev ' (development), ' test ', ' staging ', etc. * Defines the environment for YII, whose value can be ' prod ' (productio n), ' Dev ' (development), ' test ', ' staging ' and more*/defined ('yii_env') or define ('yii_env','prod');/** * Whether the the application is running in production environment * project is running in production environment*/defined ('Yii_env_prod') or define ('Yii_env_prod', yii_env = = ='prod');/** * Whether the the application is running in development environment * project is running in development environment*/defined ('Yii_env_dev') or define ('Yii_env_dev', yii_env = = ='Dev');/** * Whether the the application is running in testing environment * Project is running in testing environment*/defined ('yii_env_test') or define ('yii_env_test', yii_env = = ='Test');/** * This constant defines whether error handling should is enabled. Defaults to True. * Define whether to turn on error handler*/defined ('Yii_enable_error_handler') or define ('Yii_enable_error_handler',true);/** * Baseyii is the Core helper class for the YII framework. * Does not use Baseyii directly. Instead, use it child class [[\yii]] which you can replace to * customize methods of Baseyii. * * @author Qiang Xue <[email protected]> * @since 2.0*/ classbaseyii{/** * @var array class map used by the Yii autoloading mechanism.  * The array keys are the class names (without leading backslashes), and the array values * is the corresponding class File paths (or path aliases).     This property mainly affects * how [[AutoLoad ()]] works. * @see AutoLoad ()*/     Public Static$classMap = []; /** * @var \yii\console\application|\yii\web\application the application instance * Yii example of application, Yii's Components are used in this instance.*/     Public Static$app; /** @var Array registered path aliases * @see Getalias () * @see Setalias () * Yii's path alias Map, default @yii refers to To the current directory*/     Public Static$aliases = ['@yii'=__dir__]; /** * Returns A String representing the current version of the YII framework.     * Returns a String representing the current version of the YII framework. * @return String The version of the YII framework*/     Public Staticfunction GetVersion () {return '2.0.3'; }    /** * Translates a path alias into an actual path. * Convert aliases to Real paths **/      Public Staticfunction Getalias ($alias, $throwException =true)    {        /** * strncmp-binary security compare several characters at the beginning of a string * int strncmp (string $str 1, String $str 2, int $len) * AS $alias not start with ' @ ', it's not a Yii alias*/        if(STRNCMP ($alias,'@',1)) {            //Not an alias            return$alias; }        //Get/Position first appeared in the $alias$pos = Strpos ($alias,'/'); //if/does not exist, $root is the entire $alias, otherwise it is $alias in/before the content$root = $pos = = =false? $alias: substr ($alias,0, $pos); //If there are $root aliases        if(Isset (Static:: $aliases [$root]) {            if(Is_string (Static:: $aliases [$root]) {                //if $root the corresponding alias is a string, it is returned directly $aliases [$root] or $aliases [$root]. substr ($alias, $pos)//when the $root is $alias return $aliases [$root], the remaining string is $alias after the $root is removed on the stitching                return$pos = = =false?Static:: $aliases [$root]:Static:: $aliases [$root]. substr ($alias, $pos); } Else {                //Otherwise, to traverse the entire $aliases [$root] array, find the same value $name as $alias, and return $path. substr ($alias, strlen ($name))//is actually returned $path stitching on $alias After removing the $root, the remainder of the string                foreach(Static:: $aliases [$root] as$name =$path) {                    if(Strpos ($alias.'/', $name.'/') ===0) {                        return$path. substr ($alias, strlen ($name)); }                }            }        }        if($throwException) {Throw NewInvalidparamexception ("Invalid Path alias: $alias");//Throw hint}Else {            return false; }    }

Yii2 Framework Essay 21

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.