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
class CacheLock extends Lock
6
{
7
    /**
8
     * The cache store implementation.
9
     *
10
     * @var \Illuminate\Contracts\Cache\Store
11
     */
12
    protected $store;
13
 
14
    /**
15
     * Create a new lock instance.
16
     *
17
     * @param  \Illuminate\Contracts\Cache\Store  $store
18
     * @param  string  $name
19
     * @param  int  $seconds
20
     * @param  string|null  $owner
21
     * @return void
22
     */
23
    public function __construct($store, $name, $seconds, $owner = null)
24
    {
25
        parent::__construct($name, $seconds, $owner);
26
 
27
        $this->store = $store;
28
    }
29
 
30
    /**
31
     * Attempt to acquire the lock.
32
     *
33
     * @return bool
34
     */
35
    public function acquire()
36
    {
37
        if (method_exists($this->store, 'add') && $this->seconds > 0) {
38
            return $this->store->add(
39
                $this->name, $this->owner, $this->seconds
40
            );
41
        }
42
 
43
        if (! is_null($this->store->get($this->name))) {
44
            return false;
45
        }
46
 
47
        return ($this->seconds > 0)
48
                ? $this->store->put($this->name, $this->owner, $this->seconds)
49
                : $this->store->forever($this->name, $this->owner);
50
    }
51
 
52
    /**
53
     * Release the lock.
54
     *
55
     * @return bool
56
     */
57
    public function release()
58
    {
59
        if ($this->isOwnedByCurrentProcess()) {
60
            return $this->store->forget($this->name);
61
        }
62
 
63
        return false;
64
    }
65
 
66
    /**
67
     * Releases this lock regardless of ownership.
68
     *
69
     * @return void
70
     */
71
    public function forceRelease()
72
    {
73
        $this->store->forget($this->name);
74
    }
75
 
76
    /**
77
     * Returns the owner value written into the driver for this lock.
78
     *
79
     * @return mixed
80
     */
81
    protected function getCurrentOwner()
82
    {
83
        return $this->store->get($this->name);
84
    }
85
}