Php import module file sharing. Php import module file sharing this article shares with you the php import module file sharing. The main parameters include the import file path string, which can be used. extension of the imported file type (file sharing with the php import module ).
This article shares with you the php import module files. The main parameters include the import file path string, which can be used ". "In place of"/", the extension of the imported file type (". "), or class/inc (abbreviated). If the import is successful, true is returned. Otherwise, an exception object is returned. For more information, see.
The code is very simple. you just need to pay attention to the comments.
The code is as follows:
/**
* Import module files
*
* @ Param string $ classString the path string of the imported file. you can use "." instead "/"
* @ Param string $ fileType indicates the extension of the file type to be imported (with the "." number), or class/inc)
* @ Return Exception if the import is successful, true is returned; otherwise, an Exception object is returned.
*
* @ Example
* ImportModule ('gapi. account') => include_once ('Les les/gapi/Account. class. php ');
*/
Function importModule ($ classString, $ fileType = 'class ')
{
$ Filename = $ module_path. strtr ($ classString ,'.','/');
Switch ($ fileType ){
// Import a class file
Case 'class': $ filename. = '. class. php'; break;
// Import the inclusion file
Case 'INC': $ filename. = '. inc. php'; break;
// Customize the extension of the imported file
Default: $ filename. = $ fileType; break;
}
If (is_file ($ filename ))
{
Include_once ($ filename );
}
Else
{
Exit ('class "\ '. strtr ($ classString,'. ',' \ ').'" is not found .');
}
}
The above is the code shared in this article. I hope you will like it.
In this article, we will share with you the php import module file. The main parameters include the import file path string, which can be replaced by./and the extension of the import file type (...