Skip to content

Commit 6e2c574

Browse files
authored
migrated to laminas/laminas-diactoros (#125) (#134)
1 parent 39db36d commit 6e2c574

File tree

6 files changed

+58
-13
lines changed

6 files changed

+58
-13
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ All notable changes to this project will be documented in this file.
66
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
77
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
88

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

1122
- Added support for PHP 8.0.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
"guzzlehttp/psr7": "^1.0",
3030
"phpspec/phpspec": "^5.1 || ^6.3",
3131
"slim/slim": "^3.0",
32-
"zendframework/zend-diactoros": "^1.0"
32+
"laminas/laminas-diactoros": "^2.0"
3333
},
3434
"suggest": {
3535
"ext-zlib": "Used with compressor/decompressor streams",
3636
"guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories",
37-
"slim/slim": "Used with Slim Framework PSR-7 implementation",
38-
"zendframework/zend-diactoros": "Used with Diactoros Factories"
37+
"laminas/laminas-diactoros": "Used with Diactoros Factories",
38+
"slim/slim": "Used with Slim Framework PSR-7 implementation"
3939
},
4040
"config": {
4141
"sort-packages": true

spec/StreamFactory/DiactorosStreamFactorySpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace spec\Http\Message\StreamFactory;
44

5-
use Zend\Diactoros\Stream;
5+
use Laminas\Diactoros\Stream;
66
use PhpSpec\ObjectBehavior;
77

88
class DiactorosStreamFactorySpec extends ObjectBehavior

src/MessageFactory/DiactorosMessageFactory.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use Http\Message\MessageFactory;
66
use Http\Message\StreamFactory\DiactorosStreamFactory;
7-
use Zend\Diactoros\Request;
8-
use Zend\Diactoros\Response;
7+
use Laminas\Diactoros\Request as LaminasRequest;
8+
use Laminas\Diactoros\Response as LaminasResponse;
9+
use Zend\Diactoros\Request as ZendRequest;
10+
use Zend\Diactoros\Response as ZendResponse;
911

1012
/**
1113
* Creates Diactoros messages.
@@ -36,7 +38,16 @@ public function createRequest(
3638
$body = null,
3739
$protocolVersion = '1.1'
3840
) {
39-
return (new Request(
41+
if (class_exists(LaminasRequest::class)) {
42+
return (new LaminasRequest(
43+
$uri,
44+
$method,
45+
$this->streamFactory->createStream($body),
46+
$headers
47+
))->withProtocolVersion($protocolVersion);
48+
}
49+
50+
return (new ZendRequest(
4051
$uri,
4152
$method,
4253
$this->streamFactory->createStream($body),
@@ -54,7 +65,15 @@ public function createResponse(
5465
$body = null,
5566
$protocolVersion = '1.1'
5667
) {
57-
return (new Response(
68+
if (class_exists(LaminasResponse::class)) {
69+
return (new LaminasResponse(
70+
$this->streamFactory->createStream($body),
71+
$statusCode,
72+
$headers
73+
))->withProtocolVersion($protocolVersion);
74+
}
75+
76+
return (new ZendResponse(
5877
$this->streamFactory->createStream($body),
5978
$statusCode,
6079
$headers

src/StreamFactory/DiactorosStreamFactory.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace Http\Message\StreamFactory;
44

55
use Http\Message\StreamFactory;
6+
use Laminas\Diactoros\Stream as LaminasStream;
67
use Psr\Http\Message\StreamInterface;
7-
use Zend\Diactoros\Stream;
8+
use Zend\Diactoros\Stream as ZendStream;
89

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

2728
if (is_resource($body)) {
28-
return new Stream($body);
29+
if (class_exists(LaminasStream::class)) {
30+
return new LaminasStream($body);
31+
}
32+
33+
return new ZendStream($body);
34+
}
35+
36+
if (class_exists(LaminasStream::class)) {
37+
$stream = new LaminasStream('php://memory', 'rw');
38+
} else {
39+
$stream = new ZendStream('php://memory', 'rw');
2940
}
3041

31-
$stream = new Stream('php://memory', 'rw');
3242
if (null !== $body && '' !== $body) {
3343
$stream->write((string) $body);
3444
}

src/UriFactory/DiactorosUriFactory.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace Http\Message\UriFactory;
44

55
use Http\Message\UriFactory;
6+
use Laminas\Diactoros\Uri as LaminasUri;
67
use Psr\Http\Message\UriInterface;
7-
use Zend\Diactoros\Uri;
8+
use Zend\Diactoros\Uri as ZendUri;
89

910
/**
1011
* Creates Diactoros URI.
@@ -23,7 +24,11 @@ public function createUri($uri)
2324
if ($uri instanceof UriInterface) {
2425
return $uri;
2526
} elseif (is_string($uri)) {
26-
return new Uri($uri);
27+
if (class_exists(LaminasUri::class)) {
28+
return new LaminasUri($uri);
29+
}
30+
31+
return new ZendUri($uri);
2732
}
2833

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

0 commit comments

Comments
 (0)