PHPCMS v9 Source Analysis-2 base.php

Source: Internet
Author: User

Original link: https://www.cnblogs.com/Hebe0115/p/3484975.html


As already mentioned, base.php is an important file in the PC, the basic constants, and the loading of the core class files are done by it.

9 lines, defines a constant in_phpcms, defines a constant at the entrance of the system, and in other files determines whether the constant is defined, preventing someone from going directly across the frame and directly into certain pages,

This constant in the following modules, model operation files will exist, in the future when the development of friends in strict accordance with this requirement and norms.

12-26 lines, mainly defines a number of constants, here is mainly the use of $_server this server variable, print this array will know.

Http_referer This constant is often used later, as long as it is used to return to the superior, often very showmessage in the PC. such as ShowMessage (' parameter error ', Http_referer);

Sys_start_time is here to prepare for the execution efficiency of the following program, which is combined with the Execute_time () function in the No. 260 line of the system function/phpcms/libs/functions/global.func.php. The execution time of the program can be obtained.

27-60 lines, basically can not talk about it, because it basically and pc_base this PC's core class, we temporarily put this piece here, chatted over pc_base This class, these pieces of code will be able to understand,

Pc_base This class too long, also can not be a good screenshot, then I directly to the number of lines to locate the coordinates, convenient for everyone to read.

Pc_base is a class file, about this class we need to clear the static method and static variables, do not understand a friend to first evil, otherwise it will be difficult to understand.

Pc_base This class inside the method many are similar, we take several typical methods to axe, he is load_sys_class. (The following code explains the Cnblogs code editor, so students want to open the original code to align the number of lines)

    /**
     * Load System class Method
     * @param string $classname class name
     * @param string $path extended address
     * @param intger $initialize initialization 
  */public
    static function Load_sys_class ($classname, $path = ', $initialize = 1} {return
            Self::_load_class ($ ClassName, $path, $initialize);
    }

76-78 lines, as you can see from the annotations, the three parameters of the Load_sys_class method are class names, paths, and whether they are instantiated. At the same time, the 3 variables were passed into the _load_class method, then _load_class is the method we need to focus on.

    /** * Load class file function * @param string $classname class name * @param string $path extended address * @param Intger $initialize Initialize/private static function _load_class ($classname, $path = ', $initialize = 1} {static $classes
        = Array (); if (empty ($path)) $path = ' libs '.

        Directory_separator. ' Classes ';
        $key = MD5 ($path. $classname);
            if (Isset ($classes [$key])) {if (!empty ($classes [$key])) {return $classes [$key];
            else {return true; } if (File_exists (Pc_path. $path. Directory_separator. $classname. Class.php ')) {include Pc_path. $path. Directory_separator. $classname.
            Class.php ';
            $name = $classname; if ($my _path = Self::my_path (Pc_path. $path. Directory_separator. $classname.
                Class.php ')) {include $my _path;
            $name = ' my_ '. $classname; } if ($initialize) {$classes[$key] = new $name;
            else {$classes [$key] = true;
        return $classes [$key];
        else {return false; }
    }

107 lines, static variables, I do the project to use the static is mainly two aspects of 1, arithmetic add 2, judge whether repeat.
108 lines, if $path is empty, then the path is libs/class/this directory, and this is the system's class library, the development process can put the third party class library here.

110 lines, encrypted the path and name, not yet know the role, we look down first.
111-117 line, the judge set the $classes[$key], the current procedure to come here, this judgment is false, but the specific role we do not know, first put, continue to look down.

113-114 lines, if the file exists, then load it.
115-118 lines, this is mainly to determine whether there is a way to prevent the upgrade error.
117-121 line, here $initialize to initialize this class, and assign value to $classes[$key], see here you should understand why 111-117 lines to make this judgment. If the variable is worth saying that it has already been loaded, it is not repeated loading to ensure execution efficiency. Here's a little bit more, the difference between variable $initialize = 0 or 1 is whether you are inheriting or using the inside method after loading the class file.

This method is finished here, mainly loading the class file you specified, and if the file has already been loaded, do not repeat the load, and then perform the initialization of the operation.

Load_sys_class ($classname, $path = ', $initialize = 1)/phpcms/libs/classes/$classname. class.php

Load_app_class ($classname, $m = ', $initialize = 1)/phpcms/modules/route_m/classes/$classname. class.php

Load_model ($classname)/phpcms/model/$classname. class.php

Load_sys_func ($func)/phpcms/libs/functions/$func. func.php

Load_app_func ($func, $m = ') If $m is an empty/phpcms/modules/route_m/functions/$func. func.php Otherwise/phpcms/modules/$m/functions/$func. func.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.