3 users online. Create an account or sign in to join them.Users
Why aren't the datasources written using oop?
This is an open discussion with 7 replies, filed under General.
Search
Mine are:
require_once(TOOLKIT . '/class.datasource.php');
Class datasourcebiographie extends Datasource{
[...]
}
Not really:
public function grab(&$param_pool){
$result = new XMLElement($this->dsParamROOTELEMENT);
try{
include(TOOLKIT . '/data-sources/datasource.section.php');
}
catch(Exception $e){
$result->appendChild(new XMLElement('error', $e->getMessage()));
return $result;
} if($this->_force_empty_result) $result = $this->emptyXMLSet();
return $result;
}
edit: to clarify, the datasource itself is OO, but it then includes a file in the middle to include specific functionality.
In my eyes, this isn’t very OO, and a better solution would be:
Class datasourcebiographie extends sectionDatasource{
This bugs me, because if I want to change just a little part in the grab function, I would have to either change the database.section.php file, or overwrite the entire grab function.
I think I’d have to agree that including a file in the middle of a class to trigger functionality isn’t great practise.
It strikes me that the functionality in that include could be triggered in other ways, the include doesn’t sit well with me. The same applies with event triggering.
Any of the dev team care to comment on this? Could it be changed for the forthcoming major release?
The strange thing is, changing it isn’t that hard at all..
I have just edited the datasource.tpl file (in symphony/template) to produce an OO version. I simply replaced the class definition with parts of the include function.
It doesn’t work for static DS’s yet, but that shouldn’t be too hard to implement.
This seems to be the way Symphony 2.1 will handle section data sources: http://github.com/czheng/symphony-2/blob/experimental/extensions/ds_sections/templates/datasource.php
Thanks, that’s pretty much my solution aswell.
It’s nice to see symphony getting better and better!
Create an account or sign in to comment.
This has been on my mind for a while now, and everytime I have to create a custom datasource, it annoys me.
Is this something that isn’t fixed in 2.0x to keep older code usable, or is there any other reason?