工厂模式访问静态方法

时间:2013-06-12 12:06:29

标签: php factory

我是工厂模式的新手,并拥有以下工厂方法:

public static function build($class) {
  $class = Helper::str_lreplace("_", "_" . System_Config::getConfig("ef_platform"), $class);
  return new $class;
}

如何使用相同的工厂模式,但是对于静态方法?例如,我有以下方法调用:

   Order_WooExport::registerActions();
   Order_WooExport::registerFilters();

但我想打电话:

   Order_WPExport::registerActions();
   Order_WPExport::registerFilters();

取决于System_Config::getConfig("ef_platform");

的值

1 个答案:

答案 0 :(得分:0)

如果str_lreplace("_", "_" . System_Config::getConfig("ef_platform")为您提供了要使用的类名,并且假设您使用的是PHP 5.3+,则可以尝试使用forward_static_call或类似名称:

$class = str_lreplace("_", "_" . System_Config::getConfig("ef_platform");
forward_static_call(array($class, 'registerActions'));
forward_static_call(array($class, 'registerFilters'));
相关问题