-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from shahmal1yev/bss-94
[BSS-94] Add support for handling blobs via array
- Loading branch information
Showing
9 changed files
with
142 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,7 @@ fabric.properties | |
|
||
# PHPUnit | ||
/app/phpunit.xml | ||
|
||
phpunit.dist.xml | ||
# Build data | ||
/build/ | ||
|
||
|
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 |
---|---|---|
|
@@ -24,4 +24,5 @@ | |
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
|
||
</phpunit> |
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,46 @@ | ||
<?php | ||
|
||
namespace Atproto\DataModel\Blob; | ||
|
||
use Atproto\Contracts\DataModel\BlobHandler; | ||
use Atproto\Exceptions\InvalidArgumentException; | ||
use Atproto\Support\Arr; | ||
|
||
class ArrayBlobHandler implements BlobHandler | ||
{ | ||
private array $blob; | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function __construct(array $blob) | ||
{ | ||
$this->blob = $blob; | ||
|
||
if (! isset($this->blob['size'], $this->blob['mimeType'], $this->blob['ref']['$link'])) { | ||
throw new InvalidArgumentException( | ||
"ArrayBlobHandler requires 'ref.\$link', 'mimeType', and 'size' fields." | ||
); | ||
} | ||
} | ||
|
||
public function size(): int | ||
{ | ||
return Arr::get($this->blob, 'size'); | ||
} | ||
|
||
public function mimeType(): string | ||
{ | ||
return Arr::get($this->blob, 'mimeType'); | ||
} | ||
|
||
public function content(): string | ||
{ | ||
throw new \LogicException("Content does not exists for array blob handler."); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return Arr::get($this->blob, 'ref.$link'); | ||
} | ||
} |
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