@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | public function __construct(Google_Client $client) |
29 | 29 | { |
30 | - $this->client = $client; |
|
30 | + $this->client = $client; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function getClient() |
38 | 38 | { |
39 | - return $this->client; |
|
39 | + return $this->client; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function createBatch() |
48 | 48 | { |
49 | - return new Google_Http_Batch( |
|
50 | - $this->client, |
|
51 | - false, |
|
52 | - $this->rootUrl, |
|
53 | - $this->batchPath |
|
54 | - ); |
|
49 | + return new Google_Http_Batch( |
|
50 | + $this->client, |
|
51 | + false, |
|
52 | + $this->rootUrl, |
|
53 | + $this->batchPath |
|
54 | + ); |
|
55 | 55 | } |
56 | 56 | } |
@@ -15,87 +15,87 @@ |
||
15 | 15 | |
16 | 16 | public function rewind() |
17 | 17 | { |
18 | - if (isset($this->modelData[$this->collection_key]) |
|
19 | - && is_array($this->modelData[$this->collection_key])) { |
|
20 | - reset($this->modelData[$this->collection_key]); |
|
21 | - } |
|
18 | + if (isset($this->modelData[$this->collection_key]) |
|
19 | + && is_array($this->modelData[$this->collection_key])) { |
|
20 | + reset($this->modelData[$this->collection_key]); |
|
21 | + } |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function current() |
25 | 25 | { |
26 | - $this->coerceType($this->key()); |
|
27 | - if (is_array($this->modelData[$this->collection_key])) { |
|
28 | - return current($this->modelData[$this->collection_key]); |
|
29 | - } |
|
26 | + $this->coerceType($this->key()); |
|
27 | + if (is_array($this->modelData[$this->collection_key])) { |
|
28 | + return current($this->modelData[$this->collection_key]); |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function key() |
33 | 33 | { |
34 | - if (isset($this->modelData[$this->collection_key]) |
|
35 | - && is_array($this->modelData[$this->collection_key])) { |
|
36 | - return key($this->modelData[$this->collection_key]); |
|
37 | - } |
|
34 | + if (isset($this->modelData[$this->collection_key]) |
|
35 | + && is_array($this->modelData[$this->collection_key])) { |
|
36 | + return key($this->modelData[$this->collection_key]); |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public function next() |
41 | 41 | { |
42 | - return next($this->modelData[$this->collection_key]); |
|
42 | + return next($this->modelData[$this->collection_key]); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | public function valid() |
46 | 46 | { |
47 | - $key = $this->key(); |
|
48 | - return $key !== null && $key !== false; |
|
47 | + $key = $this->key(); |
|
48 | + return $key !== null && $key !== false; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | public function count() |
52 | 52 | { |
53 | - if (!isset($this->modelData[$this->collection_key])) { |
|
54 | - return 0; |
|
55 | - } |
|
56 | - return count($this->modelData[$this->collection_key]); |
|
53 | + if (!isset($this->modelData[$this->collection_key])) { |
|
54 | + return 0; |
|
55 | + } |
|
56 | + return count($this->modelData[$this->collection_key]); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function offsetExists($offset) |
60 | 60 | { |
61 | - if (!is_numeric($offset)) { |
|
62 | - return parent::offsetExists($offset); |
|
63 | - } |
|
64 | - return isset($this->modelData[$this->collection_key][$offset]); |
|
61 | + if (!is_numeric($offset)) { |
|
62 | + return parent::offsetExists($offset); |
|
63 | + } |
|
64 | + return isset($this->modelData[$this->collection_key][$offset]); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | public function offsetGet($offset) |
68 | 68 | { |
69 | - if (!is_numeric($offset)) { |
|
70 | - return parent::offsetGet($offset); |
|
71 | - } |
|
72 | - $this->coerceType($offset); |
|
73 | - return $this->modelData[$this->collection_key][$offset]; |
|
69 | + if (!is_numeric($offset)) { |
|
70 | + return parent::offsetGet($offset); |
|
71 | + } |
|
72 | + $this->coerceType($offset); |
|
73 | + return $this->modelData[$this->collection_key][$offset]; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | public function offsetSet($offset, $value) |
77 | 77 | { |
78 | - if (!is_numeric($offset)) { |
|
79 | - return parent::offsetSet($offset, $value); |
|
80 | - } |
|
81 | - $this->modelData[$this->collection_key][$offset] = $value; |
|
78 | + if (!is_numeric($offset)) { |
|
79 | + return parent::offsetSet($offset, $value); |
|
80 | + } |
|
81 | + $this->modelData[$this->collection_key][$offset] = $value; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | public function offsetUnset($offset) |
85 | 85 | { |
86 | - if (!is_numeric($offset)) { |
|
87 | - return parent::offsetUnset($offset); |
|
88 | - } |
|
89 | - unset($this->modelData[$this->collection_key][$offset]); |
|
86 | + if (!is_numeric($offset)) { |
|
87 | + return parent::offsetUnset($offset); |
|
88 | + } |
|
89 | + unset($this->modelData[$this->collection_key][$offset]); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | private function coerceType($offset) |
93 | 93 | { |
94 | - $typeKey = $this->keyType($this->collection_key); |
|
95 | - if (isset($this->$typeKey) && !is_object($this->modelData[$this->collection_key][$offset])) { |
|
96 | - $type = $this->$typeKey; |
|
97 | - $this->modelData[$this->collection_key][$offset] = |
|
98 | - new $type($this->modelData[$this->collection_key][$offset]); |
|
99 | - } |
|
94 | + $typeKey = $this->keyType($this->collection_key); |
|
95 | + if (isset($this->$typeKey) && !is_object($this->modelData[$this->collection_key][$offset])) { |
|
96 | + $type = $this->$typeKey; |
|
97 | + $this->modelData[$this->collection_key][$offset] = |
|
98 | + new $type($this->modelData[$this->collection_key][$offset]); |
|
99 | + } |
|
100 | 100 | } |
101 | 101 | } |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (!class_exists('Google_Client')) { |
4 | - require_once dirname(__FILE__) . '/autoload.php'; |
|
4 | + require_once dirname(__FILE__).'/autoload.php'; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -38,20 +38,20 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function __construct($pem) |
40 | 40 | { |
41 | - if (!function_exists('openssl_x509_read')) { |
|
42 | - throw new Google_Exception('Google API PHP client needs the openssl PHP extension'); |
|
43 | - } |
|
44 | - $this->publicKey = openssl_x509_read($pem); |
|
45 | - if (!$this->publicKey) { |
|
46 | - throw new Google_Auth_Exception("Unable to parse PEM: $pem"); |
|
47 | - } |
|
41 | + if (!function_exists('openssl_x509_read')) { |
|
42 | + throw new Google_Exception('Google API PHP client needs the openssl PHP extension'); |
|
43 | + } |
|
44 | + $this->publicKey = openssl_x509_read($pem); |
|
45 | + if (!$this->publicKey) { |
|
46 | + throw new Google_Auth_Exception("Unable to parse PEM: $pem"); |
|
47 | + } |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | public function __destruct() |
51 | 51 | { |
52 | - if ($this->publicKey) { |
|
53 | - openssl_x509_free($this->publicKey); |
|
54 | - } |
|
52 | + if ($this->publicKey) { |
|
53 | + openssl_x509_free($this->publicKey); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function verify($data, $signature) |
67 | 67 | { |
68 | - $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256"; |
|
69 | - $status = openssl_verify($data, $signature, $this->publicKey, $hash); |
|
70 | - if ($status === -1) { |
|
71 | - throw new Google_Auth_Exception('Signature verification error: ' . openssl_error_string()); |
|
72 | - } |
|
73 | - return $status === 1; |
|
68 | + $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256"; |
|
69 | + $status = openssl_verify($data, $signature, $this->publicKey, $hash); |
|
70 | + if ($status === -1) { |
|
71 | + throw new Google_Auth_Exception('Signature verification error: ' . openssl_error_string()); |
|
72 | + } |
|
73 | + return $status === 1; |
|
74 | 74 | } |
75 | 75 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256"; |
69 | 69 | $status = openssl_verify($data, $signature, $this->publicKey, $hash); |
70 | 70 | if ($status === -1) { |
71 | - throw new Google_Auth_Exception('Signature verification error: ' . openssl_error_string()); |
|
71 | + throw new Google_Auth_Exception('Signature verification error: '.openssl_error_string()); |
|
72 | 72 | } |
73 | 73 | return $status === 1; |
74 | 74 | } |
@@ -36,44 +36,44 @@ discard block |
||
36 | 36 | |
37 | 37 | public function __construct(Google_Client $client) |
38 | 38 | { |
39 | - if (! function_exists('apc_add') ) { |
|
40 | - $error = "Apc functions not available"; |
|
39 | + if (! function_exists('apc_add') ) { |
|
40 | + $error = "Apc functions not available"; |
|
41 | 41 | |
42 | - $client->getLogger()->error($error); |
|
43 | - throw new Google_Cache_Exception($error); |
|
44 | - } |
|
42 | + $client->getLogger()->error($error); |
|
43 | + throw new Google_Cache_Exception($error); |
|
44 | + } |
|
45 | 45 | |
46 | - $this->client = $client; |
|
46 | + $this->client = $client; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | - * @inheritDoc |
|
51 | - */ |
|
50 | + * @inheritDoc |
|
51 | + */ |
|
52 | 52 | public function get($key, $expiration = false) |
53 | 53 | { |
54 | - $ret = apc_fetch($key); |
|
55 | - if ($ret === false) { |
|
56 | - $this->client->getLogger()->debug( |
|
57 | - 'APC cache miss', |
|
58 | - array('key' => $key) |
|
59 | - ); |
|
60 | - return false; |
|
61 | - } |
|
62 | - if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) { |
|
63 | - $this->client->getLogger()->debug( |
|
64 | - 'APC cache miss (expired)', |
|
65 | - array('key' => $key, 'var' => $ret) |
|
66 | - ); |
|
67 | - $this->delete($key); |
|
68 | - return false; |
|
69 | - } |
|
54 | + $ret = apc_fetch($key); |
|
55 | + if ($ret === false) { |
|
56 | + $this->client->getLogger()->debug( |
|
57 | + 'APC cache miss', |
|
58 | + array('key' => $key) |
|
59 | + ); |
|
60 | + return false; |
|
61 | + } |
|
62 | + if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) { |
|
63 | + $this->client->getLogger()->debug( |
|
64 | + 'APC cache miss (expired)', |
|
65 | + array('key' => $key, 'var' => $ret) |
|
66 | + ); |
|
67 | + $this->delete($key); |
|
68 | + return false; |
|
69 | + } |
|
70 | 70 | |
71 | - $this->client->getLogger()->debug( |
|
72 | - 'APC cache hit', |
|
73 | - array('key' => $key, 'var' => $ret) |
|
74 | - ); |
|
71 | + $this->client->getLogger()->debug( |
|
72 | + 'APC cache hit', |
|
73 | + array('key' => $key, 'var' => $ret) |
|
74 | + ); |
|
75 | 75 | |
76 | - return $ret['data']; |
|
76 | + return $ret['data']; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -81,21 +81,21 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function set($key, $value) |
83 | 83 | { |
84 | - $var = array('time' => time(), 'data' => $value); |
|
85 | - $rc = apc_store($key, $var); |
|
84 | + $var = array('time' => time(), 'data' => $value); |
|
85 | + $rc = apc_store($key, $var); |
|
86 | 86 | |
87 | - if ($rc == false) { |
|
88 | - $this->client->getLogger()->error( |
|
89 | - 'APC cache set failed', |
|
90 | - array('key' => $key, 'var' => $var) |
|
91 | - ); |
|
92 | - throw new Google_Cache_Exception("Couldn't store data"); |
|
93 | - } |
|
87 | + if ($rc == false) { |
|
88 | + $this->client->getLogger()->error( |
|
89 | + 'APC cache set failed', |
|
90 | + array('key' => $key, 'var' => $var) |
|
91 | + ); |
|
92 | + throw new Google_Cache_Exception("Couldn't store data"); |
|
93 | + } |
|
94 | 94 | |
95 | - $this->client->getLogger()->debug( |
|
96 | - 'APC cache set', |
|
97 | - array('key' => $key, 'var' => $var) |
|
98 | - ); |
|
95 | + $this->client->getLogger()->debug( |
|
96 | + 'APC cache set', |
|
97 | + array('key' => $key, 'var' => $var) |
|
98 | + ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function delete($key) |
106 | 106 | { |
107 | - $this->client->getLogger()->debug( |
|
108 | - 'APC cache delete', |
|
109 | - array('key' => $key) |
|
110 | - ); |
|
111 | - apc_delete($key); |
|
107 | + $this->client->getLogger()->debug( |
|
108 | + 'APC cache delete', |
|
109 | + array('key' => $key) |
|
110 | + ); |
|
111 | + apc_delete($key); |
|
112 | 112 | } |
113 | 113 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | public function __construct(Google_Client $client) |
38 | 38 | { |
39 | - if (! function_exists('apc_add') ) { |
|
39 | + if (!function_exists('apc_add')) { |
|
40 | 40 | $error = "Apc functions not available"; |
41 | 41 | |
42 | 42 | $client->getLogger()->error($error); |
@@ -43,29 +43,29 @@ discard block |
||
43 | 43 | |
44 | 44 | public function __construct(Google_Client $client) |
45 | 45 | { |
46 | - if (!function_exists('memcache_connect') && !class_exists("Memcached")) { |
|
47 | - $error = "Memcache functions not available"; |
|
48 | - |
|
49 | - $client->getLogger()->error($error); |
|
50 | - throw new Google_Cache_Exception($error); |
|
51 | - } |
|
52 | - |
|
53 | - $this->client = $client; |
|
54 | - |
|
55 | - if ($client->isAppEngine()) { |
|
56 | - // No credentials needed for GAE. |
|
57 | - $this->mc = new Memcached(); |
|
58 | - $this->connection = true; |
|
59 | - } else { |
|
60 | - $this->host = $client->getClassConfig($this, 'host'); |
|
61 | - $this->port = $client->getClassConfig($this, 'port'); |
|
62 | - if (empty($this->host) || (empty($this->port) && (string) $this->port != "0")) { |
|
63 | - $error = "You need to supply a valid memcache host and port"; |
|
64 | - |
|
65 | - $client->getLogger()->error($error); |
|
66 | - throw new Google_Cache_Exception($error); |
|
67 | - } |
|
68 | - } |
|
46 | + if (!function_exists('memcache_connect') && !class_exists("Memcached")) { |
|
47 | + $error = "Memcache functions not available"; |
|
48 | + |
|
49 | + $client->getLogger()->error($error); |
|
50 | + throw new Google_Cache_Exception($error); |
|
51 | + } |
|
52 | + |
|
53 | + $this->client = $client; |
|
54 | + |
|
55 | + if ($client->isAppEngine()) { |
|
56 | + // No credentials needed for GAE. |
|
57 | + $this->mc = new Memcached(); |
|
58 | + $this->connection = true; |
|
59 | + } else { |
|
60 | + $this->host = $client->getClassConfig($this, 'host'); |
|
61 | + $this->port = $client->getClassConfig($this, 'port'); |
|
62 | + if (empty($this->host) || (empty($this->port) && (string) $this->port != "0")) { |
|
63 | + $error = "You need to supply a valid memcache host and port"; |
|
64 | + |
|
65 | + $client->getLogger()->error($error); |
|
66 | + throw new Google_Cache_Exception($error); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -73,35 +73,35 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function get($key, $expiration = false) |
75 | 75 | { |
76 | - $this->connect(); |
|
77 | - $ret = false; |
|
78 | - if ($this->mc) { |
|
79 | - $ret = $this->mc->get($key); |
|
80 | - } else { |
|
81 | - $ret = memcache_get($this->connection, $key); |
|
82 | - } |
|
83 | - if ($ret === false) { |
|
84 | - $this->client->getLogger()->debug( |
|
85 | - 'Memcache cache miss', |
|
86 | - array('key' => $key) |
|
87 | - ); |
|
88 | - return false; |
|
89 | - } |
|
90 | - if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) { |
|
91 | - $this->client->getLogger()->debug( |
|
92 | - 'Memcache cache miss (expired)', |
|
93 | - array('key' => $key, 'var' => $ret) |
|
94 | - ); |
|
95 | - $this->delete($key); |
|
96 | - return false; |
|
97 | - } |
|
98 | - |
|
99 | - $this->client->getLogger()->debug( |
|
100 | - 'Memcache cache hit', |
|
101 | - array('key' => $key, 'var' => $ret) |
|
102 | - ); |
|
103 | - |
|
104 | - return $ret['data']; |
|
76 | + $this->connect(); |
|
77 | + $ret = false; |
|
78 | + if ($this->mc) { |
|
79 | + $ret = $this->mc->get($key); |
|
80 | + } else { |
|
81 | + $ret = memcache_get($this->connection, $key); |
|
82 | + } |
|
83 | + if ($ret === false) { |
|
84 | + $this->client->getLogger()->debug( |
|
85 | + 'Memcache cache miss', |
|
86 | + array('key' => $key) |
|
87 | + ); |
|
88 | + return false; |
|
89 | + } |
|
90 | + if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) { |
|
91 | + $this->client->getLogger()->debug( |
|
92 | + 'Memcache cache miss (expired)', |
|
93 | + array('key' => $key, 'var' => $ret) |
|
94 | + ); |
|
95 | + $this->delete($key); |
|
96 | + return false; |
|
97 | + } |
|
98 | + |
|
99 | + $this->client->getLogger()->debug( |
|
100 | + 'Memcache cache hit', |
|
101 | + array('key' => $key, 'var' => $ret) |
|
102 | + ); |
|
103 | + |
|
104 | + return $ret['data']; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -112,29 +112,29 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function set($key, $value) |
114 | 114 | { |
115 | - $this->connect(); |
|
116 | - // we store it with the cache_time default expiration so objects will at |
|
117 | - // least get cleaned eventually. |
|
118 | - $data = array('time' => time(), 'data' => $value); |
|
119 | - $rc = false; |
|
120 | - if ($this->mc) { |
|
121 | - $rc = $this->mc->set($key, $data); |
|
122 | - } else { |
|
123 | - $rc = memcache_set($this->connection, $key, $data, false); |
|
124 | - } |
|
125 | - if ($rc == false) { |
|
126 | - $this->client->getLogger()->error( |
|
127 | - 'Memcache cache set failed', |
|
128 | - array('key' => $key, 'var' => $data) |
|
129 | - ); |
|
130 | - |
|
131 | - throw new Google_Cache_Exception("Couldn't store data in cache"); |
|
132 | - } |
|
133 | - |
|
134 | - $this->client->getLogger()->debug( |
|
135 | - 'Memcache cache set', |
|
136 | - array('key' => $key, 'var' => $data) |
|
137 | - ); |
|
115 | + $this->connect(); |
|
116 | + // we store it with the cache_time default expiration so objects will at |
|
117 | + // least get cleaned eventually. |
|
118 | + $data = array('time' => time(), 'data' => $value); |
|
119 | + $rc = false; |
|
120 | + if ($this->mc) { |
|
121 | + $rc = $this->mc->set($key, $data); |
|
122 | + } else { |
|
123 | + $rc = memcache_set($this->connection, $key, $data, false); |
|
124 | + } |
|
125 | + if ($rc == false) { |
|
126 | + $this->client->getLogger()->error( |
|
127 | + 'Memcache cache set failed', |
|
128 | + array('key' => $key, 'var' => $data) |
|
129 | + ); |
|
130 | + |
|
131 | + throw new Google_Cache_Exception("Couldn't store data in cache"); |
|
132 | + } |
|
133 | + |
|
134 | + $this->client->getLogger()->debug( |
|
135 | + 'Memcache cache set', |
|
136 | + array('key' => $key, 'var' => $data) |
|
137 | + ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -143,17 +143,17 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function delete($key) |
145 | 145 | { |
146 | - $this->connect(); |
|
147 | - if ($this->mc) { |
|
148 | - $this->mc->delete($key, 0); |
|
149 | - } else { |
|
150 | - memcache_delete($this->connection, $key, 0); |
|
151 | - } |
|
152 | - |
|
153 | - $this->client->getLogger()->debug( |
|
154 | - 'Memcache cache delete', |
|
155 | - array('key' => $key) |
|
156 | - ); |
|
146 | + $this->connect(); |
|
147 | + if ($this->mc) { |
|
148 | + $this->mc->delete($key, 0); |
|
149 | + } else { |
|
150 | + memcache_delete($this->connection, $key, 0); |
|
151 | + } |
|
152 | + |
|
153 | + $this->client->getLogger()->debug( |
|
154 | + 'Memcache cache delete', |
|
155 | + array('key' => $key) |
|
156 | + ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -162,23 +162,23 @@ discard block |
||
162 | 162 | */ |
163 | 163 | private function connect() |
164 | 164 | { |
165 | - if ($this->connection) { |
|
166 | - return; |
|
167 | - } |
|
168 | - |
|
169 | - if (class_exists("Memcached")) { |
|
170 | - $this->mc = new Memcached(); |
|
171 | - $this->mc->addServer($this->host, $this->port); |
|
172 | - $this->connection = true; |
|
173 | - } else { |
|
174 | - $this->connection = memcache_pconnect($this->host, $this->port); |
|
175 | - } |
|
176 | - |
|
177 | - if (! $this->connection) { |
|
178 | - $error = "Couldn't connect to memcache server"; |
|
179 | - |
|
180 | - $this->client->getLogger()->error($error); |
|
181 | - throw new Google_Cache_Exception($error); |
|
182 | - } |
|
165 | + if ($this->connection) { |
|
166 | + return; |
|
167 | + } |
|
168 | + |
|
169 | + if (class_exists("Memcached")) { |
|
170 | + $this->mc = new Memcached(); |
|
171 | + $this->mc->addServer($this->host, $this->port); |
|
172 | + $this->connection = true; |
|
173 | + } else { |
|
174 | + $this->connection = memcache_pconnect($this->host, $this->port); |
|
175 | + } |
|
176 | + |
|
177 | + if (! $this->connection) { |
|
178 | + $error = "Couldn't connect to memcache server"; |
|
179 | + |
|
180 | + $this->client->getLogger()->error($error); |
|
181 | + throw new Google_Cache_Exception($error); |
|
182 | + } |
|
183 | 183 | } |
184 | 184 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $this->connection = memcache_pconnect($this->host, $this->port); |
175 | 175 | } |
176 | 176 | |
177 | - if (! $this->connection) { |
|
177 | + if (!$this->connection) { |
|
178 | 178 | $error = "Couldn't connect to memcache server"; |
179 | 179 | |
180 | 180 | $this->client->getLogger()->error($error); |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | - * @inheritDoc |
|
35 | - */ |
|
34 | + * @inheritDoc |
|
35 | + */ |
|
36 | 36 | public function get($key, $expiration = false) |
37 | 37 | { |
38 | - return false; |
|
38 | + return false; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function set($key, $value) |
45 | 45 | { |
46 | - // Nop. |
|
46 | + // Nop. |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -52,6 +52,6 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function delete($key) |
54 | 54 | { |
55 | - // Nop. |
|
55 | + // Nop. |
|
56 | 56 | } |
57 | 57 | } |
@@ -16,7 +16,7 @@ |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -16,7 +16,7 @@ |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class Google_Cache_Exception extends Google_Exception |
@@ -83,72 +83,72 @@ discard block |
||
83 | 83 | * @throws Google_Task_Exception when misconfigured |
84 | 84 | */ |
85 | 85 | public function __construct( |
86 | - Google_Client $client, |
|
87 | - $name, |
|
88 | - $action, |
|
89 | - array $arguments = array() |
|
86 | + Google_Client $client, |
|
87 | + $name, |
|
88 | + $action, |
|
89 | + array $arguments = array() |
|
90 | 90 | ) { |
91 | - $config = (array) $client->getClassConfig('Google_Task_Runner'); |
|
91 | + $config = (array) $client->getClassConfig('Google_Task_Runner'); |
|
92 | 92 | |
93 | - if (isset($config['initial_delay'])) { |
|
94 | - if ($config['initial_delay'] < 0) { |
|
95 | - throw new Google_Task_Exception( |
|
96 | - 'Task configuration `initial_delay` must not be negative.' |
|
97 | - ); |
|
98 | - } |
|
93 | + if (isset($config['initial_delay'])) { |
|
94 | + if ($config['initial_delay'] < 0) { |
|
95 | + throw new Google_Task_Exception( |
|
96 | + 'Task configuration `initial_delay` must not be negative.' |
|
97 | + ); |
|
98 | + } |
|
99 | 99 | |
100 | - $this->delay = $config['initial_delay']; |
|
101 | - } |
|
100 | + $this->delay = $config['initial_delay']; |
|
101 | + } |
|
102 | 102 | |
103 | - if (isset($config['max_delay'])) { |
|
104 | - if ($config['max_delay'] <= 0) { |
|
105 | - throw new Google_Task_Exception( |
|
106 | - 'Task configuration `max_delay` must be greater than 0.' |
|
107 | - ); |
|
108 | - } |
|
103 | + if (isset($config['max_delay'])) { |
|
104 | + if ($config['max_delay'] <= 0) { |
|
105 | + throw new Google_Task_Exception( |
|
106 | + 'Task configuration `max_delay` must be greater than 0.' |
|
107 | + ); |
|
108 | + } |
|
109 | 109 | |
110 | - $this->maxDelay = $config['max_delay']; |
|
111 | - } |
|
110 | + $this->maxDelay = $config['max_delay']; |
|
111 | + } |
|
112 | 112 | |
113 | - if (isset($config['factor'])) { |
|
114 | - if ($config['factor'] <= 0) { |
|
115 | - throw new Google_Task_Exception( |
|
116 | - 'Task configuration `factor` must be greater than 0.' |
|
117 | - ); |
|
118 | - } |
|
113 | + if (isset($config['factor'])) { |
|
114 | + if ($config['factor'] <= 0) { |
|
115 | + throw new Google_Task_Exception( |
|
116 | + 'Task configuration `factor` must be greater than 0.' |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | |
120 | - $this->factor = $config['factor']; |
|
121 | - } |
|
120 | + $this->factor = $config['factor']; |
|
121 | + } |
|
122 | 122 | |
123 | - if (isset($config['jitter'])) { |
|
124 | - if ($config['jitter'] <= 0) { |
|
125 | - throw new Google_Task_Exception( |
|
126 | - 'Task configuration `jitter` must be greater than 0.' |
|
127 | - ); |
|
128 | - } |
|
123 | + if (isset($config['jitter'])) { |
|
124 | + if ($config['jitter'] <= 0) { |
|
125 | + throw new Google_Task_Exception( |
|
126 | + 'Task configuration `jitter` must be greater than 0.' |
|
127 | + ); |
|
128 | + } |
|
129 | 129 | |
130 | - $this->jitter = $config['jitter']; |
|
131 | - } |
|
130 | + $this->jitter = $config['jitter']; |
|
131 | + } |
|
132 | 132 | |
133 | - if (isset($config['retries'])) { |
|
134 | - if ($config['retries'] < 0) { |
|
135 | - throw new Google_Task_Exception( |
|
136 | - 'Task configuration `retries` must not be negative.' |
|
137 | - ); |
|
138 | - } |
|
139 | - $this->maxAttempts += $config['retries']; |
|
140 | - } |
|
133 | + if (isset($config['retries'])) { |
|
134 | + if ($config['retries'] < 0) { |
|
135 | + throw new Google_Task_Exception( |
|
136 | + 'Task configuration `retries` must not be negative.' |
|
137 | + ); |
|
138 | + } |
|
139 | + $this->maxAttempts += $config['retries']; |
|
140 | + } |
|
141 | 141 | |
142 | - if (!is_callable($action)) { |
|
143 | - throw new Google_Task_Exception( |
|
144 | - 'Task argument `$action` must be a valid callable.' |
|
145 | - ); |
|
146 | - } |
|
142 | + if (!is_callable($action)) { |
|
143 | + throw new Google_Task_Exception( |
|
144 | + 'Task argument `$action` must be a valid callable.' |
|
145 | + ); |
|
146 | + } |
|
147 | 147 | |
148 | - $this->name = $name; |
|
149 | - $this->client = $client; |
|
150 | - $this->action = $action; |
|
151 | - $this->arguments = $arguments; |
|
148 | + $this->name = $name; |
|
149 | + $this->client = $client; |
|
150 | + $this->action = $action; |
|
151 | + $this->arguments = $arguments; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function canAttmpt() |
160 | 160 | { |
161 | - return $this->attempts < $this->maxAttempts; |
|
161 | + return $this->attempts < $this->maxAttempts; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -169,24 +169,24 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function run() |
171 | 171 | { |
172 | - while ($this->attempt()) { |
|
173 | - try { |
|
174 | - return call_user_func_array($this->action, $this->arguments); |
|
175 | - } catch (Google_Task_Retryable $exception) { |
|
176 | - $allowedRetries = $exception->allowedRetries(); |
|
172 | + while ($this->attempt()) { |
|
173 | + try { |
|
174 | + return call_user_func_array($this->action, $this->arguments); |
|
175 | + } catch (Google_Task_Retryable $exception) { |
|
176 | + $allowedRetries = $exception->allowedRetries(); |
|
177 | 177 | |
178 | - if (!$this->canAttmpt() || !$allowedRetries) { |
|
179 | - throw $exception; |
|
180 | - } |
|
178 | + if (!$this->canAttmpt() || !$allowedRetries) { |
|
179 | + throw $exception; |
|
180 | + } |
|
181 | 181 | |
182 | - if ($allowedRetries > 0) { |
|
183 | - $this->maxAttempts = min( |
|
184 | - $this->maxAttempts, |
|
185 | - $this->attempts + $allowedRetries |
|
186 | - ); |
|
187 | - } |
|
188 | - } |
|
189 | - } |
|
182 | + if ($allowedRetries > 0) { |
|
183 | + $this->maxAttempts = min( |
|
184 | + $this->maxAttempts, |
|
185 | + $this->attempts + $allowedRetries |
|
186 | + ); |
|
187 | + } |
|
188 | + } |
|
189 | + } |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -200,16 +200,16 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function attempt() |
202 | 202 | { |
203 | - if (!$this->canAttmpt()) { |
|
204 | - return false; |
|
205 | - } |
|
203 | + if (!$this->canAttmpt()) { |
|
204 | + return false; |
|
205 | + } |
|
206 | 206 | |
207 | - if ($this->attempts > 0) { |
|
208 | - $this->backOff(); |
|
209 | - } |
|
207 | + if ($this->attempts > 0) { |
|
208 | + $this->backOff(); |
|
209 | + } |
|
210 | 210 | |
211 | - $this->attempts++; |
|
212 | - return true; |
|
211 | + $this->attempts++; |
|
212 | + return true; |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -217,18 +217,18 @@ discard block |
||
217 | 217 | */ |
218 | 218 | private function backOff() |
219 | 219 | { |
220 | - $delay = $this->getDelay(); |
|
220 | + $delay = $this->getDelay(); |
|
221 | 221 | |
222 | - $this->client->getLogger()->debug( |
|
223 | - 'Retrying task with backoff', |
|
224 | - array( |
|
225 | - 'request' => $this->name, |
|
226 | - 'retry' => $this->attempts, |
|
227 | - 'backoff_seconds' => $delay |
|
228 | - ) |
|
229 | - ); |
|
222 | + $this->client->getLogger()->debug( |
|
223 | + 'Retrying task with backoff', |
|
224 | + array( |
|
225 | + 'request' => $this->name, |
|
226 | + 'retry' => $this->attempts, |
|
227 | + 'backoff_seconds' => $delay |
|
228 | + ) |
|
229 | + ); |
|
230 | 230 | |
231 | - usleep($delay * 1000000); |
|
231 | + usleep($delay * 1000000); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | */ |
239 | 239 | private function getDelay() |
240 | 240 | { |
241 | - $jitter = $this->getJitter(); |
|
242 | - $factor = $this->attempts > 1 ? $this->factor + $jitter : 1 + abs($jitter); |
|
241 | + $jitter = $this->getJitter(); |
|
242 | + $factor = $this->attempts > 1 ? $this->factor + $jitter : 1 + abs($jitter); |
|
243 | 243 | |
244 | - return $this->delay = min($this->maxDelay, $this->delay * $factor); |
|
244 | + return $this->delay = min($this->maxDelay, $this->delay * $factor); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -252,6 +252,6 @@ discard block |
||
252 | 252 | */ |
253 | 253 | private function getJitter() |
254 | 254 | { |
255 | - return $this->jitter * 2 * mt_rand() / mt_getrandmax() - $this->jitter; |
|
255 | + return $this->jitter * 2 * mt_rand() / mt_getrandmax() - $this->jitter; |
|
256 | 256 | } |
257 | 257 | } |
@@ -16,7 +16,7 @@ |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -16,7 +16,7 @@ |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | if (!class_exists('Google_Client')) { |
19 | - require_once dirname(__FILE__) . '/../autoload.php'; |
|
19 | + require_once dirname(__FILE__).'/../autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class Google_Task_Exception extends Google_Exception |