Commit ce70390c authored by Pavel Lesnyh's avatar Pavel Lesnyh
Browse files

TRANS-5206.

Обновил пути до хранилища.
Переписал Readme
Showing with 35 additions and 16 deletions
+35 -16
......@@ -3,17 +3,27 @@
Пример конфига:
```
'localization' => [
'class' => localization\components\LocalizationComponent::class,
'login' => 'TestProjectAdmin',
'password' => 'idu183',
'url' => 'http://api.localization.local:125/',
'project_name' => 'test_project',
'yandexObjectStorage' => [
'class' => yandexObjectStorage\components\YandexObjectStorageComponent::class,
'url' => 'http://storage.yandexcloud.net',
'bucket' => 'тут что то',
'awsSecretAccessKey' => 'тут ключ',
'awsAccessKeyId' => 'ID',
'serviceUser' => 'develop',
'region' => 'ru-central1',
],
```
В зависимоти от ST надо переопределять конфиги:
```
'yandexObjectStorage' => [
'directoryProject' => '<projectName>/stage1',
],
```
Где:
1) **class** - это Класс компонета
2) **login** - Логин пользователя проекта
3) **password** - Пароль пользователя
4) **url** - Адрес сервиса локализации
5) **project_name** - Символьный идентификатор проекта в сервисе локализации
\ No newline at end of file
1) **url** - Адрес хранилища
2) **bucket** - Название хранилища
3) **awsSecretAccessKey** - Ключ апи
4) **awsAccessKeyId** - ID апи
5) **serviceUser** - Пользователь
5) **region** - Регион
5) **directoryProject** - Путь для файлов проекта, меняется в зависимости от сервера
......@@ -2,7 +2,7 @@
"name": "iwaydev/yandex-object-storage",
"description": "Пакет для работы с YA хранилещем",
"type": "extension",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"require": {
"php": ">=7.3",
......
<?php
namespace common\components\senders;
namespace yandexObjectStorage\components;
use Aws\Credentials\Credentials;
use Aws\Result;
......@@ -34,7 +34,10 @@ class YandexObjectStorage
public $url;
/** @var string */
public $objectPrefix;
public $directoryProject;
/** @var string */
public $directoryFiles;
/** @var S3Client $client */
private $client;
......@@ -64,10 +67,13 @@ class YandexObjectStorage
public function getObject(string $objectKey, $directory): Result
{
try {
$filePath = $this->directoryProject . DIRECTORY_SEPARATOR
. $this->directoryFiles . DIRECTORY_SEPARATOR . $objectKey;
$result = $this->client->getObject(
[
'Bucket' => $this->bucket,
'Key' => $this->objectPrefix . $objectKey,
'Key' => $filePath,
'SaveAs' => $directory . DIRECTORY_SEPARATOR . $objectKey,
]
);
......@@ -89,9 +95,12 @@ class YandexObjectStorage
*/
public function uploadObject(string $fullPathToFile, string $objectKey): Result
{
$filePath = $this->directoryProject . DIRECTORY_SEPARATOR
. $this->directoryFiles . DIRECTORY_SEPARATOR . $objectKey;
return $this->client->upload(
$this->bucket,
$this->objectPrefix . $objectKey,
$filePath,
fopen($fullPathToFile, 'r')
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment