Permalink
Browse files

Coding standards

  • Loading branch information...
mtdowling committed Jan 24, 2012
1 parent 98177fd commit 0a435c069122a013b48a6f26454999fcc333cbee
View
@@ -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;
}
@@ -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
@@ -13,14 +13,6 @@ class BasicAuthPlugin implements EventSubscriberInterface
private $username;
private $password;
- /**
- * {@inheritdoc}
- */
- public static function getSubscribedEvents()
- {
- return array('client.create_request' => 'onRequestCreate');
- }
-
/**
* Constructor
*
@@ -33,14 +25,21 @@ public function __construct($username, $password)
$this->password = $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);
}
}
@@ -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
@@ -50,17 +50,6 @@ class CachePlugin implements EventSubscriberInterface
'Set-Cookie2'
);
- /**
- * {@inheritdoc}
- */
- public static function getSubscribedEvents()
- {
- return array(
- 'request.before_send' => 'onRequestBeforeSend',
- 'request.sent' => 'onRequestSent'
- );
- }
-
/**
* Construct a new CachePlugin
*
@@ -77,6 +66,17 @@ public function __construct(CacheAdapterInterface $adapter, $serialize = false,
$this->defaultLifetime = (int) $defaultLifetime;
}
+ /**
+ * {@inheritdoc}
+ */
+ public static function getSubscribedEvents()
+ {
+ return array(
+ 'request.before_send' => array('onRequestBeforeSend', -255),
+ 'request.sent' => array('onRequestSent', 255)
+ );
+ }
+
/**
* Get the cache adapter object
*
View
@@ -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
@@ -48,6 +36,18 @@ public function __destruct()
$this->clearTemporaryCookies();
}
+ /**
+ * {@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)
{
@@ -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
@@ -65,6 +54,17 @@ public function __construct($maxRetries = 3, array $failureCodes = null, $delayC
$this->state = new Collection();
}
+ /**
+ * {@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
@@ -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()
{
Oops, something went wrong.

0 comments on commit 0a435c0

Please sign in to comment.