dynamicaly append method to class - workaround for aggregate_methods()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Hello list!

I am using in my application dynamic method appending to class with aggregate_methods() function. But this function is no more aviable in php5 and runkit extension seems not to be maintained any more. So I would like to replace it with something more common (__call method or so).

Just to describe the situation (simplified). There is one common class containing some common functions:

class DataLayer{

    function add_method($method){
        aggregate_methods($this, "DataLayer_".$method);
    }

    function common_funct_foo(){
        ...
    }

    function common_funct_bar(){
        ...
    }
}


And there is hundreds of data manipulation methods (defined within separate classes) which could call common functions. E.g.:


class DataLayer_get_items{
    function get_items(){
        $this->common_funct_foo();
        return something;
    }
}

And they could also call other dynamicaly added methods:

class DataLayer_update_attr{
    function update_attr(){
        $this->get_items();
        $this->common_funct_bar();
        return;
    }
}

All the stuff is used e.g. in this way:

$data = new DataLayer();
$data->add_method('get_items');
$data->add_method('update_attr');
$data->update_attr();



Now the question is whether is it possible to somehow replace functionality of add_method() without aggregate_methods() or runkit_class_adopt(). And _WITHOUT_ need to change the hundreds of DataLayer_* classes. The change should be only in the main DataLayer class. I was thinking about __call() method, but I do not know how to deal with the $this in dynamicaly appended functions. I need somehow make to $this in these functions reference to instance of DataLayer class.

Any ideas?

many thanks,
Karel


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux