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