@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php namespace AwsHelper; |
| 2 | 2 | |
| 3 | 3 | use Aws\S3\S3Client; |
| 4 | -use Aws\S3\Exception\S3Exception; |
|
| 5 | 4 | |
| 6 | 5 | class S3Helper |
| 7 | 6 | { |
@@ -45,8 +45,9 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function saveFile($file_location, $s3_location, $acl = 'private', $params = []) |
| 47 | 47 | { |
| 48 | - if ($this->s3 == null) |
|
| 49 | - return false; |
|
| 48 | + if ($this->s3 == null) { |
|
| 49 | + return false; |
|
| 50 | + } |
|
| 50 | 51 | |
| 51 | 52 | $this->getClient(); |
| 52 | 53 | |
@@ -72,8 +73,9 @@ discard block |
||
| 72 | 73 | */ |
| 73 | 74 | public function saveFileContent($file_content, $s3_location, $acl = 'private', $params = []) |
| 74 | 75 | { |
| 75 | - if ($this->s3 == null) |
|
| 76 | - return false; |
|
| 76 | + if ($this->s3 == null) { |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 77 | 79 | |
| 78 | 80 | $this->getClient(); |
| 79 | 81 | |
@@ -96,8 +98,9 @@ discard block |
||
| 96 | 98 | */ |
| 97 | 99 | public function getFile($s3_location) |
| 98 | 100 | { |
| 99 | - if ($this->s3 == null) |
|
| 100 | - return false; |
|
| 101 | + if ($this->s3 == null) { |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 101 | 104 | |
| 102 | 105 | $this->getClient(); |
| 103 | 106 | |
@@ -106,8 +109,7 @@ discard block |
||
| 106 | 109 | 'Bucket' => $this->bucket_name, |
| 107 | 110 | 'Key' => $s3_location, |
| 108 | 111 | ]); |
| 109 | - } |
|
| 110 | - catch (\Exception $e) |
|
| 112 | + } catch (\Exception $e) |
|
| 111 | 113 | { |
| 112 | 114 | return false; |
| 113 | 115 | } |
@@ -1,7 +1,6 @@ |
||
| 1 | 1 | <?php namespace AwsHelper; |
| 2 | 2 | |
| 3 | 3 | use Aws\Sqs\SqsClient; |
| 4 | -use Aws\S3\Exception\S3Exception; |
|
| 5 | 4 | |
| 6 | 5 | class SqsHelper |
| 7 | 6 | { |
@@ -13,25 +13,30 @@ discard block |
||
| 13 | 13 | public function __construct($iam_role, $iam_url='http://169.254.169.254/latest/meta-data/iam/security-credentials/') |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - if (empty($iam_role)) |
|
| 17 | - throw new \Exception('iam_role is empty'); |
|
| 16 | + if (empty($iam_role)) { |
|
| 17 | + throw new \Exception('iam_role is empty'); |
|
| 18 | + } |
|
| 18 | 19 | |
| 19 | - if (empty($iam_url)) |
|
| 20 | - throw new \Exception('iam_url is empty'); |
|
| 20 | + if (empty($iam_url)) { |
|
| 21 | + throw new \Exception('iam_url is empty'); |
|
| 22 | + } |
|
| 21 | 23 | |
| 22 | 24 | $this->iam_role = $iam_role; |
| 23 | 25 | $this->iam_url = $iam_url; |
| 24 | 26 | |
| 25 | 27 | $json = $this->getAccessData($iam_role, $iam_url); |
| 26 | 28 | |
| 27 | - if ($json->Code !== 'Success') |
|
| 28 | - throw new \Exception('Unsuccessful in returning iam amazon credentials'); |
|
| 29 | + if ($json->Code !== 'Success') { |
|
| 30 | + throw new \Exception('Unsuccessful in returning iam amazon credentials'); |
|
| 31 | + } |
|
| 29 | 32 | |
| 30 | - if (empty($json->AccessKeyId)) |
|
| 31 | - throw new \Exception('AccessKeyId does not exist.'); |
|
| 33 | + if (empty($json->AccessKeyId)) { |
|
| 34 | + throw new \Exception('AccessKeyId does not exist.'); |
|
| 35 | + } |
|
| 32 | 36 | |
| 33 | - if (empty($json->SecretAccessKey)) |
|
| 34 | - throw new \Exception('SecretAccessKey does not exist.'); |
|
| 37 | + if (empty($json->SecretAccessKey)) { |
|
| 38 | + throw new \Exception('SecretAccessKey does not exist.'); |
|
| 39 | + } |
|
| 35 | 40 | |
| 36 | 41 | $this->json = $json; |
| 37 | 42 | } |
@@ -52,14 +57,17 @@ discard block |
||
| 52 | 57 | { |
| 53 | 58 | $json = $this->getJSON(); |
| 54 | 59 | |
| 55 | - if ($json->Code !== 'Success') |
|
| 56 | - throw new \Exception('Unsuccessful in returning iam amazon credentials'); |
|
| 60 | + if ($json->Code !== 'Success') { |
|
| 61 | + throw new \Exception('Unsuccessful in returning iam amazon credentials'); |
|
| 62 | + } |
|
| 57 | 63 | |
| 58 | - if (empty($json->AccessKeyId)) |
|
| 59 | - throw new \Exception('AccessKeyId does not exist. This is possibly a problem with you aws setup.'); |
|
| 64 | + if (empty($json->AccessKeyId)) { |
|
| 65 | + throw new \Exception('AccessKeyId does not exist. This is possibly a problem with you aws setup.'); |
|
| 66 | + } |
|
| 60 | 67 | |
| 61 | - if (empty($json->SecretAccessKey)) |
|
| 62 | - throw new \Exception('SecretAccessKey does not exist. This is possibly a problem with you aws setup.'); |
|
| 68 | + if (empty($json->SecretAccessKey)) { |
|
| 69 | + throw new \Exception('SecretAccessKey does not exist. This is possibly a problem with you aws setup.'); |
|
| 70 | + } |
|
| 63 | 71 | |
| 64 | 72 | if (!empty($json->Token)) |
| 65 | 73 | { |
@@ -103,8 +111,9 @@ discard block |
||
| 103 | 111 | public function hasAccessExpired($date) |
| 104 | 112 | { |
| 105 | 113 | $date = new \DateTime($date); |
| 106 | - if ($date->format('U')-date('U') > 0) |
|
| 107 | - return false; |
|
| 114 | + if ($date->format('U')-date('U') > 0) { |
|
| 115 | + return false; |
|
| 116 | + } |
|
| 108 | 117 | |
| 109 | 118 | return true; |
| 110 | 119 | } |