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\Console\Scheduling;
4
 
5
use DateTimeInterface;
6
use Illuminate\Contracts\Cache\Factory as Cache;
7
 
8
class CacheSchedulingMutex implements SchedulingMutex, CacheAware
9
{
10
    /**
11
     * The cache factory implementation.
12
     *
13
     * @var \Illuminate\Contracts\Cache\Factory
14
     */
15
    public $cache;
16
 
17
    /**
18
     * The cache store that should be used.
19
     *
20
     * @var string|null
21
     */
22
    public $store;
23
 
24
    /**
25
     * Create a new scheduling strategy.
26
     *
27
     * @param  \Illuminate\Contracts\Cache\Factory  $cache
28
     * @return void
29
     */
30
    public function __construct(Cache $cache)
31
    {
32
        $this->cache = $cache;
33
    }
34
 
35
    /**
36
     * Attempt to obtain a scheduling mutex for the given event.
37
     *
38
     * @param  \Illuminate\Console\Scheduling\Event  $event
39
     * @param  \DateTimeInterface  $time
40
     * @return bool
41
     */
42
    public function create(Event $event, DateTimeInterface $time)
43
    {
44
        return $this->cache->store($this->store)->add(
45
            $event->mutexName().$time->format('Hi'), true, 3600
46
        );
47
    }
48
 
49
    /**
50
     * Determine if a scheduling mutex exists for the given event.
51
     *
52
     * @param  \Illuminate\Console\Scheduling\Event  $event
53
     * @param  \DateTimeInterface  $time
54
     * @return bool
55
     */
56
    public function exists(Event $event, DateTimeInterface $time)
57
    {
58
        return $this->cache->store($this->store)->has(
59
            $event->mutexName().$time->format('Hi')
60
        );
61
    }
62
 
63
    /**
64
     * Specify the cache store that should be used.
65
     *
66
     * @param  string  $store
67
     * @return $this
68
     */
69
    public function useStore($store)
70
    {
71
        $this->store = $store;
72
 
73
        return $this;
74
    }
75
}