[Vtigercrm-developers] API Developers
apcloic
apcloic at gmail.com
Tue May 10 08:44:36 GMT 2016
I've just read this :
https://www.yetiforce.com/en/developer-documentation/engine/177-loader-and-autoloader-of-files.html
So, I've made a quick test by modifying /includes/Loader.php
I only add $loaderDirs var and do a little mod on autoload($classes)
function at the end of the file and it starts working immediatly ;)
With this modification, I'm able to easily override core files or standard
module files.
Can't believe it's that simple ?!
Is there anything wrong with this change ?
Regards,
class Vtiger_Loader {
protected static $includeCache = array();
protected static $includePathCache = array();
protected static $loaderDirs = array('custom.modules.','modules.',);
...
..
.
/**
* Function to auto load the required class files matching the directory
pattern modules/xyz/types/Abc.php for class xyz_Abc_Type
* @param <String> $className
* @return <Boolean>
*/
public static function autoLoad($className) {
$parts = explode('_', $className);
$noOfParts = count($parts);
if($noOfParts > 2) {
$filePath = 'modules.';
foreach (self::$loaderDirs as $filePath) {
// Append modules and sub modules names to the path
for($i=0; $i<($noOfParts-2); ++$i) {
$filePath .= $parts[$i]. '.';
}
$fileName = $parts[$noOfParts-2];
$fileComponentName = strtolower($parts[$noOfParts-1]).'s';
$filePath .= $fileComponentName. '.' .$fileName;
if (file_exists(self::resolveNameToPath($filePath))) {
return Vtiger_Loader::includeOnce($filePath);
}
}
}
return false;
}
}
--
View this message in context: http://vtiger-crm.2324883.n4.nabble.com/Vtigercrm-developers-API-Developers-tp16531p19019.html
Sent from the vtigercrm-developers mailing list archive at Nabble.com.
More information about the vtigercrm-developers
mailing list