Skip to content
This repository was archived by the owner on May 13, 2023. It is now read-only.

Commit f965f93

Browse files
committed
Initial commit
0 parents  commit f965f93

10 files changed

+286
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
indent_style = space
9+
indent_size = 4
10+
11+
[*.yml]
12+
indent_style = space
13+
indent_size = 2

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.editorconfig export-ignore
2+
.gitattributes export-ignore
3+
.gitignore export-ignore
4+
CONTRIBUTING.md export-ignore

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
vendor/
3+
composer.lock

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
4+
## Unreleased

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015 PHP HTTP Team <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# HTTP Message Factory
2+
3+
[![Latest Version](https://img.shields.io/github/release/php-http/message-factory.svg?style=flat-square)](https://github.com/php-http/message-factory/releases)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
5+
[![Total Downloads](https://img.shields.io/packagist/dt/php-http/message-factory.svg?style=flat-square)](https://packagist.org/packages/php-http/message-factory)
6+
7+
**Factory interfaces for PSR-7 HTTP Message.**
8+
9+
10+
## Install
11+
12+
Via Composer
13+
14+
``` bash
15+
$ composer require php-http/message-factory
16+
```
17+
18+
19+
## Usage
20+
21+
This package provides interfaces for PSR-7 factories including:
22+
23+
- `MessageFactory` - WIP
24+
- `ServerRequestFactory` - WIP
25+
- `StreamFactory` - WIP
26+
- `UploadedFileFactory` - WIP
27+
- `UriFactory` - WIP
28+
29+
30+
A virtual package ([php-http/message-factory-implementation](https://packagist.org/providers/php-http/message-factory-implementation)) MAY be introduced which MUST be versioned together with this package.
31+
32+
33+
### General usage
34+
35+
``` php
36+
use Http\Message\SomeFactory;
37+
38+
class MyFactory implements SomeFactory
39+
{
40+
41+
}
42+
```
43+
44+
45+
### Factory awares and helpers
46+
47+
For each factory there is a helper interface and trait to ease injecting them into other objects (such as HTTP clients).
48+
49+
An example:
50+
51+
``` php
52+
use Http\Message\SomeFactoryAware;
53+
use Http\Message\SomeFactoryHelper;
54+
55+
class HttpClient implements SomeFactoryAware
56+
{
57+
use SomeFactoryHelper;
58+
}
59+
60+
$client = new HttpClient();
61+
$someFactory = $client->getSomeFactory();
62+
$client->setSomeFactory($someFactory);
63+
```
64+
65+
66+
## Contributing
67+
68+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
69+
70+
71+
## Security
72+
73+
If you discover any security related issues, please contact us at [[email protected]](mailto:[email protected]).
74+
75+
76+
## License
77+
78+
The MIT License (MIT). Please see [License File](LICENSE) for more information.

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "php-http/message-factory",
3+
"description": "Factory interfaces for PSR-7 HTTP Message",
4+
"license": "MIT",
5+
"keywords": ["http", "factory", "message", "stream", "uri"],
6+
"homepage": "http://php-http.org",
7+
"authors": [
8+
{
9+
"name": "Eric GELOEN",
10+
"email": "[email protected]"
11+
},
12+
{
13+
"name": "Márk Sági-Kazár",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"require": {
18+
"php": ">=5.4",
19+
"psr/http-message": "^0.11"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Http\\Message\\": "src/"
24+
}
25+
},
26+
"extra": {
27+
"branch-alias": {
28+
"dev-master": "0.1-dev"
29+
}
30+
},
31+
"prefer-stable": true,
32+
"minimum-stability": "dev"
33+
}

src/MessageFactory.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Message Factory package.
5+
*
6+
* (c) PHP HTTP Team
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Message;
13+
14+
use Psr\Http\Message\UriInterface;
15+
use Psr\Http\Message\RequestInterface;
16+
use Psr\Http\Message\ResponseInterface;
17+
use Psr\Http\Message\StreamInterface;
18+
19+
/**
20+
* @author Márk Sági-Kazár <[email protected]>
21+
*/
22+
interface MessageFactory
23+
{
24+
/**
25+
* Creates a new request
26+
*
27+
* @param string $method
28+
* @param string|UriInterface $uri
29+
* @param string $protocolVersion
30+
* @param string[] $headers
31+
* @param resource|string|StreamInterface|null $body
32+
*
33+
* @return RequestInterface
34+
*/
35+
public function createRequest(
36+
$method,
37+
$uri,
38+
$protocolVersion = '1.1',
39+
array $headers = [],
40+
$body = null
41+
);
42+
43+
/**
44+
* Creates a response
45+
*
46+
* @param integer $statusCode
47+
* @param string|null $reasonPhrase
48+
* @param string $protocolVersion
49+
* @param string[] $headers
50+
* @param resource|string|StreamInterface|null $body
51+
*
52+
* @return ResponseInterface
53+
*/
54+
public function createResponse(
55+
$statusCode = 200,
56+
$reasonPhrase = null
57+
$protocolVersion = '1.1',
58+
array $headers = [],
59+
$body = null
60+
);
61+
}

src/MessageFactoryAware.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Message Factory package.
5+
*
6+
* (c) PHP HTTP Team
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Message;
13+
14+
/**
15+
* @author Márk Sági-Kazár <[email protected]>
16+
*/
17+
interface MessageFactoryAware
18+
{
19+
/**
20+
* Returns a Message Factory
21+
*
22+
* @return MessageFactory
23+
*/
24+
public function getMessageFactory();
25+
26+
/**
27+
* Sets a Message Factory
28+
*
29+
* @param MessageFactory $messageFactory
30+
*/
31+
public function setMessageFactory(MessageFactory $messageFactory);
32+
}

src/MessageFactoryHelper.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Http Message Factory package.
5+
*
6+
* (c) PHP HTTP Team
7+
*
8+
* For the full copyright and license information, please read the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Http\Message;
13+
14+
/**
15+
* @author Márk Sági-Kazár <[email protected]>
16+
*/
17+
interface MessageFactoryHelper
18+
{
19+
/**
20+
* @var MessageFactory
21+
*/
22+
protected $messageFactory;
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function getMessageFactory()
28+
{
29+
return $this->messageFactory;
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function setMessageFactory(MessageFactory $messageFactory)
36+
{
37+
$this->messageFactory = $messageFactory;
38+
}
39+
}

0 commit comments

Comments
 (0)