Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Migrated from `zendframework/zend-diactoros` to `laminas/laminas-diactoros`.
Users are encouraged to update their dependencies by simply replacing the Zend package with the Laminas package.
Due to the [laminas-zendframework-brige](https://github.com/laminas/laminas-zendframework-bridge), BC changes
are not expected and legacy code does not need to be refactored (though it is
[recommended and simple](https://docs.laminas.dev/migration/)).
- The diactoros factories of `php-http/message` will return objects from the `Laminas\Diactoros\` namespace, if
the respective classes are available via autoloading, but continue to return objects from `Zend\Diactoros\`
namespace otherwise.

## [1.10.0] - 2020-11-11

- Added support for PHP 8.0.
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
"guzzlehttp/psr7": "^1.0",
"phpspec/phpspec": "^5.1 || ^6.3",
"slim/slim": "^3.0",
"zendframework/zend-diactoros": "^1.0"
"laminas/laminas-diactoros": "^2.0"
},
"suggest": {
"ext-zlib": "Used with compressor/decompressor streams",
"guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories",
"slim/slim": "Used with Slim Framework PSR-7 implementation",
"zendframework/zend-diactoros": "Used with Diactoros Factories"
"laminas/laminas-diactoros": "Used with Diactoros Factories",
"slim/slim": "Used with Slim Framework PSR-7 implementation"
},
"config": {
"sort-packages": true
Expand Down
2 changes: 1 addition & 1 deletion spec/StreamFactory/DiactorosStreamFactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace spec\Http\Message\StreamFactory;

use Zend\Diactoros\Stream;
use Laminas\Diactoros\Stream;
use PhpSpec\ObjectBehavior;

class DiactorosStreamFactorySpec extends ObjectBehavior
Expand Down
27 changes: 23 additions & 4 deletions src/MessageFactory/DiactorosMessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use Http\Message\MessageFactory;
use Http\Message\StreamFactory\DiactorosStreamFactory;
use Zend\Diactoros\Request;
use Zend\Diactoros\Response;
use Laminas\Diactoros\Request as LaminasRequest;
use Laminas\Diactoros\Response as LaminasResponse;
use Zend\Diactoros\Request as ZendRequest;
use Zend\Diactoros\Response as ZendResponse;

/**
* Creates Diactoros messages.
Expand Down Expand Up @@ -36,7 +38,16 @@ public function createRequest(
$body = null,
$protocolVersion = '1.1'
) {
return (new Request(
if (class_exists(LaminasRequest::class)) {
return (new LaminasRequest(
$uri,
$method,
$this->streamFactory->createStream($body),
$headers
))->withProtocolVersion($protocolVersion);
}

return (new ZendRequest(
$uri,
$method,
$this->streamFactory->createStream($body),
Expand All @@ -54,7 +65,15 @@ public function createResponse(
$body = null,
$protocolVersion = '1.1'
) {
return (new Response(
if (class_exists(LaminasResponse::class)) {
return (new LaminasResponse(
$this->streamFactory->createStream($body),
$statusCode,
$headers
))->withProtocolVersion($protocolVersion);
}

return (new ZendResponse(
$this->streamFactory->createStream($body),
$statusCode,
$headers
Expand Down
16 changes: 13 additions & 3 deletions src/StreamFactory/DiactorosStreamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Http\Message\StreamFactory;

use Http\Message\StreamFactory;
use Laminas\Diactoros\Stream as LaminasStream;
use Psr\Http\Message\StreamInterface;
use Zend\Diactoros\Stream;
use Zend\Diactoros\Stream as ZendStream;

/**
* Creates Diactoros streams.
Expand All @@ -25,10 +26,19 @@ public function createStream($body = null)
}

if (is_resource($body)) {
return new Stream($body);
if (class_exists(LaminasStream::class)) {
return new LaminasStream($body);
}

return new ZendStream($body);
}

if (class_exists(LaminasStream::class)) {
$stream = new LaminasStream('php://memory', 'rw');
} else {
$stream = new ZendStream('php://memory', 'rw');
}

$stream = new Stream('php://memory', 'rw');
if (null !== $body && '' !== $body) {
$stream->write((string) $body);
}
Expand Down
9 changes: 7 additions & 2 deletions src/UriFactory/DiactorosUriFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Http\Message\UriFactory;

use Http\Message\UriFactory;
use Laminas\Diactoros\Uri as LaminasUri;
use Psr\Http\Message\UriInterface;
use Zend\Diactoros\Uri;
use Zend\Diactoros\Uri as ZendUri;

/**
* Creates Diactoros URI.
Expand All @@ -23,7 +24,11 @@ public function createUri($uri)
if ($uri instanceof UriInterface) {
return $uri;
} elseif (is_string($uri)) {
return new Uri($uri);
if (class_exists(LaminasUri::class)) {
return new LaminasUri($uri);
}

return new ZendUri($uri);
}

throw new \InvalidArgumentException('URI must be a string or UriInterface');
Expand Down