コード例 #1
0
ファイル: Repository.php プロジェクト: catlib/config
 /**
  * 设定配置
  *
  * @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);
     }
 }
コード例 #2
0
ファイル: Connector.php プロジェクト: yb199478/framework
 /**
  * 创建一个新的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;
 }
コード例 #3
0
ファイル: RedisManager.php プロジェクト: catlib/redis
 /**
  * 获取链接配置文件
  *
  * @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;
 }
コード例 #4
0
ファイル: Connection.php プロジェクト: yb199478/framework
 /**
  * 获取配置信息
  *
  * @param  string  $option
  * @return mixed
  */
 public function getConfig($option)
 {
     return Arr::get($this->config, $option);
 }
コード例 #5
0
ファイル: Builder.php プロジェクト: yb199478/framework
 /**
  * 获取当前查询实例的绑定(一纬数组化)
  *
  * @return array
  */
 public function getBindings()
 {
     return Arr::flatten($this->bindings);
 }
コード例 #6
0
ファイル: ActiveRecord.php プロジェクト: yb199478/framework
 /**
  * 完成保存进程后
  *
  * @param  array  $options
  * @return void
  */
 protected function finishSave(array $options)
 {
     $this->event('saved', false);
     $this->syncOriginal();
     if (Arr::get($options, 'touch', true)) {
         $this->touchOwners();
     }
 }
コード例 #7
0
ファイル: Macros.php プロジェクト: catlib/support
 /**
  * 获取一个宏定义(闭包)
  *
  * @param  string  $name
  * @return \Closure
  */
 public function getMacro($name)
 {
     return Arr::get($this->macros, $name);
 }
コード例 #8
0
ファイル: Collection.php プロジェクト: catlib/collection
 /**
  * 返回集合中,最后一个通过指定测试的元素
  * 你也可以不传入参数使用 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);
 }
コード例 #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);
 }
コード例 #10
0
ファイル: Application.php プロジェクト: yb199478/framework
 /**
  * 获取已经注册过的服务提供商
  * @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;
     });
 }
コード例 #11
0
ファイル: helpers.php プロジェクト: catlib/support
 /**
  * 通过点号来设置数组
  *
  * @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;
 }