Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Cache;
4
 
5
trait RetrievesMultipleKeys
6
{
7
    /**
8
     * Retrieve multiple items from the cache by key.
9
     *
10
     * Items not found in the cache will have a null value.
11
     *
12
     * @param  array  $keys
13
     * @return array
14
     */
15
    public function many(array $keys)
16
    {
17
        $return = [];
18
 
19
        $keys = collect($keys)->mapWithKeys(function ($value, $key) {
20
            return [is_string($key) ? $key : $value => is_string($key) ? $value : null];
21
        })->all();
22
 
23
        foreach ($keys as $key => $default) {
24
            $return[$key] = $this->get($key, $default);
25
        }
26
 
27
        return $return;
28
    }
29
 
30
    /**
31
     * Store multiple items in the cache for a given number of seconds.
32
     *
33
     * @param  array  $values
34
     * @param  int  $seconds
35
     * @return bool
36
     */
37
    public function putMany(array $values, $seconds)
38
    {
39
        $manyResult = null;
40
 
41
        foreach ($values as $key => $value) {
42
            $result = $this->put($key, $value, $seconds);
43
 
44
            $manyResult = is_null($manyResult) ? $result : $result && $manyResult;
45
        }
46
 
47
        return $manyResult ?: false;
48
    }
49
}