Basic yaf tutorial (2)-Project instantiation newYaf_Application ()

Source: Internet
Author: User
When we look at the example, we know that the entry program for running the entire program is such a basic yaf tutorial (2)-instantiation of the project newYaf_Application () when we look at the example, we know that the entry program for running the entire program is like this:

$ App = new Yaf_Application (APPLICATION_PATH. "/conf/application. ini ");
$ App-> bootstrap () // call bootstrap methods defined in Bootstrap. php
-> Run ();
Start with new Yaf_Application (). What happens when we use the new class ?? The source code is analyzed. In row 351 of yaf_application.c, the source code of the method is instantiated. we can see that one input parameter and one optional parameter are required.

Zval * config;
Zval * section = NULL;
Then, let's look at the following code:

If (! Section | Z_TYPE_P (section )! = IS_STRING |! Z_STRLEN_P (section )){
// If the optional parameter section is null or is not a string or the string address is null
MAKE_STD_ZVAL (section); // defines the variable
/*
# Define YAF_G (v) TSRMG (yaf_globals_id, zend_yaf_globals *, v)
# Else
# Define YAF_G (v) (yaf_globals.v)
YAF_G is a self-defined macro variable in yaf. h. yaf defined in PHP_INI_BEGIN c. the variable value of environ, which is product by default, is then assigned to section.
*/
ZVAL_STRING (section, YAF_G (environ), 0 );
// Instantiate Config to read configuration information
Zconfig = yaf_config_instance (NULL, config, section TSRMLS_CC );
Efree (section); // releases the memory.
} Else {
// If section instantiation Config is specified, it is used to read configuration information
Zconfig = yaf_config_instance (NULL, config, section TSRMLS_CC );
}
So we can see from the above that we have php. yaf. what is the value of environ? it is set according to our preference. if it is not set, it is the product by default. This should be the case when we compile the configuration file.


[Product]
Application. directory = APP_PATH "/application /"
If the value of yaf. environ is modified, if the value is changed to widuu, and the product is not modified in your configuration file, an error is reported. no section "widuu"


Therefore, when writing a configuration file, we must write the yaf. environ value defined in php. ini as a section. The configuration file of new Yaf_Application () can be a string or an array.


Zconfig = yaf_config_instance (NULL, config, section TSRMLS_CC );
In the yaf_config.c, we can see two types of judgment.


If (Z_TYPE_P (arg1) = IS_STRING) // judge whether it is a string
If (Z_TYPE_P (arg1) = IS_ARRAY) // judge the array
Next, we will parse different types.


// The ini configuration file will be parsed through yaf_config_ini.c in yaf_config_ini_instance
Yaf_config_ini_instance (this_ptr, arg1, arg2 TSRMLS_CC );


// Array parsing will be parsed through yaf_config_simple.c in yaf_config_simple_instance
Yaf_config_simple_instance (this_ptr, arg1, readonly TSRMLS_CC );
Therefore, when new Yaf_Application () is configured, it can be configured as a configuration file or an array. So much is written today, and the rest will come back tomorrow.

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.