In oxid esales everybody likes to extend everything.
Its a bunch of happy ox-classes that just love each other, hug eachother and extend, make out the whooooooole day.
A simple example
oxI18n extends oxBase extends oxSuperCfg
Ok, I understand that you want every happy oxid-super-object to be able to read, write, delete the config, right?
But what the heck are you doing? Did you guys ever hear about design patterns?.
Maybe you should take a look at our friends from pureMVC. They have their patterns well organized in an extra folder:

It gets even better: The Super-Extender
When you want to create an oxoutput object with the following??modules?? loaded:
sub/suboutput1&sub/suboutput2&sub/suboutput3
it magically creates / extends / parties with your classes!
It uses a kind of extension g*ngb*ng function to hook up everyone with everything:
public function getClassName( $sClassName )
{
$aModules = $this->getConfig()->getConfigParam( 'aModules' );
if ( is_array( $aModules ) &&
array_key_exists( $sClassName, $aModules ) ) {
//multiple inheritance implementation
//in case we have multiple modules:
//like oxoutput
//=> sub/suboutput1&sub/suboutput2&sub/suboutput3
$aClassChain = explode( "&", $aModules[$sClassName] );
$sParent = $sClassName;
//security: just preventing string termination
$sParent = str_replace(chr(0), '', $sParent);
//building middle classes if needed
$sClassName =
$this->_makeSafeModuleClassParents( $aClassChain, $sParent );
}
// check if there is a path, if yes, remove it
$sClassName = basename( $sClassName );
return $sClassName;
}
....
/**
* Creates middle classes if needed.
*
* @param array $aClassChain Module names
* @param string $sBaseModule Oxid base class
*
* @throws oxSystemComponentException missing system
* component exception
*
* @return string
*/
private function _makeSafeModuleClassParents( $aClassChain, $sBaseModule )
{
$myConfig = $this->getConfig();
$sParent = $sBaseModule;
//building middle classes if needed
foreach ($aClassChain as $sModule) {
//creating middle classes
//e.g. class suboutput1_parent extends oxoutput {}
// class suboutput2_parent extends suboutput1 {}
//$sModuleClass = $this->getClassName($sModule);
//security: just preventing string termination
$sModule = str_replace(chr(0), '', $sModule);
//get parent and module class names from sub/suboutput2
$sParentClass = basename($sParent);
$sModuleClass = basename($sModule);
//P
//$sInitClass = "class ".$sModuleClass."_parent extends $sParentClass
//{ function ".$sModuleClass."_parent(){
// return ".$sParentClass."::".$sParentClass."();} }";
$sInitClass = "class ".$sModuleClass."_parent extends $sParentClass {}";
//initializing middle class
if (!class_exists($sModuleClass."_parent", false)) {
eval($sInitClass);
}
$sParentPath = $myConfig->getConfigParam( 'sShopDir' ).
"/modules/".$sModule.".php";
//including original file
if ( file_exists( $sParentPath ) ) {
require_once $sParentPath;
} elseif ( !class_exists( $sModuleClass ) ) {
//to avoid problems with unitest and only throw a
// exception if class does not exists MAFI
$oEx = new oxSystemComponentException();
$oEx->setMessage('EXCEPTION_SYSTEMCOMPONENT_CLASSNOTFOUND');
$oEx->setComponent($sModule);
}
$sParent = $sModule;
}
//returning the last module from the chain
$sClassName = $aClassChain[count($aClassChain) - 1];
return $sClassName;
}
So … with all the magic party stuff you end up having created / included these classes, all done by their wonderful __autload function:
- class oxoutput extends oxSuperCfg { … }
- class suboutput1_parent extends oxoutput {}
- class suboutput2_parent extends suboutput1 {}
- class suboutput3_parent extends suboutput2 {}
But what the hell is this stuff for?
A module like MyOrder extends MyOrder_parent. For what? Somebody enlighten me!
You extend non-existing classes just for the sake of creating them from the magic __autoload function, is that it?
Related post:
oxid esales – show me your 94% Unit Test coverage!