[Vtigercrm-developers] Vtiger Class Loader?
Hamono, Chris (DPC)
Chris.Hamono at sa.gov.au
Thu Jul 16 04:42:30 GMT 2015
This is the hackiest hack I have ever done... and I have done a few
The problem: Replace a core class with my own custom class at runtime
The Solution (not overly tested) ...
Change /index.php and add the following after the last include statement
// do this as late as possible
require_once ('modules/yourmod/__autoload.php');
Create modules/yourmod/__autoload.php :-
<?php
define('MODULESPATH', realpath(dirname(__FILE__) . '/../') . '/');
// create our own autoloader
function my_autoloader($class) {
if ($class === "Users_Record_Model"){
return require_once MODULESPATH . "mymod/modules/Users/models/Record.php";
}
return false;
}
spl_autoload_register('my_autoloader',true,true);
?>
Create mymod/modules/Users/models/Record.php :-
<?php
// replace the users record model with our own
$path = MODULESPATH . 'Users/models/Record.php';
$stuff = file_get_contents($path);
$newstuff = str_replace('Users_Record_Model','orig_Users_Record_Model' , $stuff);
eval(' ?>' . $newstuff);
class Users_Record_Model extends orig_Users_Record_Model {
...
classy stuff
...
}
?>
Voila
I would strongly recommend against using this hack. It was just an experiment...
Chris
On 14/07/15 06:45, Prasad wrote:
> Would prepending
> <http://php.net/manual/en/function.spl-autoload-register.php> the
> custom loader help?
That's really quite interesting... Worth a test certainly.
Thanks.
Alan
_______________________________________________
http://www.vtiger.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20150716/96ca30d5/attachment.html>
More information about the vtigercrm-developers
mailing list