/** * 创建一个新的PDO链接 * * @param string $dsn * @param array $config * @param array $options * @return \PDO */ public function createConnection($dsn, array $config, array $options) { $username = Arr::get($config, 'username'); $password = Arr::get($config, 'password'); try { $pdo = new PDO($dsn, $username, $password, $options); } catch (Exception $e) { $pdo = $this->tryAgainIfCausedByLostConnection($e, $dsn, $username, $password, $options); } return $pdo; }
/** * 获取链接配置文件 * * @param string $name * @return array * * @throws \InvalidArgumentException */ protected function getConfig($name) { $name = $name ?: $this->getDefaultConnection(); $connections = $this->app['env']['redis']['connections']; if (is_null($config = Arr::get($connections, $name))) { throw new InvalidArgumentException("Redis [{$name}] not configured."); } return $config; }
/** * 获取配置信息 * * @param string $option * @return mixed */ public function getConfig($option) { return Arr::get($this->config, $option); }
/** * 获取指定配置 * * @param string $key * @param mixed $default * @return mixed */ public function get($key, $default = null) { return Arr::get($this->items, $key, $default); }
/** * 完成保存进程后 * * @param array $options * @return void */ protected function finishSave(array $options) { $this->event('saved', false); $this->syncOriginal(); if (Arr::get($options, 'touch', true)) { $this->touchOwners(); } }
/** * 获取一个宏定义(闭包) * * @param string $name * @return \Closure */ public function getMacro($name) { return Arr::get($this->macros, $name); }
/** * 使用 "逗点" 符号从深度巢状数组取回给定的值。 * * @param \ArrayAccess|array $array * @param string $key * @param mixed $default * @return mixed */ function array_get($array, $key, $default = null) { return Arr::get($array, $key, $default); }