PHP的yaf框架类加载机制

代码

  1. 注册ini设置到global_library变量(yaf.c)
STD_PHP_INI_ENTRY("yaf.library", "",  PHP_INI_ALL, OnUpdateString, global_library, zend_yaf_globals, yaf_globals)
  1. 把global_library和local_library都传递给了loader的初始化方法(yaf_application.c)
if (YAF_G(local_library)) {
		zend_string *global_library = strlen(YAF_G(global_library))?
			zend_string_init(YAF_G(global_library), strlen(YAF_G(global_library)), 0) : NULL;
		loader = yaf_loader_instance(&zloader, YAF_G(local_library), global_library);
		if (global_library) {
			zend_string_release(global_library);
		}
	} else {
		zend_string *local_library, *global_library;
		local_library = strpprintf(0, "%s%c%s", ZSTR_VAL(YAF_G(directory)), DEFAULT_SLASH, YAF_LIBRARY_DIRECTORY_NAME);
		global_library = strlen(YAF_G(global_library))?
			zend_string_init(YAF_G(global_library), strlen(YAF_G(global_library)), 0) : NULL;
		loader = yaf_loader_instance(&zloader, local_library, global_library);
		zend_string_release(local_library);
		if (global_library) {
			zend_string_release(global_library);
		}
	}

这里的local_library指的是application.ini文件中设置的application.library 的值

如果没有设置application.library,就用application目录下的library作为local_library,就是常量YAF_LIBRARY_DIRECTORY_NAME定义的目录。

  1. yaf_loader_instance逻辑(yaf_loader.c)
    yaf_loader_instance有三个参数,loader的指针,本地类地址和全局类地址
if (library_path) {
			zend_update_property_str(yaf_loader_ce,
					instance, ZEND_STRL(YAF_LOADER_PROPERTY_NAME_LIBRARY), library_path);
		}

		if (global_path) {
			zend_update_property_str(yaf_loader_ce,
					instance, ZEND_STRL(YAF_LOADER_PROPERTY_NAME_GLOBAL_LIB), global_path);
		}

两个地址一起注册到yaf_loader_ce。

conclusion

定义的位置不影响加载效率。

你可能感兴趣的:(php,yaf)