generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
576 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Katalam\OnOfficeAdapter\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
use Katalam\OnOfficeAdapter\Facades\Testing\FileRepositoryFake; | ||
use Katalam\OnOfficeAdapter\Query\UploadBuilder; | ||
|
||
/** | ||
* @see \Katalam\OnOfficeAdapter\Repositories\SettingRepository | ||
* | ||
* @method static UploadBuilder upload() | ||
*/ | ||
class FileRepository extends Facade | ||
{ | ||
public static function fake(array ...$fakeResponses): FileRepositoryFake | ||
{ | ||
static::swap($fake = new FileRepositoryFake(...$fakeResponses)); | ||
|
||
return $fake; | ||
} | ||
|
||
protected static function getFacadeAccessor(): string | ||
{ | ||
return \Katalam\OnOfficeAdapter\Repositories\FileRepository::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Katalam\OnOfficeAdapter\Facades\Testing; | ||
|
||
use Katalam\OnOfficeAdapter\Query\Testing\UploadBuilderFake; | ||
|
||
class FileRepositoryFake | ||
{ | ||
use FakeResponses; | ||
|
||
/** | ||
* Returns a new fake upload builder instance. | ||
*/ | ||
public function upload(): UploadBuilderFake | ||
{ | ||
return new UploadBuilderFake($this->fakeResponses); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Katalam\OnOfficeAdapter\Facades\Testing\RecordFactories; | ||
|
||
use Illuminate\Support\Str; | ||
|
||
class FileUploadFactory extends BaseFactory | ||
{ | ||
public function id(int $id): static | ||
{ | ||
return $this; | ||
} | ||
|
||
public function type(string $type): static | ||
{ | ||
return $this; | ||
} | ||
|
||
public function elements(): static | ||
{ | ||
return $this; | ||
} | ||
|
||
public function tmpUploadId(string $tmpUploadId = ''): static | ||
{ | ||
if ($tmpUploadId === '') { | ||
$tmpUploadId = Str::uuid()->toString(); | ||
} | ||
|
||
$this->elements['tmpUploadId'] = $tmpUploadId; | ||
|
||
return $this; | ||
} | ||
|
||
public function success(bool $success): static | ||
{ | ||
$this->elements['success'] = $success ? 'success' : 'error'; | ||
|
||
return $this; | ||
} | ||
|
||
public function ok(): static | ||
{ | ||
$this->elements['success'] = 'success'; | ||
|
||
return $this; | ||
} | ||
|
||
public function error(): static | ||
{ | ||
$this->elements['success'] = 'error'; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Katalam\OnOfficeAdapter\Query\Testing; | ||
|
||
use Throwable; | ||
|
||
class UploadBuilderFake extends BaseFake | ||
{ | ||
/** | ||
* @throws Throwable | ||
*/ | ||
public function save(string $fileContent): string | ||
{ | ||
$record = $this->get()->first(); | ||
|
||
return data_get($record, 'elements.tmpUploadId'); | ||
} | ||
|
||
/** | ||
* @throws Throwable | ||
*/ | ||
public function link(string $tmpUploadId, array $data = []): bool | ||
{ | ||
$record = $this->get()->first(); | ||
|
||
return data_get($record, 'elements.success') === 'success'; | ||
} | ||
|
||
/** | ||
* @throws Throwable | ||
*/ | ||
public function saveAndLink(string $fileContent, array $data = []): bool | ||
{ | ||
$tmpUploadId = $this->save($fileContent); | ||
|
||
return $this->link($tmpUploadId, $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
namespace Katalam\OnOfficeAdapter\Query; | ||
|
||
use Illuminate\Support\Collection; | ||
use Katalam\OnOfficeAdapter\Enums\OnOfficeAction; | ||
use Katalam\OnOfficeAdapter\Enums\OnOfficeResourceType; | ||
use Katalam\OnOfficeAdapter\Exceptions\OnOfficeException; | ||
use Katalam\OnOfficeAdapter\Query\Concerns\NonFilterable; | ||
use Katalam\OnOfficeAdapter\Query\Concerns\NonOrderable; | ||
use Katalam\OnOfficeAdapter\Query\Concerns\NonSelectable; | ||
use Katalam\OnOfficeAdapter\Services\OnOfficeService; | ||
|
||
class UploadBuilder extends Builder | ||
{ | ||
use NonFilterable; | ||
use NonFilterable; | ||
use NonOrderable; | ||
use NonSelectable; | ||
|
||
public function __construct( | ||
private readonly OnOfficeService $onOfficeService, | ||
) { | ||
} | ||
|
||
/** | ||
* @throws OnOfficeException | ||
*/ | ||
public function get(): Collection | ||
{ | ||
throw new OnOfficeException('Method not implemented'); | ||
} | ||
|
||
/** | ||
* @throws OnOfficeException | ||
*/ | ||
public function first(): array | ||
{ | ||
throw new OnOfficeException('Method not implemented'); | ||
} | ||
|
||
/** | ||
* @throws OnOfficeException | ||
*/ | ||
public function find(int $id): array | ||
{ | ||
throw new OnOfficeException('Method not implemented'); | ||
} | ||
|
||
/** | ||
* @throws OnOfficeException | ||
*/ | ||
public function each(callable $callback): void | ||
{ | ||
throw new OnOfficeException('Method not implemented'); | ||
} | ||
|
||
/** | ||
* @throws OnOfficeException | ||
*/ | ||
public function modify(int $id): bool | ||
{ | ||
throw new OnOfficeException('Not implemented'); | ||
} | ||
|
||
/** | ||
* File content as base64-encoded binary data. | ||
* Returns the temporary upload id. | ||
* | ||
* @throws OnOfficeException | ||
*/ | ||
public function save(string $fileContent): string | ||
{ | ||
$response = $this->onOfficeService->requestApi( | ||
OnOfficeAction::Do, | ||
OnOfficeResourceType::UploadFile, | ||
parameters: [ | ||
OnOfficeService::DATA => $fileContent, | ||
] | ||
); | ||
|
||
return $response->json('response.results.0.data.records.0.elements.tmpUploadId'); | ||
} | ||
|
||
/** | ||
* @throws OnOfficeException | ||
*/ | ||
public function link(string $tmpUploadId, array $data = []): self | ||
{ | ||
$data = array_replace($data, [ | ||
'tmpUploadId' => $tmpUploadId, | ||
]); | ||
|
||
$this->onOfficeService->requestApi( | ||
OnOfficeAction::Do, | ||
OnOfficeResourceType::UploadFile, | ||
parameters: $data, | ||
); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* File content as base64-encoded binary data. | ||
* Returns the temporary upload id. | ||
* | ||
* @throws OnOfficeException | ||
*/ | ||
public function saveAndLink(string $fileContent, array $data = []): self | ||
{ | ||
$tmpUploadId = $this->save($fileContent); | ||
|
||
return $this->link($tmpUploadId, $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Katalam\OnOfficeAdapter\Repositories; | ||
|
||
use Katalam\OnOfficeAdapter\Query\UploadBuilder; | ||
use Katalam\OnOfficeAdapter\Services\OnOfficeService; | ||
|
||
class FileRepository | ||
{ | ||
public function __construct( | ||
private readonly OnOfficeService $onOfficeService, | ||
) { | ||
} | ||
|
||
/** | ||
* Returns a new upload builder instance. | ||
*/ | ||
public function upload(): UploadBuilder | ||
{ | ||
return new UploadBuilder($this->onOfficeService); | ||
} | ||
} |
Oops, something went wrong.