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:
30
30
31
31
before_install :
32
32
- 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
33
34
- travis_retry composer self-update
34
35
35
36
install :
Original file line number Diff line number Diff line change 1
1
# Change Log
2
2
3
+ ## Unreleased
4
+
5
+ ### Added
6
+
7
+ - Message, stream and URI factories for [ Slim Framework] ( https://github.com/slimphp/Slim )
3
8
4
9
## 1.3.1 - 2016-07-15
5
10
Original file line number Diff line number Diff line change 22
22
"ext-zlib" : " *" ,
23
23
"phpspec/phpspec" : " ^2.4" ,
24
24
"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"
26
28
},
27
29
"suggest" : {
28
30
"zendframework/zend-diactoros" : " Used with Diactoros Factories" ,
29
31
"guzzlehttp/psr7" : " Used with Guzzle PSR-7 Factories" ,
32
+ "slim/slim" : " Used with Slim Framework PSR-7 implementation" ,
30
33
"ext-zlib" : " Used with compressor/decompressor streams"
31
34
},
32
35
"autoload" : {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ formatter.name: pretty
6
6
extensions :
7
7
- PhpSpec\Extension\CodeCoverageExtension
8
8
- Coduo\PhpSpec\DataProvider\DataProviderExtension
9
+ - Akeneo\SkipExampleExtension
9
10
code_coverage :
10
11
format : clover
11
12
output : build/coverage.xml
Original file line number Diff line number Diff line change 5
5
formatter.name: pretty
6
6
extensions:
7
7
- 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 <[email protected] >
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 <[email protected] >
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
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Http \Message \UriFactory ;
4
+
5
+ use Http \Message \UriFactory ;
6
+ use Psr \Http \Message \UriInterface ;
7
+ use Slim \Http \Uri ;
8
+
9
+ /**
10
+ * Creates Slim 3 URI.
11
+ *
12
+ * @author Mika Tuupola <[email protected] >
13
+ */
14
+ final class SlimUriFactory implements UriFactory
15
+ {
16
+ /**
17
+ * {@inheritdoc}
18
+ */
19
+ public function createUri ($ uri )
20
+ {
21
+ if ($ uri instanceof UriInterface) {
22
+ return $ uri ;
23
+ }
24
+
25
+ if (is_string ($ uri )) {
26
+ return Uri::createFromString ($ uri );
27
+ }
28
+
29
+ throw new \InvalidArgumentException ('URI must be a string or UriInterface ' );
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments