Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 访问静态方法的工厂模式_Php_Factory - Fatal编程技术网

Php 访问静态方法的工厂模式

Php 访问静态方法的工厂模式,php,factory,Php,Factory,我不熟悉工厂模式,并采用以下工厂方法: public static function build($class) { $class = Helper::str_lreplace("_", "_" . System_Config::getConfig("ef_platform"), $class); return new $class; } 除了静态方法外,如何使用相同的工厂模式?例如,我有以下方法调用: Order_WooExport::registerActions();

我不熟悉工厂模式,并采用以下工厂方法:

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_平台”)的值

提供了
str_lreplace(““,““)。System_Config::getConfig(“ef_platform”)
提供了您想要使用的类名,如果您使用的是PHP 5.3+,您可以尝试或类似的方法:

$class = str_lreplace("_", "_" . System_Config::getConfig("ef_platform");
forward_static_call(array($class, 'registerActions'));
forward_static_call(array($class, 'registerFilters'));
静态工厂(以及真正静态的任何东西)是一个反模式。创建一个可实例化的工厂类,该类可以被注入,因为这提供了松散耦合。如果您想为某些内容键入提示,请使用接口。。