Skip to content

Commit

Permalink
[MOD] update get client service
Browse files Browse the repository at this point in the history
lcp0578 committed Jul 23, 2017
1 parent d3a543d commit 4450496
Showing 6 changed files with 42 additions and 22 deletions.
13 changes: 0 additions & 13 deletions Controller/DefaultController.php

This file was deleted.

16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
Aliyun OSS Bundle for Symfony3

## Installation
============

### Step 1: Download the Bundle
---------------------------
@@ -46,4 +45,17 @@ class AppKernel extends Kernel
}
```
## Usage
============
```php

/**
*
* @var $arService \KitBaseBundle\Service\VoidarService
*/
$ossService = $this->get('kit_oss.oss_client_service');
$ossClient = $ossService->getClient($accessKeyId, $accessKeySecret, $endpoint);
$bucketListInfo = $ossClient->listBuckets();
$bucketList = $bucketListInfo->getBucketList();
foreach($bucketList as $bucket) {
dump($bucket->getLocation() . "\t" . $bucket->getName() . "\t" . $bucket->getCreatedate() . "\n");
}
```
3 changes: 0 additions & 3 deletions Resources/config/routing.yml

This file was deleted.

5 changes: 2 additions & 3 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
services:
# kit_oss.example:
# class: Kit\OssBundle\Example
# arguments: ["@service_id", "plain_value", "%parameter%"]
kit_oss.oss_client_service:
class: Kit\Bundle\OssBundle\Service\OssClientService
1 change: 0 additions & 1 deletion Resources/views/Default/index.html.twig

This file was deleted.

26 changes: 26 additions & 0 deletions Service/OssClientService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace Kit\Bundle\OssBundle\Service;

use OSS\OssClient;
use Symfony\Component\Config\Definition\Exception\Exception;

class OssClientService
{
/**
* get oss client
* @param unknown $accessKeyId
* @param unknown $accessKeySecret
* @param unknown $endpoint
* @throws Exception
* @return \OSS\OssClient
*/
public function getClient($accessKeyId, $accessKeySecret, $endpoint)
{
try{
return new OssClient($accessKeyId, $accessKeySecret, $endpoint);
}catch (\OSS\Core\OssException $e) {
throw new Exception($e->getMessage());
}

}
}

0 comments on commit 4450496

Please sign in to comment.