Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 5f2fc06

Browse files
committed
Merge branch 'hotfix/zendframework/zendframework#6462-fix-phpcs-reported-errors' into develop
Forward port zendframework/zendframework#6462
9 parents 13a1827 + e24be06 + 1cd130f + 2f4d84a + c5055d9 + b5302e2 + 9969a8b + 02e14e6 + b32313c commit 5f2fc06

2 files changed

Lines changed: 228 additions & 228 deletions

File tree

src/Storage/Adapter/MemcachedResourceManager.php

Lines changed: 88 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,94 @@ class MemcachedResourceManager
2828
*/
2929
protected $resources = array();
3030

31+
/**
32+
* Get servers
33+
* @param string $id
34+
* @throws Exception\RuntimeException
35+
* @return array array('host' => <host>, 'port' => <port>, 'weight' => <weight>)
36+
*/
37+
public function getServers($id)
38+
{
39+
if (!$this->hasResource($id)) {
40+
throw new Exception\RuntimeException("No resource with id '{$id}'");
41+
}
42+
43+
$resource = & $this->resources[$id];
44+
45+
if ($resource instanceof MemcachedResource) {
46+
return $resource->getServerList();
47+
}
48+
return $resource['servers'];
49+
}
50+
51+
/**
52+
* Normalize one server into the following format:
53+
* array('host' => <host>, 'port' => <port>, 'weight' => <weight>)
54+
*
55+
* @param string|array &$server
56+
* @throws Exception\InvalidArgumentException
57+
*/
58+
protected function normalizeServer(&$server)
59+
{
60+
$host = null;
61+
$port = 11211;
62+
$weight = 0;
63+
64+
// convert a single server into an array
65+
if ($server instanceof Traversable) {
66+
$server = ArrayUtils::iteratorToArray($server);
67+
}
68+
69+
if (is_array($server)) {
70+
// array(<host>[, <port>[, <weight>]])
71+
if (isset($server[0])) {
72+
$host = (string) $server[0];
73+
$port = isset($server[1]) ? (int) $server[1] : $port;
74+
$weight = isset($server[2]) ? (int) $server[2] : $weight;
75+
}
76+
77+
// array('host' => <host>[, 'port' => <port>[, 'weight' => <weight>]])
78+
if (!isset($server[0]) && isset($server['host'])) {
79+
$host = (string) $server['host'];
80+
$port = isset($server['port']) ? (int) $server['port'] : $port;
81+
$weight = isset($server['weight']) ? (int) $server['weight'] : $weight;
82+
}
83+
84+
} else {
85+
// parse server from URI host{:?port}{?weight}
86+
$server = trim($server);
87+
if (strpos($server, '://') === false) {
88+
$server = 'tcp://' . $server;
89+
}
90+
91+
$server = parse_url($server);
92+
if (!$server) {
93+
throw new Exception\InvalidArgumentException("Invalid server given");
94+
}
95+
96+
$host = $server['host'];
97+
$port = isset($server['port']) ? (int) $server['port'] : $port;
98+
99+
if (isset($server['query'])) {
100+
$query = null;
101+
parse_str($server['query'], $query);
102+
if (isset($query['weight'])) {
103+
$weight = (int) $query['weight'];
104+
}
105+
}
106+
}
107+
108+
if (!$host) {
109+
throw new Exception\InvalidArgumentException('Missing required server host');
110+
}
111+
112+
$server = array(
113+
'host' => $host,
114+
'port' => $port,
115+
'weight' => $weight,
116+
);
117+
}
118+
31119
/**
32120
* Check if a resource exists
33121
*
@@ -372,26 +460,6 @@ public function setServers($id, $servers)
372460
return $this;
373461
}
374462

375-
/**
376-
* Get servers
377-
* @param string $id
378-
* @throws Exception\RuntimeException
379-
* @return array array('host' => <host>, 'port' => <port>, 'weight' => <weight>)
380-
*/
381-
public function getServers($id)
382-
{
383-
if (!$this->hasResource($id)) {
384-
throw new Exception\RuntimeException("No resource with id '{$id}'");
385-
}
386-
387-
$resource = & $this->resources[$id];
388-
389-
if ($resource instanceof MemcachedResource) {
390-
return $resource->getServerList();
391-
}
392-
return $resource['servers'];
393-
}
394-
395463
/**
396464
* Add servers
397465
*
@@ -461,74 +529,6 @@ protected function normalizeServers(& $servers)
461529
$servers = array_values($result);
462530
}
463531

464-
/**
465-
* Normalize one server into the following format:
466-
* array('host' => <host>, 'port' => <port>, 'weight' => <weight>)
467-
*
468-
* @param string|array $server
469-
* @throws Exception\InvalidArgumentException
470-
*/
471-
protected function normalizeServer(& $server)
472-
{
473-
$host = null;
474-
$port = 11211;
475-
$weight = 0;
476-
477-
// convert a single server into an array
478-
if ($server instanceof Traversable) {
479-
$server = ArrayUtils::iteratorToArray($server);
480-
}
481-
482-
if (is_array($server)) {
483-
// array(<host>[, <port>[, <weight>]])
484-
if (isset($server[0])) {
485-
$host = (string) $server[0];
486-
$port = isset($server[1]) ? (int) $server[1] : $port;
487-
$weight = isset($server[2]) ? (int) $server[2] : $weight;
488-
}
489-
490-
// array('host' => <host>[, 'port' => <port>[, 'weight' => <weight>]])
491-
if (!isset($server[0]) && isset($server['host'])) {
492-
$host = (string) $server['host'];
493-
$port = isset($server['port']) ? (int) $server['port'] : $port;
494-
$weight = isset($server['weight']) ? (int) $server['weight'] : $weight;
495-
}
496-
497-
} else {
498-
// parse server from URI host{:?port}{?weight}
499-
$server = trim($server);
500-
if (strpos($server, '://') === false) {
501-
$server = 'tcp://' . $server;
502-
}
503-
504-
$server = parse_url($server);
505-
if (!$server) {
506-
throw new Exception\InvalidArgumentException("Invalid server given");
507-
}
508-
509-
$host = $server['host'];
510-
$port = isset($server['port']) ? (int) $server['port'] : $port;
511-
512-
if (isset($server['query'])) {
513-
$query = null;
514-
parse_str($server['query'], $query);
515-
if (isset($query['weight'])) {
516-
$weight = (int) $query['weight'];
517-
}
518-
}
519-
}
520-
521-
if (!$host) {
522-
throw new Exception\InvalidArgumentException('Missing required server host');
523-
}
524-
525-
$server = array(
526-
'host' => $host,
527-
'port' => $port,
528-
'weight' => $weight,
529-
);
530-
}
531-
532532
/**
533533
* Compare 2 normalized server arrays
534534
* (Compares only the host and the port)

0 commit comments

Comments
 (0)