← All changes
|
includes/sdk/google/google/grpc-gcp/src/Config.php
+12
-12
1.2.4
→
1.4.2
View file →
| @@ -16,11 +16,11 @@ | ||
| 16 | 16 | * See the License for the specific language governing permissions and |
| 17 | 17 | * limitations under the License. |
| 18 | 18 | * |
| 19 | 19 | */ |
| 20 | -namespace Dudlewebs\WPMCS\Grpc\Gcp; | |
| 20 | +namespace Dudlewebs\WPMCS\GCP\Grpc\Gcp; | |
| 21 | 21 | |
| 22 | -use Dudlewebs\WPMCS\Psr\Cache\CacheItemPoolInterface; | |
| 22 | +use Dudlewebs\WPMCS\GCP\Psr\Cache\CacheItemPoolInterface; | |
| 23 | 23 | /** |
| 24 | 24 | * Config is used to enable the support for the channel management. |
| 25 | 25 | */ |
| 26 | 26 | class Config |
| @@ -35,19 +35,19 @@ | ||
| 35 | 35 | * @param CacheItemPoolInterface $cacheItemPool A pool for storing configuration and channels |
| 36 | 36 | * cross requests within a single worker process. |
| 37 | 37 | * @throws \RuntimeException When a failure occurs while attempting to attach to shared memory. |
| 38 | 38 | */ |
| 39 | - public function __construct($target, $conf = null, CacheItemPoolInterface $cacheItemPool = null) | |
| 39 | + public function __construct($target, $conf = null, ?CacheItemPoolInterface $cacheItemPool = null) | |
| 40 | 40 | { |
| 41 | 41 | if ($conf == null) { |
| 42 | 42 | // If there is no configure file, use the default gRPC channel. |
| 43 | - $this->gcp_call_invoker = new \Dudlewebs\WPMCS\Grpc\DefaultCallInvoker(); | |
| 43 | + $this->gcp_call_invoker = new \Dudlewebs\WPMCS\GCP\Grpc\DefaultCallInvoker(); | |
| 44 | 44 | return; |
| 45 | 45 | } |
| 46 | 46 | $gcp_channel = null; |
| 47 | - $url_host = parse_url($target, \PHP_URL_HOST); | |
| 47 | + $url_host = \parse_url($target, \PHP_URL_HOST); | |
| 48 | 48 | $this->hostname = $url_host ? $url_host : $target; |
| 49 | - $channel_pool_key = $this->hostname . '.gcp.channel.' . getmypid(); | |
| 49 | + $channel_pool_key = $this->hostname . '.gcp.channel.' . \getmypid(); | |
| 50 | 50 | if (!$cacheItemPool) { |
| 51 | 51 | $affinity_conf = $this->parseConfObject($conf); |
| 52 | 52 | $gcp_call_invoker = new GCPCallInvoker($affinity_conf); |
| 53 | 53 | $this->gcp_call_invoker = $gcp_call_invoker; |
| @@ -54,9 +54,9 @@ | ||
| 54 | 54 | } else { |
| 55 | 55 | $item = $cacheItemPool->getItem($channel_pool_key); |
| 56 | 56 | if ($item->isHit()) { |
| 57 | 57 | // Channel pool for the $hostname API has already created. |
| 58 | - $gcp_call_invoker = unserialize($item->get()); | |
| 58 | + $gcp_call_invoker = \unserialize($item->get()); | |
| 59 | 59 | } else { |
| 60 | 60 | $affinity_conf = $this->parseConfObject($conf); |
| 61 | 61 | // Create GCP channel based on the information. |
| 62 | 62 | $gcp_call_invoker = new GCPCallInvoker($affinity_conf); |
| @@ -61,11 +61,11 @@ | ||
| 61 | 61 | // Create GCP channel based on the information. |
| 62 | 62 | $gcp_call_invoker = new GCPCallInvoker($affinity_conf); |
| 63 | 63 | } |
| 64 | 64 | $this->gcp_call_invoker = $gcp_call_invoker; |
| 65 | - register_shutdown_function(function ($gcp_call_invoker, $cacheItemPool, $item) { | |
| 65 | + \register_shutdown_function(function ($gcp_call_invoker, $cacheItemPool, $item) { | |
| 66 | 66 | // Push the current gcp_channel back into the pool when the script finishes. |
| 67 | - $item->set(serialize($gcp_call_invoker)); | |
| 67 | + $item->set(\serialize($gcp_call_invoker)); | |
| 68 | 68 | $cacheItemPool->save($item); |
| 69 | 69 | }, $gcp_call_invoker, $cacheItemPool, $item); |
| 70 | 70 | } |
| 71 | 71 | } |
| @@ -84,18 +84,18 @@ | ||
| 84 | 84 | return $this->channel->getTarget(); |
| 85 | 85 | } |
| 86 | 86 | private function parseConfObject($conf_object) |
| 87 | 87 | { |
| 88 | - $config = json_decode($conf_object->serializeToJsonString(), \true); | |
| 88 | + $config = \json_decode($conf_object->serializeToJsonString(), \true); | |
| 89 | 89 | if (isset($config['channelPool'])) { |
| 90 | 90 | $affinity_conf['channelPool'] = $config['channelPool']; |
| 91 | 91 | } |
| 92 | 92 | $aff_by_method = array(); |
| 93 | 93 | if (isset($config['method'])) { |
| 94 | - for ($i = 0; $i < count($config['method']); $i++) { | |
| 94 | + for ($i = 0; $i < \count($config['method']); $i++) { | |
| 95 | 95 | // In proto3, if the value is default, eg 0 for int, it won't be serialized. |
| 96 | 96 | // Thus serialized string may not have `command` if the value is default 0(BOUND). |
| 97 | - if (!array_key_exists('command', $config['method'][$i]['affinity'])) { | |
| 97 | + if (!\array_key_exists('command', $config['method'][$i]['affinity'])) { | |
| 98 | 98 | $config['method'][$i]['affinity']['command'] = 'BOUND'; |
| 99 | 99 | } |
| 100 | 100 | $aff_by_method[$config['method'][$i]['name'][0]] = $config['method'][$i]['affinity']; |
| 101 | 101 | } |