Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Coding standards

  • Loading branch information...
commit 0a435c069122a013b48a6f26454999fcc333cbee 1 parent 98177fd
@mtdowling mtdowling authored
View
4 Curl/CurlHandle.php
@@ -37,7 +37,7 @@ class CurlHandle
public static function factory(RequestInterface $request)
{
$handle = curl_init();
-
+
// Array of default cURL options.
$curlOptions = array(
CURLOPT_URL => $request->getUrl(),
@@ -256,7 +256,7 @@ public function getStderr($asResource = false)
fseek($stderr, 0);
$e = stream_get_contents($stderr);
fseek($stderr, 0, SEEK_END);
-
+
return $e;
}
View
3  Message/RequestFactory.php
@@ -27,7 +27,8 @@ class RequestFactory
'content-length', 'content-type', 'date', 'expect', 'from', 'host',
'if-match', 'if-modified-since', 'if-none-match', 'if-range',
'if-unmodified-since', 'max-forwards', 'pragma', 'proxy-authorization',
- 'range', 'referer', 'te', 'transfer-encoding', 'upgrade', 'user-agent', 'via', 'warning'
+ 'range', 'referer', 'te', 'transfer-encoding', 'upgrade', 'user-agent',
+ 'via', 'warning'
);
/**
View
19 Plugin/BasicAuthPlugin.php
@@ -14,14 +14,6 @@ class BasicAuthPlugin implements EventSubscriberInterface
private $password;
/**
- * {@inheritdoc}
- */
- public static function getSubscribedEvents()
- {
- return array('client.create_request' => 'onRequestCreate');
- }
-
- /**
* Constructor
*
* @param string $username HTTP basic auth username
@@ -34,13 +26,20 @@ public function __construct($username, $password)
}
/**
+ * {@inheritdoc}
+ */
+ public static function getSubscribedEvents()
+ {
+ return array('client.create_request' => array('onRequestCreate', 255));
+ }
+
+ /**
* Add basic auth
*
* @param Event $event
*/
public function onRequestCreate(Event $event)
{
- $request = $event['request'];
- $request->setAuth($this->username, $this->password);
+ $event['request']->setAuth($this->username, $this->password);
}
}
View
34 Plugin/BatchQueuePlugin.php
@@ -20,24 +20,24 @@ class BatchQueuePlugin implements EventSubscriberInterface, \Countable
private $queue = array();
/**
- * {@inheritdoc}
+ * @param int $autoFlushCount (optional) Set to >0 to automatically flush
+ * the queue when the number of requests is > $autoFlushCount
*/
- public static function getSubscribedEvents()
+ public function __construct($autoFlushCount = 0)
{
- return array(
- 'client.create_request' => 'onRequestCreate',
- 'request.before_send' => 'onRequestBeforeSend',
- 'flush' => 'flush'
- );
+ $this->autoFlushCount = $autoFlushCount;
}
/**
- * @param int $autoFlushCount (optional) Set to >0 to automatically flush
- * the queue when the number of requests is > $autoFlushCount
+ * {@inheritdoc}
*/
- public function __construct($autoFlushCount = 0)
+ public static function getSubscribedEvents()
{
- $this->autoFlushCount = $autoFlushCount;
+ return array(
+ 'client.create_request' => array('onRequestCreate', -255),
+ 'request.before_send' => array('onRequestBeforeSend', 255),
+ 'flush' => array('flush', -255)
+ );
}
/**
@@ -74,11 +74,9 @@ public function removeRequest(RequestInterface $request)
*/
public function onRequestCreate(Event $event)
{
- if ($event['request']) {
- $this->queue[] = $event['request'];
- if ($this->autoFlushCount && count($this->queue) >= $this->autoFlushCount) {
- $this->flush();
- }
+ $this->queue[] = $event['request'];
+ if ($this->autoFlushCount && count($this->queue) >= $this->autoFlushCount) {
+ $this->flush();
}
}
@@ -90,9 +88,7 @@ public function onRequestCreate(Event $event)
*/
public function onRequestBeforeSend(Event $event)
{
- if ($event['request']) {
- $this->removeRequest($event['request']);
- }
+ $this->removeRequest($event['request']);
}
/**
View
22 Plugin/CachePlugin.php
@@ -51,17 +51,6 @@ class CachePlugin implements EventSubscriberInterface
);
/**
- * {@inheritdoc}
- */
- public static function getSubscribedEvents()
- {
- return array(
- 'request.before_send' => 'onRequestBeforeSend',
- 'request.sent' => 'onRequestSent'
- );
- }
-
- /**
* Construct a new CachePlugin
*
* @param CacheAdapterInterface $adapter Cache adapter to write and read cache data
@@ -78,6 +67,17 @@ public function __construct(CacheAdapterInterface $adapter, $serialize = false,
}
/**
+ * {@inheritdoc}
+ */
+ public static function getSubscribedEvents()
+ {
+ return array(
+ 'request.before_send' => array('onRequestBeforeSend', -255),
+ 'request.sent' => array('onRequestSent', 255)
+ );
+ }
+
+ /**
* Get the cache adapter object
*
* @return CacheAdapter
View
50 Plugin/CookiePlugin.php
@@ -17,18 +17,6 @@ class CookiePlugin implements EventSubscriberInterface
* @var CookieJarInterface
*/
protected $jar;
-
- /**
- * {@inheritdoc}
- */
- public static function getSubscribedEvents()
- {
- return array(
- 'request.before_send' => 'onRequestBeforeSend',
- 'request.sent' => 'onRequestSent',
- 'request.receive.status_line' => 'onRequestReceiveStatusLine'
- );
- }
/**
* Create a new CookiePlugin
@@ -49,6 +37,18 @@ public function __destruct()
}
/**
+ * {@inheritdoc}
+ */
+ public static function getSubscribedEvents()
+ {
+ return array(
+ 'request.before_send' => array('onRequestBeforeSend', 100),
+ 'request.sent' => array('onRequestSent', 100),
+ 'request.receive.status_line' => 'onRequestReceiveStatusLine'
+ );
+ }
+
+ /**
* Parse a cookie string as set in a Set-Cookie HTTP header and return data
* about the cookie
*
@@ -154,7 +154,7 @@ public static function parseCookie($cookie, RequestInterface $request = null, $d
$value = ($decode && $value && !is_bool($value)) ? urldecode($value) : $value;
if (0 == $foundCookies || !$found) {
- // If cookies have not yet been retrieved, or this value was
+ // If cookies have not yet been retrieved, or this value was
// not found in the cookie pieces array, treat as a cookie
// IF non-cookies have been parsed, then this isn't a cookie,
// but it's cookie data. Cookies must be first, followed by data.
@@ -220,7 +220,7 @@ public function addCookies(RequestInterface $request)
}
}
}
-
+
return $match && $cookies ? $cookies : array();
}
@@ -235,7 +235,7 @@ public function extractCookies(Response $response)
if (!$cookie = $response->getSetCookie()) {
return array();
}
-
+
$cookieData = array();
foreach ((array) $cookie as $c) {
$cdata = self::parseCookie($c, $response->getRequest());
@@ -268,7 +268,7 @@ public function extractCookies(Response $response)
}
}
}
-
+
return $cookieData;
}
@@ -306,31 +306,31 @@ public function clearTemporaryCookies()
{
return $this->jar->clearTemporary();
}
-
+
/**
* Add cookies before a request is sent
- *
- * @param Event $event
+ *
+ * @param Event $event
*/
public function onRequestBeforeSend(Event $event)
{
$this->addCookies($event['request']);
}
-
+
/**
* Extract cookies from a sent request
- *
- * @param Event $event
+ *
+ * @param Event $event
*/
public function onRequestSent(Event $event)
{
$this->extractCookies($event['response']);
}
-
+
/**
* Extract cookies from a redirect response
- *
- * @param Event $event
+ *
+ * @param Event $event
*/
public function onRequestReceiveStatusLine(Event $event)
{
View
34 Plugin/ExponentialBackoffPlugin.php
@@ -35,17 +35,6 @@ class ExponentialBackoffPlugin implements EventSubscriberInterface
* @var Closure
*/
protected $delayClosure;
-
- /**
- * {@inheritdoc}
- */
- public static function getSubscribedEvents()
- {
- return array(
- 'request.sent' => 'onRequestSent',
- CurlMultiInterface::POLLING_REQUEST => 'onRequestPoll'
- );
- }
/**
* Construct a new exponential backoff plugin
@@ -66,6 +55,17 @@ public function __construct($maxRetries = 3, array $failureCodes = null, $delayC
}
/**
+ * {@inheritdoc}
+ */
+ public static function getSubscribedEvents()
+ {
+ return array(
+ 'request.sent' => 'onRequestSent',
+ CurlMultiInterface::POLLING_REQUEST => 'onRequestPoll'
+ );
+ }
+
+ /**
* Set the maximum number of retries the plugin should use before failing
* the request
*
@@ -127,11 +127,11 @@ public function calculateWait($retries)
{
return (int) pow(2, $retries);
}
-
+
/**
* Called when a request has been sent
- *
- * @param Event $event
+ *
+ * @param Event $event
*/
public function onRequestSent(Event $event)
{
@@ -151,11 +151,11 @@ public function onRequestSent(Event $event)
}
}
}
-
+
/**
* Called when a request is polling in the curl mutli object
- *
- * @param Event $event
+ *
+ * @param Event $event
*/
public function onRequestPoll(Event $event)
{
View
4 Plugin/HistoryPlugin.php
@@ -21,9 +21,9 @@ class HistoryPlugin implements EventSubscriberInterface, \IteratorAggregate, \Co
* @var array Requests that have passd through the plugin
*/
protected $requests = array();
-
+
/**
- * {@inheritdoc}
+ * {@inheritdoc}
*/
public static function getSubscribedEvents()
{
View
50 Plugin/LogPlugin.php
@@ -53,19 +53,6 @@ class LogPlugin implements EventSubscriberInterface
* @var string Cached copy of the hostname
*/
private $hostname;
-
- /**
- * {@inheritdoc}
- */
- public static function getSubscribedEvents()
- {
- return array(
- 'curl.callback.write' => 'onCurlWrite',
- 'curl.callback.read' => 'onCurlRead',
- 'request.before_send' => 'onRequestBeforeSend',
- 'request.complete' => 'onRequestComplete'
- );
- }
/**
* Construct a new LogPlugin
@@ -81,6 +68,19 @@ public function __construct(LogAdapterInterface $logAdapter, $settings = self::L
}
/**
+ * {@inheritdoc}
+ */
+ public static function getSubscribedEvents()
+ {
+ return array(
+ 'curl.callback.write' => array('onCurlWrite', 255),
+ 'curl.callback.read' => array('onCurlRead', 255),
+ 'request.before_send' => array('onRequestBeforeSend', 255),
+ 'request.complete' => array('onRequestComplete', 255)
+ );
+ }
+
+ /**
* Change the log settings of the plugin
*
* @param int $settings (optional) Bitwise settings to control what's logged
@@ -103,11 +103,11 @@ public function getLogAdapter()
{
return $this->logAdapter;
}
-
+
/**
* Event triggered when curl data is read from a request
- *
- * @param Event $event
+ *
+ * @param Event $event
*/
public function onCurlRead(Event $event)
{
@@ -117,11 +117,11 @@ public function onCurlRead(Event $event)
$request->getParams()->get('request_wire')->write($event['read']);
}
}
-
+
/**
* Event triggered when curl data is written to a response
- *
- * @param Event $event
+ *
+ * @param Event $event
*/
public function onCurlWrite(Event $event)
{
@@ -131,11 +131,11 @@ public function onCurlWrite(Event $event)
$request->getParams()->get('response_wire')->write($event['write']);
}
}
-
+
/**
* Called before a request is sent
- *
- * @param Event $event
+ *
+ * @param Event $event
*/
public function onRequestBeforeSend(Event $event)
{
@@ -159,11 +159,11 @@ public function onRequestBeforeSend(Event $event)
}
}
}
-
+
/**
* Triggers the actual log write when a request completes
- *
- * @param Event $event
+ *
+ * @param Event $event
*/
public function onRequestComplete(Event $event)
{
View
47 Plugin/Md5ValidatorPlugin.php
@@ -23,14 +23,6 @@ class Md5ValidatorPlugin implements EventSubscriberInterface
* @var bool Whether or not to compare when a Content-Encoding is present
*/
protected $contentEncoded;
-
- /**
- * {@inheritdoc}
- */
- public static function getSubscribedEvents()
- {
- return array('request.complete' => 'onRequestComplete');
- }
/**
* Constructor
@@ -53,12 +45,20 @@ public function __construct($contentEncoded = true, $contentLengthCutoff = 20971
/**
* {@inheritdoc}
+ */
+ public static function getSubscribedEvents()
+ {
+ return array('request.complete' => array('onRequestComplete', 255));
+ }
+
+ /**
+ * {@inheritdoc}
* @throws UnexpectedValueException
*/
public function onRequestComplete(Event $event)
{
$response = $event['response'];
-
+
$contentMd5 = $response->getContentMd5();
if (!$contentMd5) {
return;
@@ -75,23 +75,18 @@ public function onRequestComplete(Event $event)
return;
}
- switch ($contentEncoding) {
- case 'gzip':
- $response->getBody()->compress('zlib.deflate');
- $hash = $response->getBody()->getContentMd5();
- $response->getBody()->uncompress();
- break;
- case 'compress':
- $response->getBody()->compress('bzip2.compress');
- $hash = $response->getBody()->getContentMd5();
- $response->getBody()->uncompress();
- break;
- default:
- if ($contentEncoding) {
- return;
- }
- $hash = $response->getBody()->getContentMd5();
- break;
+ if (!$contentEncoding) {
+ $hash = $response->getBody()->getContentMd5();
+ } else if ($contentEncoding == 'gzip') {
+ $response->getBody()->compress('zlib.deflate');
+ $hash = $response->getBody()->getContentMd5();
+ $response->getBody()->uncompress();
+ } else if ($contentEncoding == 'compress') {
+ $response->getBody()->compress('bzip2.compress');
+ $hash = $response->getBody()->getContentMd5();
+ $response->getBody()->uncompress();
+ } else {
+ return;
}
if ($contentMd5 !== $hash) {
View
44 Plugin/MockPlugin.php
@@ -22,17 +22,34 @@ class MockPlugin extends AbstractHasDispatcher implements EventSubscriberInterfa
* @var bool Whether or not to remove the plugin when the queue is empty
*/
protected $temporary = false;
-
+
/**
- * {@inheritdoc}
+ * Constructor
+ *
+ * @param array $responses (optional) Array of responses to queue
+ * @param bool $temporary (optional) Set to TRUE to remove the plugin when
+ * the queue is empty
+ */
+ public function __construct(array $responses = null, $temporary = false)
+ {
+ $this->temporary = $temporary;
+ if ($responses) {
+ foreach ($responses as $response) {
+ $this->addResponse($response);
+ }
+ }
+ }
+
+ /**
+ * {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array('client.create_request' => 'onRequestCreate');
}
-
+
/**
- * {@inheritdoc}
+ * {@inheritdoc}
*/
public static function getAllEvents()
{
@@ -63,23 +80,6 @@ public static function getMockFile($path)
}
/**
- * Constructor
- *
- * @param array $responses (optional) Array of responses to queue
- * @param bool $temporary (optional) Set to TRUE to remove the plugin when
- * the queue is empty
- */
- public function __construct(array $responses = null, $temporary = false)
- {
- $this->temporary = $temporary;
- if ($responses) {
- foreach ($responses as $response) {
- $this->addResponse($response);
- }
- }
- }
-
- /**
* Returns the number of remaining mock responses
*
* @return int
@@ -163,7 +163,7 @@ public function dequeue(RequestInterface $request)
/**
* Called when a request completes
- *
+ *
* @param Event $event
*/
public function onRequestCreate(Event $event)
Please sign in to comment.
Something went wrong with that request. Please try again.