Skip to content

Commit e02880b

Browse files
committed
+ Initial commit
0 parents  commit e02880b

File tree

12 files changed

+1160
-0
lines changed

12 files changed

+1160
-0
lines changed

.gitignore

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

LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2016 Jorge Matricali <jorgematricali@gmail.com>
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
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all 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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PSR Http Client
2+
================
3+
4+
[PSR-7](http://www.php-fig.org/psr/psr-7/).
5+
6+
Note that this is not a HTTP protocol implementation of its own. It is merely a
7+
wrapper of libcurl that implements PSR-7 HTTP message interface.

composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "jorge-matricali/http-client",
3+
"description": "Hola",
4+
"type": "library",
5+
"keywords": ["http", "client", "psr7", "curl", "wrapper"],
6+
"require": {
7+
"psr/http-message": "^1.0"
8+
},
9+
"require-dev": {
10+
"phpunit/phpunit": "~4.0",
11+
"squizlabs/php_codesniffer": "~1.5",
12+
"satooshi/php-coveralls": "~1.0"
13+
},
14+
"autoload": {
15+
"classmap": [
16+
"src/"
17+
]
18+
},
19+
"license": "MIT",
20+
"authors": [
21+
{
22+
"name": "Jorge Matricali",
23+
"email": "jorgematricali@gmail.com"
24+
}
25+
],
26+
"support": {
27+
"issues": "https://github.com/jorge-matricali/php-http-client/issues",
28+
"source": "https://github.com/jorge-matricali/php-http-client"
29+
}
30+
}

phpunit.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="false"
11+
strict="true"
12+
verbose="true"
13+
bootstrap="./vendor/autoload.php">
14+
15+
<testsuites>
16+
<testsuite name="Http Client Test Suite">
17+
<directory>./tests/</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<filter>
22+
<whitelist>
23+
<directory suffix=".php">./src/</directory>
24+
</whitelist>
25+
</filter>
26+
27+
<logging>
28+
<log type="coverage-html" target="./build/coverage" charset="UTF-8"
29+
title="Recordings Service"
30+
yui="true" highlight="true"
31+
lowUpperBound="35" highLowerBound="70" />
32+
<log type="coverage-clover" target="./build/logs/clover.xml"/>
33+
<log type="junit" target="./build/logs/junit.xml"
34+
logIncompleteSkipped="false"/>
35+
<log type="testdox-html" target="./build/testdox.html" />
36+
</logging>
37+
</phpunit>

src/Client.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Matricali\Http;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
use Psr\Http\Message\ResponseInterface;
7+
8+
class Client
9+
{
10+
protected $handle = null;
11+
12+
public function sendRequest(RequestInterface $request): ResponseInterface
13+
{
14+
if ($this->handle === null) {
15+
$this->handle = curl_init();
16+
}
17+
18+
$ret = curl_exec($this->handle);
19+
}
20+
21+
public function get($uri, $headers = []): ResponseInterface
22+
{
23+
$request = new Request('GET', $uri, $headers);
24+
return $this->sendRequest($request);
25+
}
26+
}

src/Client/Exception.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Matricali\Http\Client;
4+
5+
class Exception extends \Exception
6+
{
7+
}

src/Request.php

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
3+
namespace Matricali\Http;
4+
5+
use Psr\Http\Message\RequestInterface;
6+
use Psr\Http\Message\ResponseInterface;
7+
8+
class Request
9+
{
10+
protected $method = 'GET';
11+
protected $uri;
12+
13+
public function __construct($uri)
14+
{
15+
16+
}
17+
18+
/**
19+
* Retrieves the message's request target.
20+
*
21+
* Retrieves the message's request-target either as it will appear (for
22+
* clients), as it appeared at request (for servers), or as it was
23+
* specified for the instance (see withRequestTarget()).
24+
*
25+
* In most cases, this will be the origin-form of the composed URI,
26+
* unless a value was provided to the concrete implementation (see
27+
* withRequestTarget() below).
28+
*
29+
* If no URI is available, and no request-target has been specifically
30+
* provided, this method MUST return the string "/".
31+
*
32+
* @return string
33+
*/
34+
public function getRequestTarget()
35+
{
36+
37+
}
38+
39+
/**
40+
* Return an instance with the specific request-target.
41+
*
42+
* If the request needs a non-origin-form request-target — e.g., for
43+
* specifying an absolute-form, authority-form, or asterisk-form —
44+
* this method may be used to create an instance with the specified
45+
* request-target, verbatim.
46+
*
47+
* This method MUST be implemented in such a way as to retain the
48+
* immutability of the message, and MUST return an instance that has the
49+
* changed request target.
50+
*
51+
* @link http://tools.ietf.org/html/rfc7230#section-5.3 (for the various
52+
* request-target forms allowed in request messages)
53+
* @param mixed $requestTarget
54+
* @return static
55+
*/
56+
public function withRequestTarget($requestTarget)
57+
{
58+
59+
}
60+
61+
/**
62+
* Retrieves the HTTP method of the request.
63+
*
64+
* @return string Returns the request method.
65+
*/
66+
public function getMethod()
67+
{
68+
return $this->method;
69+
}
70+
71+
/**
72+
* Return an instance with the provided HTTP method.
73+
*
74+
* While HTTP method names are typically all uppercase characters, HTTP
75+
* method names are case-sensitive and thus implementations SHOULD NOT
76+
* modify the given string.
77+
*
78+
* This method MUST be implemented in such a way as to retain the
79+
* immutability of the message, and MUST return an instance that has the
80+
* changed request method.
81+
*
82+
* @param string $method Case-sensitive method.
83+
* @return static
84+
* @throws \InvalidArgumentException for invalid HTTP methods.
85+
*/
86+
public function withMethod($method)
87+
{
88+
89+
}
90+
91+
/**
92+
* Retrieves the URI instance.
93+
*
94+
* This method MUST return a UriInterface instance.
95+
*
96+
* @link http://tools.ietf.org/html/rfc3986#section-4.3
97+
* @return UriInterface Returns a UriInterface instance
98+
* representing the URI of the request.
99+
*/
100+
public function getUri()
101+
{
102+
return $this->uri;
103+
}
104+
105+
/**
106+
* Returns an instance with the provided URI.
107+
*
108+
* This method MUST update the Host header of the returned request by
109+
* default if the URI contains a host component. If the URI does not
110+
* contain a host component, any pre-existing Host header MUST be carried
111+
* over to the returned request.
112+
*
113+
* You can opt-in to preserving the original state of the Host header by
114+
* setting `$preserveHost` to `true`. When `$preserveHost` is set to
115+
* `true`, this method interacts with the Host header in the following ways:
116+
*
117+
* - If the Host header is missing or empty, and the new URI contains
118+
* a host component, this method MUST update the Host header in the returned
119+
* request.
120+
* - If the Host header is missing or empty, and the new URI does not contain a
121+
* host component, this method MUST NOT update the Host header in the returned
122+
* request.
123+
* - If a Host header is present and non-empty, this method MUST NOT update
124+
* the Host header in the returned request.
125+
*
126+
* This method MUST be implemented in such a way as to retain the
127+
* immutability of the message, and MUST return an instance that has the
128+
* new UriInterface instance.
129+
*
130+
* @link http://tools.ietf.org/html/rfc3986#section-4.3
131+
* @param UriInterface $uri New request URI to use.
132+
* @param bool $preserveHost Preserve the original state of the Host header.
133+
* @return static
134+
*/
135+
public function withUri(UriInterface $uri, $preserveHost = false)
136+
{
137+
138+
}
139+
}

0 commit comments

Comments
 (0)