/** * 解析链接实例名分析出是读还是写 * * @param string $name * @return array */ protected function parseConnectionName($name) { $name = $name ?: $this->getDefaultConnection(); return Str::endsWith($name, ['::read', '::write']) ? explode('::', $name, 2) : [$name, null]; }
/** * 确定异常是否由于是链接丢失造成的 * * @param \Exception $e * @return bool */ protected function causedByLostConnection(Exception $e) { $message = $e->getMessage(); return Str::contains($message, ['server has gone away', 'no connection to the server', 'Lost connection', 'is dead or not enabled', 'Error while sending', 'decryption failed or bad record mac', 'server closed the connection unexpectedly', 'SSL connection has been closed unexpectedly', 'Deadlock found when trying to get lock', 'Error writing data to the connection']); }
/** * 获取通配符监听事件 * @param string $event 事件 * @return array */ protected function getWildcardListeners($event) { $wildcards = []; foreach ($this->wildcards as $key => $listeners) { if (Str::is($key, $event)) { $wildcards = array_merge($wildcards, $listeners); } } return $wildcards; }
/** * 获取环境变量 * * @param string $key * @param mixed $default * @return mixed */ function env($key, $default = null) { $value = getenv($key); if ($value === false) { return value($default); } switch (strtolower($value)) { case 'true': case '(true)': return true; case 'false': case '(false)': return false; case 'empty': case '(empty)': return ''; case 'null': case '(null)': return; } if (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) { return substr($value, 1, -1); } return $value; }