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.
feat: add imprint to settings repository
- Loading branch information
Showing
9 changed files
with
204 additions
and
0 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
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
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,95 @@ | ||
<?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\Services\OnOfficeService; | ||
|
||
class ImprintBuilder extends Builder | ||
{ | ||
use NonFilterable; | ||
use NonFilterable; | ||
use NonOrderable; | ||
|
||
public function __construct( | ||
private readonly OnOfficeService $onOfficeService, | ||
) { | ||
} | ||
|
||
public function get(): Collection | ||
{ | ||
$columns = $this->columns; | ||
$listLimit = $this->limit; | ||
$listOffset = $this->offset; | ||
|
||
return $this->onOfficeService->requestAll(/** | ||
* @throws OnOfficeException | ||
*/ function () use ($columns) { | ||
return $this->onOfficeService->requestApi( | ||
OnOfficeAction::Read, | ||
OnOfficeResourceType::Impressum, | ||
parameters: [ | ||
OnOfficeService::DATA => $columns, | ||
] | ||
); | ||
}, pageSize: $listLimit, offset: $listOffset); | ||
} | ||
|
||
/** | ||
* @throws OnOfficeException | ||
*/ | ||
public function first(): array | ||
{ | ||
$columns = $this->columns; | ||
|
||
$response = $this->onOfficeService->requestApi( | ||
OnOfficeAction::Read, | ||
OnOfficeResourceType::Impressum, | ||
parameters: [ | ||
OnOfficeService::DATA => $columns, | ||
] | ||
); | ||
|
||
return $response->json('response.results.0.data.records.0'); | ||
} | ||
|
||
/** | ||
* @throws OnOfficeException | ||
*/ | ||
public function find(int $id): array | ||
{ | ||
$columns = $this->columns; | ||
|
||
$response = $this->onOfficeService->requestApi( | ||
OnOfficeAction::Read, | ||
OnOfficeResourceType::Impressum, | ||
resourceId: $id, | ||
parameters: [ | ||
OnOfficeService::DATA => $columns, | ||
] | ||
); | ||
|
||
return $response->json('response.results.0.data.records.0'); | ||
} | ||
|
||
/** | ||
* @throws OnOfficeException | ||
*/ | ||
public function each(callable $callback): void | ||
{ | ||
throw new OnOfficeException('Not implemented'); | ||
} | ||
|
||
/** | ||
* @throws OnOfficeException | ||
*/ | ||
public function modify(int $id): bool | ||
{ | ||
throw new OnOfficeException('Not implemented'); | ||
} | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Katalam\OnOfficeAdapter\Query\Testing; | ||
|
||
class ImprintBuilderFake extends BaseFake | ||
{ | ||
} |
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,20 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Http; | ||
use Katalam\OnOfficeAdapter\Facades\SettingRepository; | ||
use Katalam\OnOfficeAdapter\Tests\Stubs\GetImprintResponse; | ||
|
||
it('works', function () { | ||
Http::preventStrayRequests(); | ||
Http::fake([ | ||
'*' => GetImprintResponse::make(), | ||
]); | ||
|
||
$imprint = SettingRepository::imprint() | ||
->get(); | ||
|
||
expect($imprint) | ||
->toHaveCount(1) | ||
->and(data_get($imprint, '0.elements.firstname')) | ||
->toBe('Max'); | ||
}); |
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,58 @@ | ||
<?php | ||
|
||
namespace Katalam\OnOfficeAdapter\Tests\Stubs; | ||
|
||
use GuzzleHttp\Promise\PromiseInterface; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
class GetImprintResponse | ||
{ | ||
public static function make(array $data = []): PromiseInterface | ||
{ | ||
return Http::response(self::getBody($data)); | ||
} | ||
|
||
private static function getBody(array $data): array | ||
{ | ||
return array_merge_recursive([ | ||
'status' => [ | ||
'code' => 200, | ||
'errorcode' => 0, | ||
'message' => 'OK', | ||
], | ||
'response' => [ | ||
'results' => [ | ||
[ | ||
'actionid' => 'urn:onoffice-de-ns:smart:2.5:smartml:action:read', | ||
'resourceid' => '21', | ||
'resourcetype' => 'impressum', | ||
'cacheable' => true, | ||
'identifier' => '', | ||
'data' => [ | ||
'meta' => [ | ||
'cntabsolute' => null, | ||
], | ||
'records' => [ | ||
[ | ||
'id' => 'impressum', | ||
'type' => null, | ||
'elements' => [ | ||
'title' => 'Mr.', | ||
'firstname' => 'Max', | ||
'lastname' => 'Mustermann', | ||
'firma' => 'onOffice GmbH', | ||
'country' => 'Germany', | ||
], | ||
], | ||
], | ||
], | ||
'status' => [ | ||
'errorcode' => 0, | ||
'message' => 'OK', | ||
], | ||
], | ||
], | ||
], | ||
], $data); | ||
} | ||
} |