Exemplo n.º 1
0
 /**
  * 设定配置
  *
  * @param  array|string  $key
  * @param  mixed   $value
  * @return void
  */
 public function set($key, $value = null)
 {
     if (is_array($key)) {
         foreach ($key as $innerKey => $innerValue) {
             Arr::set($this->items, $innerKey, $innerValue);
         }
     } else {
         Arr::set($this->items, $key, $value);
     }
 }
Exemplo n.º 2
0
 /**
  * 创建一个新的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;
 }
Exemplo n.º 3
0
 /**
  * 获取链接配置文件
  *
  * @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;
 }
Exemplo n.º 4
0
 /**
  * 获取配置信息
  *
  * @param  string  $option
  * @return mixed
  */
 public function getConfig($option)
 {
     return Arr::get($this->config, $option);
 }
Exemplo n.º 5
0
 /**
  * 获取当前查询实例的绑定(一纬数组化)
  *
  * @return array
  */
 public function getBindings()
 {
     return Arr::flatten($this->bindings);
 }
Exemplo n.º 6
0
 /**
  * 完成保存进程后
  *
  * @param  array  $options
  * @return void
  */
 protected function finishSave(array $options)
 {
     $this->event('saved', false);
     $this->syncOriginal();
     if (Arr::get($options, 'touch', true)) {
         $this->touchOwners();
     }
 }
Exemplo n.º 7
0
 /**
  * 获取一个宏定义(闭包)
  *
  * @param  string  $name
  * @return \Closure
  */
 public function getMacro($name)
 {
     return Arr::get($this->macros, $name);
 }
Exemplo n.º 8
0
 /**
  * 返回集合中,最后一个通过指定测试的元素
  * 你也可以不传入参数使用 last 方法以获取集合中最后一个元素
  *
  * @param  callable|null  $callback
  * @param  mixed  $default
  * @return mixed
  */
 public function last(callable $callback = null, $default = null)
 {
     if (is_null($callback)) {
         return count($this->items) > 0 ? end($this->items) : value($default);
     }
     return Arr::last($this->items, $callback, $default);
 }
Exemplo n.º 9
0
 /**
  * 分析配置
  *
  * @param  array   $config
  * @param  string  $name
  * @return array
  */
 protected function parseConfig(array $config, $name)
 {
     return Arr::add(Arr::add($config, 'prefix', ''), 'name', $name);
 }
Exemplo n.º 10
0
 /**
  * 获取已经注册过的服务提供商
  * @param  \CatLib\Support\ServiceProvider|string $provider 服务提供商
  * @return \CatLib\Support\ServiceProvider|null
  */
 public function getProvider($provider)
 {
     $name = is_string($provider) ? $provider : get_class($provider);
     return Arr::first($this->serviceProviders, function ($key, $value) use($name) {
         return $value instanceof $name;
     });
 }
Exemplo n.º 11
0
 /**
  * 通过点号来设置数组
  *
  * @param  mixed  $target
  * @param  string|array  $key
  * @param  mixed  $value
  * @param  bool  $overwrite
  * @return mixed
  */
 function data_set(&$target, $key, $value, $overwrite = true)
 {
     $segments = is_array($key) ? $key : explode('.', $key);
     if (($segment = array_shift($segments)) === '*') {
         if (!Arr::accessible($target)) {
             $target = [];
         }
         if ($segments) {
             foreach ($target as &$inner) {
                 data_set($inner, $segments, $value, $overwrite);
             }
         } elseif ($overwrite) {
             foreach ($target as &$inner) {
                 $inner = $value;
             }
         }
     } elseif (Arr::accessible($target)) {
         if ($segments) {
             if (!Arr::exists($target, $segment)) {
                 $target[$segment] = [];
             }
             data_set($target[$segment], $segments, $value, $overwrite);
         } elseif ($overwrite || !Arr::exists($target, $segment)) {
             $target[$segment] = $value;
         }
     } elseif (is_object($target)) {
         if ($segments) {
             if (!isset($target->{$segment})) {
                 $target->{$segment} = [];
             }
             data_set($target->{$segment}, $segments, $value, $overwrite);
         } elseif ($overwrite || !isset($target->{$segment})) {
             $target->{$segment} = $value;
         }
     }
     return $target;
 }