-
Notifications
You must be signed in to change notification settings - Fork 5
/
Main.php
56 lines (45 loc) · 1.62 KB
/
Main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace IdnoPlugins\S3 {
use \Idno\Common\Plugin;
use \Aws\S3\S3Client;
class Main extends Plugin {
public $_s3client;
function registerTranslations()
{
\Idno\Core\Idno::site()->language()->register(
new \Idno\Core\GetTextTranslation(
's3', dirname(__FILE__) . '/languages/'
)
);
}
function registerEventHooks() {
$config = \Idno\Core\Idno::site()->config();
// All of this only makes sense if we have an aws_key and aws_secret
if (!empty($config->aws_key)
&& !empty($config->aws_secret)
&& !empty($config->aws_bucket)) {
if (empty($config->aws_region)) {
$region = 'us-east-1';
} else {
$region = $config->aws_region;
}
$params = array(
'credentials' => [
'key' => $config->aws_key,
'secret' => $config->aws_secret,
],
'region' => $region,
'version' => 'latest',
);
if (!empty($config->aws_base_url)) {
$params['base_url'] = $config->aws_base_url;
}
if (!empty($config->aws_suppress_region)) {
unset($params['region']);
}
$this->_s3client = S3Client::factory($params);
$this->_s3client->registerStreamWrapper();
}
}
}
}