]> _ Git - physioassist-wordpress.git/blob
f68b8291b8abca4495bd14eecde863e3a6916dd7
[physioassist-wordpress.git] /
1 <?php
2
3 use WPML\Collect\Support\Arr;
4 use WPML\Collect\Support\Collection;
5
6 if (! function_exists('wpml_collect')) {
7     /**
8      * Create a collection from the given value.
9      *
10      * @param  mixed  $value
11      * @return \WPML\Collect\Support\Collection
12      */
13     function wpml_collect($value = null)
14     {
15         return new Collection($value);
16     }
17 }
18
19 if (! function_exists('value')) {
20     /**
21      * Return the default value of the given value.
22      *
23      * @param  mixed  $value
24      * @return mixed
25      */
26     function value($value)
27     {
28         return $value instanceof Closure ? $value() : $value;
29     }
30 }
31
32 if (! function_exists('data_get')) {
33     /**
34      * Get an item from an array or object using "dot" notation.
35      *
36      * @param  mixed   $target
37      * @param  string|array  $key
38      * @param  mixed   $default
39      * @return mixed
40      */
41     function data_get($target, $key, $default = null)
42     {
43         if (is_null($key)) {
44             return $target;
45         }
46
47         $key = is_array($key) ? $key : explode('.', $key);
48
49         while (($segment = array_shift($key)) !== null) {
50             if ($segment === '*') {
51                 if ($target instanceof Collection) {
52                     $target = $target->all();
53                 } elseif (! is_array($target)) {
54                     return value($default);
55                 }
56
57                 $result = Arr::pluck($target, $key);
58
59                 return in_array('*', $key) ? Arr::collapse($result) : $result;
60             }
61
62             if (Arr::accessible($target) && Arr::exists($target, $segment)) {
63                 $target = $target[$segment];
64             } elseif (is_object($target) && isset($target->{$segment})) {
65                 $target = $target->{$segment};
66             } else {
67                 return value($default);
68             }
69         }
70
71         return $target;
72     }
73 }
74
75 if (! function_exists('with')) {
76     /**
77      * Return the given object. Useful for chaining.
78      *
79      * @param  mixed  $object
80      * @return mixed
81      */
82     function with($object)
83     {
84         return $object;
85     }
86 }