我正在摆弄这个问题但无法解决它 - 只是想检查这里是否有人可以提供帮助
我正在加载类并像这样调用构造函数
include_once './Myaws.php';
$aws = new Myaws();
$aws->bucket = $images['config']['bucket'];
Myaws.php如下
class Myaws {
public $bucket;
function __construct() {
$this->aws = Aws::factory('./config/aws_config.php');
}
}
它就像一个魅力!
现在问题
'./config/aws_config.php'只是一个根据部署阶段而改变的数组 - 所以我想让它变得动态。这是我做的,它不起作用
include_once './Myaws.php';
$aws = new Myaws();
$aws->bucket = $images['config']['bucket'];
$aws->config = $images['config']['awsconfig'];
在Myaws.php中,我更改了以下内容
class Myaws {
public $bucket;
public $config;
function __construct() {
$this->aws = Aws::factory($this->config);
}
}
它不起作用:(以及下面的一个
include_once './Myaws.php';
$aws = new Myaws($images['config']['awsconfig']);
$aws->bucket = $images['config']['bucket'];
class Myaws {
public $bucket;
function __construct($config) {
$this->aws = Aws::factory($config);
}
}
这是非常基本的哎呀,我觉得我似乎没有得到它。任何人都可以建议我如何使变量$ config动态化?
答案 0 :(得分:3)
我发现所包含文件与传递数组中的格式不是100%兼容。另请在api文档中查看他们如何使用my_profile传递这些凭据。
这是我用于生成配置
的当前方法的示例$aws = Aws::factory($this->getAwsConfig());
private function getAwsConfig()
{
return array(
// Bootstrap the configuration file with AWS specific features
'credentials' => array(
'key' => $this->awsKey,
'secret' => $this->awsSecret
),
'includes' => array('_aws'),
'services' => array(
// All AWS clients extend from 'default_settings'. Here we are
// overriding 'default_settings' with our default credentials and
// providing a default region setting.
'default_settings' => array(
'params' => array(
'region' => $this->awsRegion
)
)
)
);
}