xLink / CybershadeCMS

[Abandoned][Broke] Repo for CybershadeCMS
1 stars 0 forks source link

Object instantiation #26

Closed MantisSTS closed 11 years ago

MantisSTS commented 11 years ago

I propose we add a new method of object instantiation, rather than having multiple methods to instantiate the object required, we have 1 method which does it. Ie:

    public function getObject(){
        $arguments = func_get_args();

        if( is_empty( $arguments ) ){
            return false;
        }

        $class = array_shift($arguments);

        if(!isset( coreObj::$_classes[$class] )){
            $class::getInstance($class, $arguments);
        }

        return coreObj::$_classes[$class];
    }

That was just a quick mock up, but you get the point.

The reason I propose this is to clean up the coreObj class, as atm its a mess.

xLink commented 11 years ago

theres already one in there if you look, thing is, theres a fair few of em that cant be done like that, cause of the way we set it up, eg DBO & TPL, but the rest of em can use coreObj::getInstance()

MantisSTS commented 11 years ago

Then why do we keep adding in seperate functions for each individual new class?

xLink commented 11 years ago

consistency i suppose

MantisSTS commented 11 years ago

Imo we should still be using something like the above, so we keep everything consistant and clean.

There is no reason why you cant write a function which has all that in there, even if it is a case of having switch/cases in there rather than separate functions

MantisSTS commented 11 years ago

I guess this is out of disccusion so closing it.

NoelDavies commented 11 years ago

Why is it out of discussion? If you can create a PoC and get it working, then go for it.

xLink commented 11 years ago

Fixed - https://github.com/cybershade/CSCMS/blob/master/core/classes/class.coreobj.php#L372 Used __callStatic() to determine if we are wanting a get*() method, if that comes back as true && ( classExists && no method exists in coreObj for it ){ then init the obj & call to the method with the args }