Ejemplo n.º 1
0
 /**
  * Get an item from an array or object using "dot" notation.
  *
  * @param  mixed   $target
  * @param  string|array  $key
  * @param  mixed   $default
  * @return mixed
  */
 function data_get($target, $key, $default = null)
 {
     if (is_null($key)) {
         return $target;
     }
     $key = is_array($key) ? $key : explode('.', $key);
     while (($segment = array_shift($key)) !== null) {
         if ($segment === '*') {
             if ($target instanceof Collection) {
                 $target = $target->all();
             } elseif (!is_array($target)) {
                 return value($default);
             }
             $result = Arr::pluck($target, $key);
             return in_array('*', $key) ? Arr::collapse($result) : $result;
         }
         if (Arr::accessible($target) && Arr::exists($target, $segment)) {
             $target = $target[$segment];
         } elseif (is_object($target) && isset($target->{$segment})) {
             $target = $target->{$segment};
         } else {
             return value($default);
         }
     }
     return $target;
 }
Ejemplo n.º 2
0
 /**
  * Set a given configuration value.
  *
  * @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);
     }
 }
Ejemplo n.º 3
0
 /**
  * Get and remove an item from the collection.
  *
  * @param  mixed  $key
  * @param  mixed  $default
  * @return mixed
  */
 public function pull($key, $default = null)
 {
     return Arr::pull($this->items, $key, $default);
 }
Ejemplo n.º 4
0
 /**
  * Get the registered service provider instance if it exists.
  *
  * @param  ServiceProvider|string  $provider
  * @return 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;
     });
 }