Is it possible to override a function dynamically in Zend?
class My_Core_Default_Api extends Zend_Mail_Transport_Sendmail
{
public function getApi()
{
echo "Old Api";
}
}
class My_Core_New_Api extends Zend_Mail_Transport_Sendmail
{
public function getApi()
{
echo "New Api";
}
}
Here I would like to override Core_Default_Api->getApi()
with Core_New_Api->getA开发者_JAVA百科pi()
. Any suggestions please
class My_Core_New_Api extends My_Core_Default_Api {
public function getApi()
{
echo "New Api";
// if you'd like to also include functionality of parent class
My_Core_Default_Api::getApi();
}
}
It's not real "Zend" question. It's more PHP & design patterns question.
Problem would be that you would need to switch the instances of the Mail Transport - you're looking for Dependency injection, maybe.... or Proxy or Facade design pattern. You need ONE PLACE where you will switch the class and it will change everywhere else. I'd set that in config and have a class that loads propper class name from config and returns new instance... something like this:
TransportSelector::getTransport()->send($mail);
精彩评论