~ancarda/psr7-string-stream

ref: 613485cfa5ed04fe26f6b60807209e098a97ca87 psr7-string-stream/src/IllegalOperationException.php -rw-r--r-- 1.2 KiB
613485cfMark Dain Throw StreamUnusableException after close/detach 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php

declare(strict_types=1);

namespace Ancarda\Psr7\StringStream;

use RuntimeException;
use Throwable;

/**
 * IllegalOperationException is thrown when a user attempts to perform an unsupported operation.
 *
 * An example might be calling write() on a read only stream.
 */
class IllegalOperationException extends RuntimeException
{
    /** @var string */
    private $operation;

    /**
     * @param string $operation The operation, such as "write", that was refused.
     * @param string $justification Why can't the user perform the operation?
     *   This should complete the sentence "This stream is X", e.g. "This stream is read-only".
     * @param Throwable|null $previous
     */
    public function __construct(string $operation, string $justification, Throwable $previous = null)
    {
        $this->operation = $operation;

        parent::__construct(
            "You cannot call `{$this->operation}' on this stream because it's $justification.",
            0,
            $previous
        );
    }

    /**
     * Returns the operation, such as "write", that was refused.
     *
     * @return string
     */
    public function getOperation(): string
    {
        return $this->operation;
    }
}