Skip to content

Commit

Permalink
Merge pull request #32 from stil/dev
Browse files Browse the repository at this point in the history
Update of dependencies and dust off
  • Loading branch information
stil authored May 20, 2017
2 parents fd2002d + e708c85 commit 8bbfd24
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 129 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: php
php:
- 5.5
- 5.4
- '7.1'
install:
- composer self-update
- composer install
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Travis](https://img.shields.io/travis/stil/curl-easy.svg)](https://travis-ci.org/stil/curl-easy)
[![Latest Stable Version](https://poser.pugx.org/stil/curl-easy/v/stable)](https://packagist.org/packages/stil/curl-easy) [![Total Downloads](https://poser.pugx.org/stil/curl-easy/downloads)](https://packagist.org/packages/stil/curl-easy) [![License](https://poser.pugx.org/stil/curl-easy/license)](https://packagist.org/packages/stil/curl-easy)

# Table of contents
Expand Down Expand Up @@ -39,15 +40,10 @@ If you need high speed crawling in your project, you might be interested in stil

## Installation
In order to use cURL-PHP library you need to install the » libcurl package.
It also requires PHP 5.3 or newer and Symfony's EventDispatcher 2.1.* or newer.

[Composer](http://getcomposer.org) is recommended for installation.
```json
{
"require": {
"stil/curl-easy": "*"
}
}
Install this library as [Composer](http://getcomposer.org) package with following command:
```bash
composer require stil/curl-easy
```
## Examples
### Single request with blocking
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"description": "cURL wrapper for PHP. Supports parallel and non-blocking requests. For high speed crawling, see stil/curl-robot.",
"license": "MIT",
"require": {
"symfony/event-dispatcher": "^3.0"
"symfony/event-dispatcher": "^3.2"
},
"require-dev": {
"phpunit/phpunit": "^5.4"
"phpunit/phpunit": "^6.1"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 8 additions & 7 deletions src/Collection.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

namespace cURL;

class Collection
{
/**
* @var array Collection
*/
protected $data = array();
protected $data = [];

/**
* Converts current object to array
*
Expand All @@ -17,11 +18,11 @@ public function toArray()
{
return $this->data;
}

/**
* Sets value
*
* @param mixed $key Key
* @param mixed $key Key
* @param mixed $value Value
* @return self
*/
Expand All @@ -36,7 +37,7 @@ public function set($key, $value = null)
}
return $this;
}

/**
* Checks if key does exist
*
Expand All @@ -47,7 +48,7 @@ public function has($key)
{
return isset($this->data[$key]);
}

/**
* Returns value of $key
*
Expand All @@ -63,7 +64,7 @@ public function get($key)
throw new Exception('Key does not exist.');
}
}

/**
* Removes key
*
Expand Down
3 changes: 2 additions & 1 deletion src/ConstantsTable.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace cURL;

class ConstantsTable
Expand Down Expand Up @@ -37,7 +38,7 @@ public static function findNumericValue($const)

$const = strtoupper($const);
if (!isset($table[$const])) {
throw new Exception('Constant CURLOPT_'.$const.' does not exist.');
throw new Exception('Constant CURLOPT_' . $const . ' does not exist.');
}

return $table[$const];
Expand Down
1 change: 1 addition & 0 deletions src/Error.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace cURL;

class Error extends \Exception
Expand Down
25 changes: 13 additions & 12 deletions src/Event.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?php

namespace cURL;

use Symfony\Component\EventDispatcher\Event as SymfonyEvent;

class Event extends SymfonyEvent
{
/**
* @var Response
*/
public $response;
/**
* @var Response
*/
public $response;

/**
* @var Request
*/
public $request;
/**
* @var Request
*/
public $request;

/**
* @var RequestsQueue
*/
public $queue;
/**
* @var RequestsQueue
*/
public $queue;
}
1 change: 1 addition & 0 deletions src/Exception.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace cURL;

class Exception extends \Exception
Expand Down
5 changes: 3 additions & 2 deletions src/Options.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace cURL;

class Options extends Collection
Expand All @@ -14,10 +15,10 @@ public function applyTo(Request $request)
if (!empty($this->data)) {
curl_setopt_array($request->getHandle(), $this->data);
}

return $this;
}

/**
* Intelligent setters
*
Expand Down
25 changes: 13 additions & 12 deletions src/Request.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace cURL;

use Symfony\Component\EventDispatcher\EventDispatcher;
Expand All @@ -9,17 +10,17 @@ class Request extends EventDispatcher implements RequestInterface
* @var resource cURL handler
*/
protected $ch;

/**
* @var RequestsQueue Queue instance when requesting async
*/
protected $queue;

/**
* @var Options Object containing options for current request
*/
protected $options = null;

/**
* Create new cURL handle
*
Expand All @@ -32,7 +33,7 @@ public function __construct($url = null)
}
$this->ch = curl_init();
}

/**
* Closes cURL resource and frees the memory.
* It is neccessary when you make a lot of requests
Expand All @@ -44,7 +45,7 @@ public function __destruct()
curl_close($this->ch);
}
}

/**
* Get the cURL\Options instance
* Creates empty one if does not exist
Expand All @@ -58,28 +59,28 @@ public function getOptions()
}
return $this->options;
}

/**
* Sets Options
*
*
* @param Options $options Options
* @return void
*/
public function setOptions(Options $options)
{
$this->options = $options;
}

/**
* Returns cURL raw resource
*
*
* @return resource cURL handle
*/
public function getHandle()
{
return $this->ch;
}

/**
* Get unique id of cURL handle
* Useful for debugging or logging.
Expand All @@ -90,7 +91,7 @@ public function getUID()
{
return (int)$this->ch;
}

/**
* Perform a cURL session.
* Equivalent to curl_exec().
Expand All @@ -107,7 +108,7 @@ public function send()
$this->options->applyTo($this);
}
$content = curl_exec($this->ch);

$response = new Response($this, $content);
$errorCode = curl_errno($this->ch);
if ($errorCode !== CURLE_OK) {
Expand Down
6 changes: 6 additions & 0 deletions src/RequestInterface.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php

namespace cURL;

interface RequestInterface
{
public function getOptions();

public function setOptions(Options $options);

public function getUID();

public function socketPerform();

public function socketSelect($timeout);

public function send();
}
Loading

0 comments on commit 8bbfd24

Please sign in to comment.