Page 1 of 1

Extending class in application level

PostPosted: Tue Jan 05, 2010 3:22 pm
by kevinwen
I want to extend the class under framework in my application so I can have my own customization with changing anything in the framework, and I won't have any problem doing framework upgrade in the future. Does anybody know how to do it? Thanks. For example, I want to create a file (MyHistoryTool.php) doing the following:

class MyHistoryTool extends Dataface_HistoryTool {
function myfunc() {
return 'Hello World!';
}

function getHistoryLog(&$record, $lang=null, $limit=100){ //override the function in parent class
echo "this is the new history log";
}
}

In which folder under my application should I put this MyHistoryTool.php? Does anybody know? If it's possible to do so, how do I use these new/overriding function and integrate with those templates in Dataface/templates?

Re: Extending class in application level

PostPosted: Tue Jan 05, 2010 9:35 pm
by shannah
Unfortunately this isn't easy to do. Ideally you want to make use of the Factory design pattern but Xataface doesn't use this pattern currently.

One option is to exploit Xataface's include directory order of lookup and just override the HistoryTool class. Xataface will look in the following locations for its classes, in this order:

1. . (i.e. current directory).
2. xataface (i.e. the xataface directory)
3. xataface/lib

Do if you were to add a directory named 'Dataface' (capitals count) into your application directory, and place your modified HistoryTool.php file into that directory, your application would use your version instead of the one with the Xataface distribution. Then you only need to worry if there are changes made to the HistoryTool when you update Xataface (and you can always run a diff or a merge on that file to ensure that all is ok).

-Steve