mirror of
https://github.com/ivuorinen/curly.git
synced 2026-01-26 11:33:59 +00:00
Initial commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
.DS_Store
|
||||
19
LICENSE
Normal file
19
LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2018 Ismo Vuorinen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
23
README.md
Normal file
23
README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
Curly PHP Curl client
|
||||
=====================
|
||||
|
||||
Main features:
|
||||
|
||||
- BASIC, NTLM, DIGEST and SPNEGO auth authentication support
|
||||
- proxy support
|
||||
- allowed http methods: GET, POST, PUT, DELETE
|
||||
- request customization (User Agent, HTTP Version, Content Type, ...)
|
||||
|
||||
## Why?
|
||||
|
||||
Because I needed a CURL library that handled NTLM authentication and
|
||||
let me choose what parameters should be passed to the CURL instance.
|
||||
|
||||
## Usage
|
||||
|
||||
*todo*
|
||||
|
||||
## License
|
||||
|
||||
This package is released under the MIT License (MIT).
|
||||
Please see [License File](LICENSE) for more information.
|
||||
41
composer.json
Normal file
41
composer.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "ivuorinen/curly",
|
||||
"description": "HTTP Curl client capable of NTLM authentication",
|
||||
"keywords": [
|
||||
"http",
|
||||
"curl",
|
||||
"ntlm"
|
||||
],
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ismo Vuorinen",
|
||||
"email": "ismo@ivuorinen.net"
|
||||
}
|
||||
],
|
||||
"type": "project",
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"league/uri": "^5.3",
|
||||
"ext-curl": "*",
|
||||
"ext-zlib": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "6.*",
|
||||
"phpstan/phpstan": "^0.10.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ivuorinen\\Curly\\": "src/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"ivuorinen\\Curly\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit --colors --verbose",
|
||||
"check": "vendor/bin/phpstan analyse src tests --level=7"
|
||||
}
|
||||
}
|
||||
21
phpunit.xml
Normal file
21
phpunit.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false">
|
||||
<testsuites>
|
||||
<testsuite name="Test Suite">
|
||||
<directory suffix="Test.php">./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
1207
src/Curly.php
Normal file
1207
src/Curly.php
Normal file
File diff suppressed because it is too large
Load Diff
12
src/Exceptions/AuthenticationException.php
Normal file
12
src/Exceptions/AuthenticationException.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace ivuorinen\Curly\Exceptions;
|
||||
|
||||
/**
|
||||
* Class AuthenticationException
|
||||
* Extends \Exception
|
||||
*
|
||||
* @package ivuorinen\Curly\Exceptions
|
||||
*/
|
||||
class AuthenticationException extends \Exception
|
||||
{
|
||||
}
|
||||
14
src/Exceptions/HTTPException.php
Normal file
14
src/Exceptions/HTTPException.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace ivuorinen\Curly\Exceptions;
|
||||
|
||||
/**
|
||||
* Class HTTPException
|
||||
* Extends \Exception
|
||||
*
|
||||
* @package ivuorinen\Curly\Exceptions
|
||||
* @mixin \Exception
|
||||
*/
|
||||
class HTTPException extends \Exception
|
||||
{
|
||||
}
|
||||
61
tests/CurlyBasicsTest.php
Normal file
61
tests/CurlyBasicsTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace ivuorinen\Curly\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CurlyBasicsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Just check if the YourClass has no syntax error
|
||||
*
|
||||
* This is just a simple check to make sure your library has no
|
||||
* syntax error. This helps you troubleshoot any typo before you
|
||||
* even use this library in a real project.
|
||||
*
|
||||
* @throws \ivuorinen\Curly\Exceptions\HTTPException
|
||||
*/
|
||||
public function testIsThereAnySyntaxError()
|
||||
{
|
||||
$var = new \ivuorinen\Curly\Curly;
|
||||
$this->assertTrue(is_object($var));
|
||||
unset($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just check if the Curly has no syntax errors
|
||||
*
|
||||
* This is just a simple check to make sure your library has no
|
||||
* syntax error. This helps you troubleshoot any typo before you
|
||||
* even use this library in a real project.
|
||||
*
|
||||
* @throws \ivuorinen\Curly\Exceptions\HTTPException
|
||||
*/
|
||||
public function testParseData()
|
||||
{
|
||||
$var = new \ivuorinen\Curly\Curly;
|
||||
|
||||
$expected = "foo=bar&baz=buzz";
|
||||
|
||||
// String
|
||||
$this->assertTrue($var->parseData($expected) == $expected);
|
||||
|
||||
// Array
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$var->parseData(['foo' => 'bar', 'baz' => 'buzz'])
|
||||
);
|
||||
|
||||
// Object
|
||||
$actual = new \stdClass();
|
||||
$actual->foo = "bar";
|
||||
$actual->baz = "buzz";
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$var->parseData($actual)
|
||||
);
|
||||
|
||||
unset($var);
|
||||
}
|
||||
}
|
||||
207
tests/CurlyMethodsTest.php
Normal file
207
tests/CurlyMethodsTest.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace ivuorinen\Curly\Tests;
|
||||
|
||||
use ivuorinen\Curly\Curly;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CurlyMethodsTest extends TestCase
|
||||
{
|
||||
protected $curly = false;
|
||||
|
||||
public function testPort()
|
||||
{
|
||||
$this->assertEquals(80, $this->curly->getPort());
|
||||
$this->curly->setPort(1234);
|
||||
$this->assertEquals(1234, $this->curly->getPort());
|
||||
}
|
||||
|
||||
public function testTimeout()
|
||||
{
|
||||
$this->assertEquals(30, $this->curly->getTimeout());
|
||||
$this->curly->setTimeout(10);
|
||||
$this->assertEquals(10, $this->curly->getTimeout());
|
||||
}
|
||||
|
||||
public function testSkipSSLVerify()
|
||||
{
|
||||
$this->assertTrue(method_exists(
|
||||
$this->curly,
|
||||
'getSkipSSLVerify'
|
||||
));
|
||||
$this->assertTrue(method_exists(
|
||||
$this->curly,
|
||||
'setSkipSSLVerify'
|
||||
));
|
||||
|
||||
$this->assertFalse($this->curly->getSkipSSLVerify());
|
||||
$this->curly->setSkipSSLVerify(true);
|
||||
$this->assertTrue($this->curly->getSkipSSLVerify());
|
||||
$this->curly->setSkipSSLVerify(false);
|
||||
$this->assertFalse($this->curly->getSkipSSLVerify());
|
||||
}
|
||||
|
||||
public function testHttpMethod()
|
||||
{
|
||||
$this->assertTrue(method_exists($this->curly, 'getMethod'));
|
||||
$this->assertTrue(method_exists($this->curly, 'setMethod'));
|
||||
|
||||
$this->assertEquals('GET', $this->curly->getMethod());
|
||||
|
||||
$this->curly->setMethod('POST');
|
||||
$this->assertEquals(
|
||||
'POST',
|
||||
$this->curly->getMethod()
|
||||
);
|
||||
}
|
||||
|
||||
public function testVerbose()
|
||||
{
|
||||
$this->assertTrue(method_exists($this->curly, 'getVerbose'));
|
||||
$this->assertTrue(method_exists($this->curly, 'setVerbose'));
|
||||
|
||||
$this->assertFalse($this->curly->getVerbose());
|
||||
$this->curly->setVerbose(true);
|
||||
$this->assertTrue($this->curly->getVerbose());
|
||||
}
|
||||
|
||||
public function testProxy()
|
||||
{
|
||||
$this->assertTrue(method_exists($this->curly, 'getProxy'));
|
||||
$this->assertTrue(method_exists($this->curly, 'setProxy'));
|
||||
|
||||
$this->assertNull($this->curly->getProxy());
|
||||
|
||||
$proxy = 'http://example.com';
|
||||
$this->curly->setProxy($proxy);
|
||||
$this->assertEquals($proxy, $this->curly->getProxy());
|
||||
}
|
||||
|
||||
public function testUserAgent()
|
||||
{
|
||||
$this->assertTrue(method_exists($this->curly, 'getUserAgent'));
|
||||
$this->assertTrue(method_exists($this->curly, 'setUserAgent'));
|
||||
|
||||
$this->assertEquals(
|
||||
'ivuorinen-curly',
|
||||
$this->curly->getUserAgent()
|
||||
);
|
||||
|
||||
$this->curly->setUserAgent('testing');
|
||||
$this->assertEquals(
|
||||
'testing',
|
||||
$this->curly->getUserAgent()
|
||||
);
|
||||
}
|
||||
|
||||
public function testHeaders()
|
||||
{
|
||||
$this->assertTrue(method_exists(
|
||||
$this->curly, 'getHeaders'
|
||||
));
|
||||
$this->assertTrue(method_exists(
|
||||
$this->curly, 'setHeader'
|
||||
));
|
||||
$this->assertTrue(method_exists(
|
||||
$this->curly, 'getHeader'
|
||||
));
|
||||
$this->assertTrue(method_exists(
|
||||
$this->curly, 'unsetHeader'
|
||||
));
|
||||
|
||||
$headers = $this->curly->getHeaders();
|
||||
|
||||
$defaultHeaders = [
|
||||
'Accept',
|
||||
'Accept-Language',
|
||||
'Accept-Encoding',
|
||||
'Accept-Charset'
|
||||
];
|
||||
foreach ($defaultHeaders as $defaultHeader) {
|
||||
$this->assertArrayHasKey(
|
||||
$defaultHeader, $headers, $defaultHeader
|
||||
);
|
||||
|
||||
$this->curly->setHeader($defaultHeader, 'testing');
|
||||
|
||||
$this->assertEquals(
|
||||
'testing',
|
||||
$this->curly->getHeader($defaultHeader)
|
||||
);
|
||||
|
||||
$this->curly->unsetHeader($defaultHeader);
|
||||
$this->assertFalse($this->curly->getHeader($defaultHeader));
|
||||
}
|
||||
}
|
||||
|
||||
public function testContentType()
|
||||
{
|
||||
$this->assertTrue(method_exists(
|
||||
$this->curly, 'getContentType'
|
||||
));
|
||||
$this->assertTrue(method_exists(
|
||||
$this->curly, 'setContentType'
|
||||
));
|
||||
|
||||
$default = 'application/x-www-form-urlencoded';
|
||||
$this->assertEquals($default, $this->curly->getContentType());
|
||||
|
||||
$this->curly->setContentType('testing');
|
||||
$this->assertEquals(
|
||||
'testing',
|
||||
$this->curly->getContentType()
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuth()
|
||||
{
|
||||
$this->curly->setAuth(
|
||||
'BASIC',
|
||||
'user',
|
||||
'pass'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'BASIC',
|
||||
$this->curly->getAuthenticationMethod()
|
||||
);
|
||||
$this->assertEquals('user', $this->curly->getUser());
|
||||
$this->assertEquals('pass', $this->curly->getPass());
|
||||
}
|
||||
|
||||
public function testHttpVersion()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'1.0',
|
||||
$this->curly->getHttpVersion()
|
||||
);
|
||||
|
||||
$this->curly->setHttpVersion('1.1');
|
||||
$this->assertEquals(
|
||||
'1.1',
|
||||
$this->curly->getHttpVersion()
|
||||
);
|
||||
|
||||
$this->curly->setHttpVersion('1.2');
|
||||
$this->assertEquals(
|
||||
'NONE',
|
||||
$this->curly->getHttpVersion()
|
||||
);
|
||||
}
|
||||
|
||||
public function testHost()
|
||||
{
|
||||
$test = 'http://user:password@example.com/xyz';
|
||||
$this->curly->setHost($test);
|
||||
$this->assertEquals($test, $this->curly->getHost());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \ivuorinen\Curly\Exceptions\HTTPException
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->curly = new Curly;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user