forked from thephpleague/flysystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
290ba29
commit ea4542a
Showing
8 changed files
with
113 additions
and
171 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\Flysystem\GoogleCloudStorage; | ||
|
||
use Google\Cloud\Storage\Bucket; | ||
use LogicException; | ||
use Throwable; | ||
|
||
use function array_key_exists; | ||
|
||
class StubRiggedBucket extends Bucket | ||
{ | ||
private array $triggers = []; | ||
|
||
public function failForObject($name, ?Throwable $throwable = null): void | ||
{ | ||
$this->setupTrigger('object', $name, $throwable); | ||
} | ||
|
||
public function failForUpload($name, ?Throwable $throwable = null): void | ||
{ | ||
$this->setupTrigger('upload', $name, $throwable); | ||
} | ||
|
||
public function object($name, array $options = []) | ||
{ | ||
$this->pushTrigger('object', $name); | ||
|
||
return parent::object($name, $options); | ||
} | ||
|
||
public function upload($data, array $options = []) | ||
{ | ||
$this->pushTrigger('upload', $options['name'] ?? 'unknown-object-name'); | ||
|
||
return parent::upload($data, $options); | ||
} | ||
|
||
private function setupTrigger(string $method, string $name, ?Throwable $throwable): void | ||
{ | ||
$this->triggers[$method][$name] = $throwable ?: new LogicException('unknown error'); | ||
} | ||
|
||
private function pushTrigger(string $method, string $name): void | ||
{ | ||
$trigger = $this->triggers[$method][$name] ?? null; | ||
|
||
if ($trigger instanceof Throwable) { | ||
unset($this->triggers[$method][$name]); | ||
throw $trigger; | ||
} | ||
} | ||
} |
Oops, something went wrong.