我有一个像这样的静态类。
<?php
class Language
{
public static $language = array();
var $config;
function __construct($config)
{
switch(strtoupper($config['LANGUAGE']))
{
case 'ENGLISH':
self::setEnglish();
break;
case 'TURKISH':
self::setTurkish();
break;
default:
self::setEnglish();
}
}
public static function setEnglish()
{
self::$language = array(
'CHAIN_VALIDATOR_INITIALIZED' => 'ChainValidator initialized!',
'ERROR_FUNCTION_RETURNED_FALSE' => 'A function returned false.',
);
}
public static function setTurkish()
{
self::$language = array(
'CHAIN_VALIDATOR_INITIALIZED' => 'ChainValidator çalışıyor!',
'ERROR_FUNCTION_RETURNED_FALSE' => 'Bir fonksiyon false döndürdü.',
);
}
public static function getLanguage($key)
{
return isset(self::$language[$key]) ? self::$language[$key] : $key;
}
}
?>
它被这样使用,
Language::getLanguage('CHAIN_VALIDATOR_INITIALIZED')
但我必须传递更多参数。与此类似,
Language::getLanguage('CHAIN_VALIDATOR_INITIALIZED', array(__FUNCTION__))
这些参数应该按顺序传递,例如 %s。最终外观应如下所示:
"A function returned false" to;
"%s function returned false"
And output would be;
"myLovelyFunction() returned false" (the first array parameter, which is __FUNCTION__)
听起来像是小菜一碟,我的大脑停止了 atm。
我怎样才能做到这一点?