mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-07 16:18:33 +00:00
Find crop codes under crop and document unreadable avatar files
This commit is contained in:
5 files changed
+52
-5
No files matched your search
@@ -72,9 +72,10 @@ trait ManagesProfile
|
||||
* @param array{x: int, y: int, size: int}|null $crop the square to use, in pixels of the
|
||||
* upright picture; the centre without one
|
||||
* @throws ValidationFailedException 422 with the codes "avatar_invalid", "avatar_too_large",
|
||||
* "crop_invalid"
|
||||
* "crop_invalid" (keyed by crop.x, crop.y or crop.size; errorCodeFor('crop') finds them)
|
||||
* @throws ApiException 413 "avatar_too_large", 401, 403 "missing_scope", "user_token_required",
|
||||
* 429 "too_many_requests" (also more than 10 uploads an hour)
|
||||
* @throws \RuntimeException when the file can't be opened (nothing is sent then)
|
||||
*/
|
||||
public function uploadAvatar(string|SplFileInfo $file, ?array $crop = null): User
|
||||
{
|
||||
@@ -129,4 +130,4 @@ trait ManagesProfile
|
||||
|
||||
return new User($result->data);
|
||||
}
|
||||
}
|
||||
}␍
|
||||
@@ -19,9 +19,25 @@ class ValidationFailedException extends ApiException
|
||||
return is_object($codes) || is_array($codes) ? array_map('strval', (array) $codes) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* The code of $field, or of its first failed sub-field when the codes are keyed by those
|
||||
* (`crop` finds `crop.x`, `crop.y` or `crop.size`).
|
||||
*/
|
||||
public function errorCodeFor(string $field): ?string
|
||||
{
|
||||
return $this->errorCodes()[$field] ?? null;
|
||||
$codes = $this->errorCodes();
|
||||
|
||||
if (isset($codes[$field])) {
|
||||
return $codes[$field];
|
||||
}
|
||||
|
||||
foreach ($codes as $key => $code) {
|
||||
if (str_starts_with((string) $key, $field . '.')) {
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user