Skip to content

Commit

Permalink
Change method and property visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ngmy committed Jun 28, 2023
1 parent c81c1f1 commit 535ca1a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/CanRespond.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

trait CanRespond
{
public string $responseIdent;
private string $responseIdent;

public function prepareResponse(?string $id = null): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelJobResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class LaravelJobResponse
{
public bool $throwExceptionOnFailure = false;
private bool $throwExceptionOnFailure = false;

public function __construct(
private readonly Dispatcher $dispatcher,
Expand Down
68 changes: 34 additions & 34 deletions src/Transport/CacheTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,39 @@ public function __construct(string $store = null)
}
}

public function awaitResponse(string $id, int $timeout): ResponseContract
{
$responses = $this->_awaitResponses($id, $timeout, 1);
$response = $responses[0];

return $this->createResponse($response);
}

public function awaitResponses(string $id, int $expectedResponses, int $timeout): ResponseCollection
{
return $this->createResponses($this->_awaitResponses($id, $timeout, $expectedResponses));
}

public function sendResponse(string $id, array $data): void
{
$store = $this->cacheStore->getStore();
\assert($store instanceof LockProvider);
$lock = $store->lock($id.$this->lockIdSuffix, $this->lockHoldSeconds);

try {
$lock->block($this->lockWaitSeconds);

$cacheData = $this->cacheStore->get($id, []);
\assert(\is_array($cacheData));
$cacheData[] = $data;
$this->cacheStore->put($id, $cacheData, $this->cacheTtl);
} catch (LockTimeoutException $e) {
throw new TimeoutException('Timed out attempting to acquire cache lock - something went wrong.');
} finally {
$lock->release();
}
}

/**
* @return list<array{response?: mixed, exception?: array{
* exception_class: string,
Expand All @@ -66,7 +99,7 @@ public function __construct(string $store = null)
*
* @throws TimeoutException
*/
public function _awaitResponses(string $id, int $timeout, int $expectedResponses = 1): array
private function _awaitResponses(string $id, int $timeout, int $expectedResponses = 1): array
{
$timeoutAt = now()->addSeconds($timeout);

Expand All @@ -90,37 +123,4 @@ public function _awaitResponses(string $id, int $timeout, int $expectedResponses

return $responses;
}

public function awaitResponse(string $id, int $timeout): ResponseContract
{
$responses = $this->_awaitResponses($id, $timeout, 1);
$response = $responses[0];

return $this->createResponse($response);
}

public function awaitResponses(string $id, int $expectedResponses, int $timeout): ResponseCollection
{
return $this->createResponses($this->_awaitResponses($id, $timeout, $expectedResponses));
}

public function sendResponse(string $id, array $data): void
{
$store = $this->cacheStore->getStore();
\assert($store instanceof LockProvider);
$lock = $store->lock($id.$this->lockIdSuffix, $this->lockHoldSeconds);

try {
$lock->block($this->lockWaitSeconds);

$cacheData = $this->cacheStore->get($id, []);
\assert(\is_array($cacheData));
$cacheData[] = $data;
$this->cacheStore->put($id, $cacheData, $this->cacheTtl);
} catch (LockTimeoutException $e) {
throw new TimeoutException('Timed out attempting to acquire cache lock - something went wrong.');
} finally {
$lock->release();
}
}
}
6 changes: 3 additions & 3 deletions src/Transport/RedisTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class RedisTransport extends TransportAbstract implements TransportContract
{
public Connection $connection;
private Connection $connection;

public function __construct(string $connection = null)
{
Expand Down Expand Up @@ -72,7 +72,7 @@ public function sendResponse(string $id, array $data): void
* line: int,
* }|array{}} $data
*/
public function forStorage(array $data): string
private function forStorage(array $data): string
{
return serialize($data);
}
Expand All @@ -88,7 +88,7 @@ public function forStorage(array $data): string
* line: int,
* }|array{}}
*/
public function fromStorage(string $data): array
private function fromStorage(string $data): array
{
// No safety added, this is an internal-only serialization and should not be an attack vector.
// @noinspection UnserializeExploitsInspection
Expand Down
2 changes: 1 addition & 1 deletion src/Transport/TransportAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class TransportAbstract
* By default if an exception occurs the exception will be passed as a ExceptionResponse object, however if this
* flag is true, an exception will be raised instead.
*/
public bool $shouldThrowException = false;
private bool $shouldThrowException = false;

/**
* @param array{response?: mixed, exception?: array{
Expand Down

0 comments on commit 535ca1a

Please sign in to comment.