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;
4
 
5
use Carbon\CarbonInterval;
6
use Illuminate\Contracts\Cache\Factory as Cache;
7
 
8
class CacheCommandMutex implements CommandMutex
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 = null;
23
 
24
    /**
25
     * Create a new command mutex.
26
     *
27
     * @param  \Illuminate\Contracts\Cache\Factory  $cache
28
     */
29
    public function __construct(Cache $cache)
30
    {
31
        $this->cache = $cache;
32
    }
33
 
34
    /**
35
     * Attempt to obtain a command mutex for the given command.
36
     *
37
     * @param  \Illuminate\Console\Command  $command
38
     * @return bool
39
     */
40
    public function create($command)
41
    {
42
        return $this->cache->store($this->store)->add(
43
            $this->commandMutexName($command),
44
            true,
45
            method_exists($command, 'isolationLockExpiresAt')
46
                    ? $command->isolationLockExpiresAt()
47
                    : CarbonInterval::hour(),
48
        );
49
    }
50
 
51
    /**
52
     * Determine if a command mutex exists for the given command.
53
     *
54
     * @param  \Illuminate\Console\Command  $command
55
     * @return bool
56
     */
57
    public function exists($command)
58
    {
59
        return $this->cache->store($this->store)->has(
60
            $this->commandMutexName($command)
61
        );
62
    }
63
 
64
    /**
65
     * Release the mutex for the given command.
66
     *
67
     * @param  \Illuminate\Console\Command  $command
68
     * @return bool
69
     */
70
    public function forget($command)
71
    {
72
        return $this->cache->store($this->store)->forget(
73
            $this->commandMutexName($command)
74
        );
75
    }
76
 
77
    /**
78
     * @param  \Illuminate\Console\Command  $command
79
     * @return string
80
     */
81
    protected function commandMutexName($command)
82
    {
83
        return 'framework'.DIRECTORY_SEPARATOR.'command-'.$command->getName();
84
    }
85
 
86
    /**
87
     * Specify the cache store that should be used.
88
     *
89
     * @param  string|null  $store
90
     * @return $this
91
     */
92
    public function useStore($store)
93
    {
94
        $this->store = $store;
95
 
96
        return $this;
97
    }
98
}