Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: chroma-x/php-basic-http-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.3.7
Choose a base ref
...
head repository: chroma-x/php-basic-http-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 13 commits
  • 36 files changed
  • 4 contributors

Commits on Nov 13, 2018

  1. Language level migration.

    Martin Brecht-Precht committed Nov 13, 2018
    Copy the full SHA
    ffb193e View commit details
  2. Updated readme.

    Martin Brecht-Precht committed Nov 13, 2018
    Copy the full SHA
    788db01 View commit details

Commits on Nov 14, 2018

  1. Updated readme.

    Martin Brecht-Precht committed Nov 14, 2018
    Copy the full SHA
    9976538 View commit details
  2. Code cleanup.

    Martin Brecht-Precht committed Nov 14, 2018
    Copy the full SHA
    4a81a85 View commit details

Commits on Jul 15, 2019

  1. Fixed an method change issue.

    Martin Brecht-Precht committed Jul 15, 2019
    Copy the full SHA
    d110a71 View commit details

Commits on Jan 18, 2021

  1. Change root namespace and vendor prefixes

    Martin Brecht-Precht committed Jan 18, 2021
    Copy the full SHA
    de3a634 View commit details

Commits on Feb 24, 2022

  1. Copy the full SHA
    d0bdb88 View commit details

Commits on Jul 24, 2024

  1. Included PHP 8.3

    Bonscho committed Jul 24, 2024
    Copy the full SHA
    ee39e9c View commit details

Commits on Aug 1, 2024

  1. Copy the full SHA
    20bc9ef View commit details
  2. Merge pull request #2 from andriusbaliutis/master

    Upgrade library for PHP 8 compatibility
    Bonscho authored Aug 1, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    82b4e6e View commit details

Commits on Aug 2, 2024

  1. Copy the full SHA
    c131463 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    9d322f0 View commit details
  3. Merge pull request #3 from andriusbaliutis/master

    Fix issue with statistics class property redirect url
    Bonscho authored Aug 2, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    86d4338 View commit details
Showing with 700 additions and 1,735 deletions.
  1. +0 −32 .codeclimate.yml
  2. +0 −29 .travis.yml
  3. +1 −1 LICENSE
  4. +40 −40 README.md
  5. +37 −35 composer.json
  6. +0 −17 phpunit.xml.dist
  7. +24 −73 src/BasicHttpClient.php
  8. +4 −2 src/Exception/HttpRequestAuthenticationException.php
  9. +4 −2 src/Exception/HttpRequestException.php
  10. +4 −2 src/Exception/HttpRequestMessageException.php
  11. +4 −2 src/Exception/HttpResponseException.php
  12. +18 −44 src/HttpClientInterface.php
  13. +93 −198 src/Request/AbstractRequest.php
  14. +7 −10 src/Request/Authentication/AuthenticationInterface.php
  15. +16 −50 src/Request/Authentication/BasicAuthentication.php
  16. +26 −75 src/Request/Authentication/ClientCertificateAuthentication.php
  17. +5 −7 src/Request/Base/CurlConfiguratorInterface.php
  18. +12 −38 src/Request/Message/Body/Body.php
  19. +5 −3 src/Request/Message/Body/BodyInterface.php
  20. +13 −43 src/Request/Message/Cookie/Cookie.php
  21. +13 −31 src/Request/Message/Cookie/CookieInterface.php
  22. +15 −40 src/Request/Message/Header/Header.php
  23. +17 −41 src/Request/Message/Header/HeaderInterface.php
  24. +54 −185 src/Request/Message/Message.php
  25. +36 −120 src/Request/Message/MessageInterface.php
  26. +7 −8 src/Request/Request.php
  27. +41 −108 src/Request/RequestInterface.php
  28. +34 −121 src/Request/Transport/HttpTransport.php
  29. +28 −20 src/Request/Transport/HttpsTransport.php
  30. +28 −68 src/Request/Transport/TransportInterface.php
  31. +37 −108 src/Response/AbstractResponse.php
  32. +15 −40 src/Response/Header/Header.php
  33. +5 −3 src/Response/Response.php
  34. +17 −49 src/Response/ResponseInterface.php
  35. +35 −83 src/Response/Statistics/Statistics.php
  36. +5 −7 src/Util/HeaderNameUtil.php
32 changes: 0 additions & 32 deletions .codeclimate.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Martin Brecht-Precht, Markenwerk GmbH
Copyright (c) 2016 Martin Brecht-Precht, Chroma Experience GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
80 changes: 40 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# PHP Basic HTTP Client

[![Build Status](https://travis-ci.org/markenwerk/php-basic-http-client.svg?branch=master)](https://travis-ci.org/markenwerk/php-basic-http-client)
[![Test Coverage](https://codeclimate.com/github/markenwerk/php-basic-http-client/badges/coverage.svg)](https://codeclimate.com/github/markenwerk/php-basic-http-client/coverage)
[![Dependency Status](https://www.versioneye.com/user/projects/571f8827fcd19a00415b2836/badge.svg)](https://www.versioneye.com/user/projects/571f8827fcd19a00415b2836)
[![Build Status](https://travis-ci.org/chroma-x/php-basic-http-client.svg?branch=master)](https://travis-ci.org/chroma-x/php-basic-http-client)
[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/0bc596c2-5849-4e0f-a46f-a7b94d28f97c.svg)](https://insight.sensiolabs.com/projects/0bc596c2-5849-4e0f-a46f-a7b94d28f97c)
[![Code Climate](https://codeclimate.com/github/markenwerk/php-basic-http-client/badges/gpa.svg)](https://codeclimate.com/github/markenwerk/php-basic-http-client)
[![Latest Stable Version](https://poser.pugx.org/markenwerk/basic-http-client/v/stable)](https://packagist.org/packages/markenwerk/basic-http-client)
[![Total Downloads](https://poser.pugx.org/markenwerk/basic-http-client/downloads)](https://packagist.org/packages/markenwerk/basic-http-client)
[![License](https://poser.pugx.org/markenwerk/basic-http-client/license)](https://packagist.org/packages/markenwerk/basic-http-client)
[![Code Climate](https://codeclimate.com/github/chroma-x/php-basic-http-client/badges/gpa.svg)](https://codeclimate.com/github/chroma-x/php-basic-http-client)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/03db69a367dd4bbbbbd03e4612dfdbe5)](https://www.codacy.com/app/Bonscho/php-basic-http-client?utm_source=github.com&utm_medium=referral&utm_content=chroma-x/php-basic-http-client&utm_campaign=Badge_Grade)
[![Latest Stable Version](https://poser.pugx.org/chroma-x/basic-http-client/v/stable)](https://packagist.org/packages/chroma-x/basic-http-client)
[![Total Downloads](https://poser.pugx.org/chroma-x/basic-http-client/downloads)](https://packagist.org/packages/chroma-x/basic-http-client)
[![License](https://poser.pugx.org/chroma-x/basic-http-client/license)](https://packagist.org/packages/chroma-x/basic-http-client)

A basic yet extensible HTTP client library providing different authentication methods written in PHP.

@@ -27,7 +26,7 @@ Find out more at the [„PSR-7 is imminent, and here's my issues with it“](htt
```{json}
{
"require": {
"markenwerk/basic-http-client": "~3.0"
"chroma-x/basic-http-client": "~4.0"
}
}
```
@@ -45,9 +44,9 @@ require_once('path/to/vendor/autoload.php');
#### Preparing the HTTP client

```{php}
use Markenwerk\BasicHttpClient;
use Markenwerk\BasicHttpClient\Request\Authentication;
use Markenwerk\BasicHttpClient\Request\Message;
use ChromaX\BasicHttpClient;
use ChromaX\BasicHttpClient\Request\Authentication;
use ChromaX\BasicHttpClient\Request\Message;
// Instantiating a basic HTTP client with the endpoints URL
// If the endpoint uses the `HTTPS` schema a `HttpsTransport` instance will be used automatically.
@@ -132,10 +131,10 @@ The same mechanic is offered to perform `PUT` and `PATCH` requests wich all are

The following example shows the usage with a more detailed configuration.

#### Configuring a HTTP Transport instance
#### Configuring an HTTP Transport instance

```{php}
use Markenwerk\BasicHttpClient\Request\Transport\HttpTransport;
use ChromaX\BasicHttpClient\Request\Transport\HttpTransport;
// Configuring a Transport instance
$transport = new HttpTransport();
@@ -148,10 +147,10 @@ $transport
->setMaxRedirects(10);
```

#### Configuring a HTTPS Transport instance
#### Configuring an HTTPS Transport instance

```{php}
use Markenwerk\BasicHttpClient\Request\Transport\HttpsTransport;
use ChromaX\BasicHttpClient\Request\Transport\HttpsTransport;
// Configuring a Transport instance
$transport = new HttpsTransport();
@@ -162,16 +161,17 @@ $transport
->setAllowCaching(true)
->setFollowRedirects(true)
->setMaxRedirects(10)
->setVerifyHost(true)
->setVerifyPeer(true);
```

#### Configuring a Message instance with Body

```{php}
use Markenwerk\BasicHttpClient\Request\Message\Body\Body;
use Markenwerk\BasicHttpClient\Request\Message\Cookie\Cookie;
use Markenwerk\BasicHttpClient\Request\Message\Header\Header;
use Markenwerk\BasicHttpClient\Request\Message\Message;
use ChromaX\BasicHttpClient\Request\Message\Body\Body;
use ChromaX\BasicHttpClient\Request\Message\Cookie\Cookie;
use ChromaX\BasicHttpClient\Request\Message\Header\Header;
use ChromaX\BasicHttpClient\Request\Message\Message;
// Configuring a message Body instance
$messageBody = new Body();
@@ -219,12 +219,12 @@ $message->addAdditionalHeader(new Header('Custom-Header', array('AnotherCustomHe

#### Configuring an endpoints URL, build the Request instance and perform the HTTP request

For more information about the usage of the URL object please take a look at the [PHP URL Util](https://github.com/markenwerk/php-url-util) project.
For more information about the usage of the URL object please take a look at the [PHP URL Util](https://github.com/chroma-x/php-url-util) project.

```{php}
use Markenwerk\BasicHttpClient\Request\Authentication\BasicAuthentication;
use Markenwerk\BasicHttpClient\Request\Request;
use Markenwerk\UrlUtil\Url;
use ChromaX\BasicHttpClient\Request\Authentication\BasicAuthentication;
use ChromaX\BasicHttpClient\Request\Request;
use ChromaX\UrlUtil\Url;
// Setting up the endpoints URL
$url = new Url('https://john:secret@yourapihere-com-98yq3775xff0.runscope.net:443/path/to/resource?arg1=123#fragment');
@@ -274,8 +274,8 @@ You can add one or more Authentication instances to every Request instance. At t
Required credentials are a *username* and a *password* that get provided to the class constructor as arguments.

```{php}
use Markenwerk\BasicHttpClient\Request\Authentication\BasicAuthentication;
use Markenwerk\BasicHttpClient\Request\Request;
use ChromaX\BasicHttpClient\Request\Authentication\BasicAuthentication;
use ChromaX\BasicHttpClient\Request\Request;
// Configuring the authentication
$basicAuthentication = new BasicAuthentication('username', 'password');
@@ -290,8 +290,8 @@ $request->addAuthentication($basicAuthentication);
Required credentials are a *Certificate Authority Certificate*, a *Client Certificate* and the password that is used to decrypt the Client Certificate that get provided to the class constructor as arguments.

```{php}
use Markenwerk\BasicHttpClient\Request\Authentication\ClientCertificateAuthentication;
use Markenwerk\BasicHttpClient\Request\Request;
use ChromaX\BasicHttpClient\Request\Authentication\ClientCertificateAuthentication;
use ChromaX\BasicHttpClient\Request\Request;
// Configuring the authentication
$clientCertificateAuthentication = new ClientCertificateAuthentication(
@@ -314,7 +314,7 @@ $request->addAuthentication($clientCertificateAuthentication);
If using the `BasicHttpClient` the response object is returned by the termination methods listed above. If directly using the Request instance, you can get the Response object via a getter.

```{php}
// Getting the response Markenwerk\BasicHttpClient\Response\Response object
// Getting the response ChromaX\BasicHttpClient\Response\Response object
$response = $request->getResponse();
// Reading the HTTP status code as integer; will return `200`
@@ -323,7 +323,7 @@ echo print_r($response->getStatusCode(), true) . PHP_EOL;
// Reading the HTTP status text as string; will return `HTTP/1.1 200 OK`
echo print_r($response->getStatusText(), true) . PHP_EOL;
// Reading the HTTP response headers as array of Markenwerk\BasicHttpClient\Response\Header\Header objects
// Reading the HTTP response headers as array of ChromaX\BasicHttpClient\Response\Header\Header objects
echo print_r($response->getHeaders(), true) . PHP_EOL;
// Reading the HTTP response body as string
@@ -346,7 +346,7 @@ echo print_r($request->getEffectiveStatus(), true) . PHP_EOL;
// Getting the effective raw request headers as string
echo print_r($request->getEffectiveRawHeader(), true) . PHP_EOL;
// Getting the effective request headers as array of `Markenwerk\BasicHttpClient\Request\Message\Header\Header` objects
// Getting the effective request headers as array of `ChromaX\BasicHttpClient\Request\Message\Header\Header` objects
echo print_r($request->getEffectiveHeaders(), true) . PHP_EOL.PHP_EOL;
```

@@ -355,7 +355,7 @@ echo print_r($request->getEffectiveHeaders(), true) . PHP_EOL.PHP_EOL;
## Getting some transactional statistics

```{php}
// Getting the statistics Markenwerk\BasicHttpClient\Response\Statistics\Statistics object
// Getting the statistics ChromaX\BasicHttpClient\Response\Statistics\Statistics object
$statistics = $request->getResponse()->getStatistics();
// Reading the redirection URL if the server responds with an redirect HTTP header and
@@ -391,32 +391,32 @@ echo print_r($statistics->getTotalTime(), true).PHP_EOL;
Every part of the client is based upon proper interfaces. Most class instances can get injected into the client itself.
If you want to extend the client just write some classes implementing the according interface and you´re done with that.

Take a look at the [PHP JSON HTTP Client](https://github.com/markenwerk/php-json-http-client) which is an extension of the PHP Basic HTTP Client.
Take a look at the [PHP JSON HTTP Client](https://github.com/chroma-x/php-json-http-client) which is an extension of the PHP Basic HTTP Client.

---

## Exception handling

PHP Basic HTTP Client provides different exceptions – also provided by the PHP Common Exceptions project – for proper handling.
You can find more information about [PHP Common Exceptions at Github](https://github.com/markenwerk/php-common-exceptions).
You can find more information about [PHP Common Exceptions at Github](https://github.com/chroma-x/php-common-exceptions).

### Exceptions to be expected

In general you should expect that any setter method could thrown an `\InvalidArgumentException`. The following exceptions could get thrown while using PHP Basic HTTP Client.

- `Markenwerk\CommonException\IoException\FileNotFoundException` on configuring a `ClientCertificateAuthentication`instance
- `Markenwerk\CommonException\IoException\FileReadableException` on configuring a `ClientCertificateAuthentication`instance
- `Markenwerk\BasicHttpClient\Exception\HttpRequestAuthenticationException` on performing a request
- `Markenwerk\BasicHttpClient\Exception\HttpRequestException` on performing a request
- `Markenwerk\CommonException\NetworkException\ConnectionTimeoutException` on performing a request
- `Markenwerk\CommonException\NetworkException\CurlException` on performing a request
- `ChromaX\CommonException\IoException\FileNotFoundException` on configuring a `ClientCertificateAuthentication`instance
- `ChromaX\CommonException\IoException\FileReadableException` on configuring a `ClientCertificateAuthentication`instance
- `ChromaX\BasicHttpClient\Exception\HttpRequestAuthenticationException` on performing a request
- `ChromaX\BasicHttpClient\Exception\HttpRequestException` on performing a request
- `ChromaX\CommonException\NetworkException\ConnectionTimeoutException` on performing a request
- `ChromaX\CommonException\NetworkException\CurlException` on performing a request

---

## Contribution

Contributing to our projects is always very appreciated.
**But: please follow the contribution guidelines written down in the [CONTRIBUTING.md](https://github.com/markenwerk/php-basic-http-client/blob/master/CONTRIBUTING.md) document.**
**But: please follow the contribution guidelines written down in the [CONTRIBUTING.md](https://github.com/chroma-x/php-basic-http-client/blob/master/CONTRIBUTING.md) document.**

## License

72 changes: 37 additions & 35 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
{
"name": "markenwerk/basic-http-client",
"type": "library",
"description": "A basic yet extensible HTTP client library providing different authentication methods written in PHP.",
"keywords": [
"HTTP client",
"RESTful",
"JSON",
"SSL",
"Basic Auth",
"Client Certificate Auth"
],
"homepage": "http://markenwerk.net/",
"license": "MIT",
"authors": [
{
"name": "Martin Brecht-Precht",
"email": "mb@markenwerk.net",
"homepage": "http://markenwerk.net"
}
],
"autoload": {
"psr-4": {
"Markenwerk\\BasicHttpClient\\": "src/"
}
},
"require": {
"php": ">=5.3",
"lib-curl": "*",
"markenwerk/url-util": "~2.0",
"markenwerk/common-exceptions": "~3.0"
},
"require-dev": {
"phpunit/phpunit": ">=4.8.26",
"codeclimate/php-test-reporter": "dev-master"
}
"name": "chroma-x/basic-http-client",
"type": "library",
"description": "A basic yet extensible HTTP client library providing different authentication methods written in PHP.",
"keywords": [
"HTTP client",
"RESTful",
"JSON",
"SSL",
"Basic Auth",
"Client Certificate Auth"
],
"homepage": "https://chroma-x.de/",
"license": "MIT",
"authors": [
{
"name": "Martin Brecht-Precht",
"email": "mb@chroma-x.de",
"homepage": "https://chroma-x.de"
},
{
"name": "Andrius Baliutis",
"email": "ab@chroma-x.de",
"homepage": "https://chroma-x.de"
}
],
"autoload": {
"psr-4": {
"ChromaX\\BasicHttpClient\\": "src/"
}
},
"require": {
"php": "^8.3",
"ext-curl": "*",
"ext-mbstring": "*",
"chroma-x/url-util": "~2.0",
"chroma-x/common-exceptions": "~3.0"
}
}
17 changes: 0 additions & 17 deletions phpunit.xml.dist

This file was deleted.

Loading