File tree Expand file tree Collapse file tree 11 files changed +226
-1
lines changed Expand file tree Collapse file tree 11 files changed +226
-1
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ matrix:
3030
3131before_install :
3232 - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
33+ - if [[ "${TRAVIS_PHP_VERSION}" == "5.4" ]]; then composer remove slim/slim --dev --no-update; fi
3334 - travis_retry composer self-update
3435
3536install :
Original file line number Diff line number Diff line change 11# Change Log
22
3+ ## Unreleased
4+
5+ ### Added
6+
7+ - Message, stream and URI factories for [ Slim Framework] ( https://github.com/slimphp/Slim )
38
49## 1.3.1 - 2016-07-15
510
Original file line number Diff line number Diff line change 2222 "ext-zlib" : " *" ,
2323 "phpspec/phpspec" : " ^2.4" ,
2424 "henrikbjorn/phpspec-code-coverage" : " ^1.0" ,
25- "coduo/phpspec-data-provider-extension" : " ^1.0"
25+ "coduo/phpspec-data-provider-extension" : " ^1.0" ,
26+ "akeneo/phpspec-skip-example-extension" : " ^1.0" ,
27+ "slim/slim" : " ^3.5"
2628 },
2729 "suggest" : {
2830 "zendframework/zend-diactoros" : " Used with Diactoros Factories" ,
2931 "guzzlehttp/psr7" : " Used with Guzzle PSR-7 Factories" ,
32+ "slim/slim" : " Used with Slim Framework PSR-7 implementation" ,
3033 "ext-zlib" : " Used with compressor/decompressor streams"
3134 },
3235 "autoload" : {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ formatter.name: pretty
66extensions :
77 - PhpSpec\Extension\CodeCoverageExtension
88 - Coduo\PhpSpec\DataProvider\DataProviderExtension
9+ - Akeneo\SkipExampleExtension
910code_coverage :
1011 format : clover
1112 output : build/coverage.xml
Original file line number Diff line number Diff line change 55formatter.name: pretty
66extensions:
77 - Coduo\PhpSpec\DataProvider\DataProviderExtension
8+ - Akeneo\SkipExampleExtension
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace spec \Http \Message \MessageFactory ;
4+
5+ use PhpSpec \ObjectBehavior ;
6+
7+ /**
8+ * @require Slim\Http\Request
9+ */
10+ class SlimMessageFactorySpec extends ObjectBehavior
11+ {
12+ use MessageFactoryBehavior;
13+
14+ function it_is_initializable ()
15+ {
16+ $ this ->shouldHaveType ('Http\Message\MessageFactory\SlimMessageFactory ' );
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace spec \Http \Message \StreamFactory ;
4+
5+ use Slim \Http \Stream ;
6+ use PhpSpec \ObjectBehavior ;
7+
8+ /**
9+ * @require Slim\Http\Stream
10+ */
11+ class SlimStreamFactorySpec extends ObjectBehavior
12+ {
13+ use StreamFactoryBehavior;
14+
15+ function it_is_initializable ()
16+ {
17+ $ this ->shouldHaveType ('Http\Message\StreamFactory\SlimStreamFactory ' );
18+ }
19+
20+ function it_creates_a_stream_from_stream ()
21+ {
22+ $ resource = fopen ('php://memory ' , 'rw ' );
23+ $ this ->createStream (new Stream ($ resource ))
24+ ->shouldHaveType ('Psr\Http\Message\StreamInterface ' );
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace spec \Http \Message \UriFactory ;
4+
5+ use Psr \Http \Message \UriInterface ;
6+ use PhpSpec \ObjectBehavior ;
7+
8+ /**
9+ * @require Slim\Http\Uri
10+ */
11+ class SlimUriFactorySpec extends ObjectBehavior
12+ {
13+ use UriFactoryBehavior;
14+
15+ function it_is_initializable ()
16+ {
17+ $ this ->shouldHaveType ('Http\Message\UriFactory\SlimUriFactory ' );
18+ }
19+
20+ /**
21+ * TODO: Remove this when https://github.com/phpspec/phpspec/issues/825 is resolved
22+ */
23+ function it_creates_a_uri_from_uri (UriInterface $ uri )
24+ {
25+ $ this ->createUri ($ uri )->shouldReturn ($ uri );
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Http \Message \MessageFactory ;
4+
5+ use Http \Message \StreamFactory \SlimStreamFactory ;
6+ use Http \Message \UriFactory \SlimUriFactory ;
7+ use Http \Message \MessageFactory ;
8+ use Slim \Http \Request ;
9+ use Slim \Http \Response ;
10+ use Slim \Http \Headers ;
11+
12+ /**
13+ * Creates Slim 3 messages.
14+ *
15+ * @author Mika Tuupola <tuupola@appelsiini.net>
16+ */
17+ final class SlimMessageFactory implements MessageFactory
18+ {
19+ /**
20+ * @var SlimStreamFactory
21+ */
22+ private $ streamFactory ;
23+
24+ /**
25+ * @var SlimUriFactory
26+ */
27+ private $ uriFactory ;
28+
29+ public function __construct ()
30+ {
31+ $ this ->streamFactory = new SlimStreamFactory ();
32+ $ this ->uriFactory = new SlimUriFactory ();
33+ }
34+
35+ /**
36+ * {@inheritdoc}
37+ */
38+ public function createRequest (
39+ $ method ,
40+ $ uri ,
41+ array $ headers = [],
42+ $ body = null ,
43+ $ protocolVersion = '1.1 '
44+ ) {
45+ return (new Request (
46+ $ method ,
47+ $ this ->uriFactory ->createUri ($ uri ),
48+ new Headers ($ headers ),
49+ [],
50+ [],
51+ $ this ->streamFactory ->createStream ($ body ),
52+ []
53+ ))->withProtocolVersion ($ protocolVersion );
54+ }
55+
56+ /**
57+ * {@inheritdoc}
58+ */
59+ public function createResponse (
60+ $ statusCode = 200 ,
61+ $ reasonPhrase = null ,
62+ array $ headers = [],
63+ $ body = null ,
64+ $ protocolVersion = '1.1 '
65+ ) {
66+ return (new Response (
67+ $ statusCode ,
68+ new Headers ($ headers ),
69+ $ this ->streamFactory ->createStream ($ body )
70+ ))->withProtocolVersion ($ protocolVersion );
71+ }
72+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Http \Message \StreamFactory ;
4+
5+ use Http \Message \StreamFactory ;
6+ use Psr \Http \Message \StreamInterface ;
7+ use Slim \Http \Stream ;
8+
9+ /**
10+ * Creates Slim 3 streams.
11+ *
12+ * @author Mika Tuupola <tuupola@appelsiini.net>
13+ */
14+ final class SlimStreamFactory implements StreamFactory
15+ {
16+ /**
17+ * {@inheritdoc}
18+ */
19+ public function createStream ($ body = null )
20+ {
21+ if ($ body instanceof StreamInterface) {
22+ return $ body ;
23+ }
24+
25+ if (is_resource ($ body )) {
26+ $ stream = new Stream ($ body );
27+ } else {
28+ $ resource = fopen ('php://memory ' , 'r+ ' );
29+ $ stream = new Stream ($ resource );
30+
31+ if (null !== $ body ) {
32+ $ stream ->write ((string ) $ body );
33+ }
34+ }
35+
36+ $ stream ->rewind ();
37+
38+ return $ stream ;
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments