Organized

This commit is contained in:
Jason Thistlethwaite
2026-10-17 20:50:35 -04:00
parent bd26c8894f
commit 9ee9eb3ec6
130 changed files with 24172 additions and 140 deletions
+25
View File
@@ -22,6 +22,31 @@ final class RedmineClient
$this->client = $client;
}
/**
* Run a callback while impersonating an existing Redmine username.
*
* Redmine impersonation only applies when the authenticated API user has
* permission to switch users.
*
* @param callable $callback
*
* @return mixed
*/
public function withImpersonation(?string $username, callable $callback)
{
$normalized = is_string($username) ? trim($username) : '';
if ($normalized === '') {
return $callback();
}
$this->client->startImpersonateUser($normalized);
try {
return $callback();
} finally {
$this->client->stopImpersonateUser();
}
}
public static function fromCredentials(string $url, string $apiKeyOrUsername, ?string $password = null): self
{
return new self(new NativeCurlClient($url, $apiKeyOrUsername, $password));