我目前正在处理第三方库,该库在全局命名空间中定义全局用户名/密码常量。我不想在需要连接不同凭证(即多个集合)的同时修改库源代码。因此,编辑库源代码不是解决方案。老实说,即使没有这个要求,修改第三方库源代码也不是一个好习惯,因为它可能会在更新时导致意外结果。
define('OSRS_USERNAME', $credentials[self::USERNAMETAG]);
define('OSRS_KEY', $credentials[self::PASSWORDTAG]);
$host = isset($credentials['testmode']) ? self::TESTHOST : self::LIVEHOST;
define('OSRS_HOST', $host);
define('OSRS_SSL_PORT', self::PORT);
//only now we can require the openSRS loader as it otherwise would define other values as contants for username & password
//@ is here to supress warnings about redefining the credentials constants in the 3rd party config file
//this is safe as just including the file shoould not throw if the script does not have any syntax errors
@require_once('OpenSRS/openSRS_loader.php');
然而,这仍然在CLI中输出警告
有没有办法压制这些警告?
答案 0 :(得分:0)
这是他们的配置文件:
https://github.com/OpenSRS/osrs-toolkit-php/blob/master/opensrs/openSRS_config.php.template
从他们的文档中,您可以在重命名的副本中定义这些常量。
检查您的dist是否有名为openSRS_config.php