primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use Throwable;
use UnexpectedValueException;
class DeserializationException extends UnexpectedValueException implements ExceptionInterface
{
public static function forInvalidHeader(): self
{
throw new self('Invalid header detected');
}
public static function forInvalidHeaderContinuation(): self
{
throw new self('Invalid header continuation');
}
public static function forRequestFromArray(Throwable $previous): self
{
return new self('Cannot deserialize request', $previous->getCode(), $previous);
}
public static function forResponseFromArray(Throwable $previous): self
{
return new self('Cannot deserialize response', $previous->getCode(), $previous);
}
public static function forUnexpectedCarriageReturn(): self
{
throw new self('Unexpected carriage return detected');
}
public static function forUnexpectedEndOfHeaders(): self
{
throw new self('Unexpected end of headers');
}
public static function forUnexpectedLineFeed(): self
{
throw new self('Unexpected line feed detected');
}
}

View File

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use Throwable;
/**
* Marker interface for package-specific exceptions.
*/
interface ExceptionInterface extends Throwable
{
}

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use Laminas\Diactoros\ServerRequestFilter\FilterUsingXForwardedHeaders;
use function gettype;
use function is_object;
use function is_string;
use function sprintf;
class InvalidForwardedHeaderNameException extends RuntimeException implements ExceptionInterface
{
public static function forHeader(mixed $name): self
{
if (! is_string($name)) {
$name = sprintf('(value of type %s)', is_object($name) ? $name::class : gettype($name));
}
return new self(sprintf(
'Invalid X-Forwarded-* header name "%s" provided to %s',
$name,
FilterUsingXForwardedHeaders::class
));
}
}

View File

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use function gettype;
use function is_object;
use function sprintf;
class InvalidProxyAddressException extends RuntimeException implements ExceptionInterface
{
public static function forInvalidProxyArgument(mixed $proxy): self
{
$type = is_object($proxy) ? $proxy::class : gettype($proxy);
return new self(sprintf(
'Invalid proxy of type "%s" provided;'
. ' must be a valid IPv4 or IPv6 address, optionally with a subnet mask provided'
. ' or an array of such values',
$type,
));
}
public static function forAddress(string $address): self
{
return new self(sprintf(
'Invalid proxy address "%s" provided;'
. ' must be a valid IPv4 or IPv6 address, optionally with a subnet mask provided',
$address,
));
}
}

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use RuntimeException;
use Throwable;
class InvalidStreamPointerPositionException extends RuntimeException implements ExceptionInterface
{
/** {@inheritDoc} */
public function __construct(
string $message = 'Invalid pointer position',
int $code = 0,
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
}

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use UnexpectedValueException;
class SerializationException extends UnexpectedValueException implements ExceptionInterface
{
public static function forInvalidRequestLine(): self
{
return new self('Invalid request line detected');
}
public static function forInvalidStatusLine(): self
{
return new self('No status line detected');
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use RuntimeException;
class UnreadableStreamException extends RuntimeException implements ExceptionInterface
{
public static function dueToConfiguration(): self
{
return new self('Stream is not readable');
}
public static function dueToMissingResource(): self
{
return new self('No resource available; cannot read');
}
public static function dueToPhpError(): self
{
return new self('Error reading stream');
}
public static function forCallbackStream(): self
{
return new self('Callback streams cannot read');
}
}

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use UnexpectedValueException;
use function sprintf;
class UnrecognizedProtocolVersionException extends UnexpectedValueException implements ExceptionInterface
{
public static function forVersion(string $version): self
{
return new self(sprintf('Unrecognized protocol version (%s)', $version));
}
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use RuntimeException;
class UnrewindableStreamException extends RuntimeException implements ExceptionInterface
{
public static function forCallbackStream(): self
{
return new self('Callback streams cannot rewind position');
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use RuntimeException;
class UnseekableStreamException extends RuntimeException implements ExceptionInterface
{
public static function dueToConfiguration(): self
{
return new self('Stream is not seekable');
}
public static function dueToMissingResource(): self
{
return new self('No resource available; cannot seek position');
}
public static function dueToPhpError(): self
{
return new self('Error seeking within stream');
}
public static function forCallbackStream(): self
{
return new self('Callback streams cannot seek position');
}
}

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use RuntimeException;
class UntellableStreamException extends RuntimeException implements ExceptionInterface
{
public static function dueToMissingResource(): self
{
return new self('No resource available; cannot tell position');
}
public static function dueToPhpError(): self
{
return new self('Error occurred during tell operation');
}
public static function forCallbackStream(): self
{
return new self('Callback streams cannot tell position');
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use RuntimeException;
class UnwritableStreamException extends RuntimeException implements ExceptionInterface
{
public static function dueToConfiguration(): self
{
return new self('Stream is not writable');
}
public static function dueToMissingResource(): self
{
return new self('No resource available; cannot write');
}
public static function dueToPhpError(): self
{
return new self('Error writing to stream');
}
public static function forCallbackStream(): self
{
return new self('Callback streams cannot write');
}
}

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use RuntimeException;
use Throwable;
class UploadedFileAlreadyMovedException extends RuntimeException implements ExceptionInterface
{
/** {@inheritDoc} */
public function __construct(
string $message = 'Cannot retrieve stream after it has already moved',
int $code = 0,
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
}

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Laminas\Diactoros\Exception;
use RuntimeException;
use function sprintf;
class UploadedFileErrorException extends RuntimeException implements ExceptionInterface
{
public static function forUnmovableFile(): self
{
return new self('Error occurred while moving uploaded file');
}
public static function dueToStreamUploadError(string $error): self
{
return new self(sprintf(
'Cannot retrieve stream due to upload error: %s',
$error
));
}
public static function dueToUnwritablePath(): self
{
return new self('Unable to write to designated path');
}
public static function dueToUnwritableTarget(string $targetDirectory): self
{
return new self(sprintf(
'The target directory `%s` does not exist or is not writable',
$targetDirectory
));
}
}