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\Queue\Capsule;
4
 
5
use Illuminate\Container\Container;
6
use Illuminate\Queue\QueueManager;
7
use Illuminate\Queue\QueueServiceProvider;
8
use Illuminate\Support\Traits\CapsuleManagerTrait;
9
 
10
/**
11
 * @mixin \Illuminate\Queue\QueueManager
12
 * @mixin \Illuminate\Contracts\Queue\Queue
13
 */
14
class Manager
15
{
16
    use CapsuleManagerTrait;
17
 
18
    /**
19
     * The queue manager instance.
20
     *
21
     * @var \Illuminate\Queue\QueueManager
22
     */
23
    protected $manager;
24
 
25
    /**
26
     * Create a new queue capsule manager.
27
     *
28
     * @param  \Illuminate\Container\Container|null  $container
29
     * @return void
30
     */
31
    public function __construct(Container $container = null)
32
    {
33
        $this->setupContainer($container ?: new Container);
34
 
35
        // Once we have the container setup, we will set up the default configuration
36
        // options in the container "config" bindings. This'll just make the queue
37
        // manager behave correctly since all the correct bindings are in place.
38
        $this->setupDefaultConfiguration();
39
 
40
        $this->setupManager();
41
 
42
        $this->registerConnectors();
43
    }
44
 
45
    /**
46
     * Setup the default queue configuration options.
47
     *
48
     * @return void
49
     */
50
    protected function setupDefaultConfiguration()
51
    {
52
        $this->container['config']['queue.default'] = 'default';
53
    }
54
 
55
    /**
56
     * Build the queue manager instance.
57
     *
58
     * @return void
59
     */
60
    protected function setupManager()
61
    {
62
        $this->manager = new QueueManager($this->container);
63
    }
64
 
65
    /**
66
     * Register the default connectors that the component ships with.
67
     *
68
     * @return void
69
     */
70
    protected function registerConnectors()
71
    {
72
        $provider = new QueueServiceProvider($this->container);
73
 
74
        $provider->registerConnectors($this->manager);
75
    }
76
 
77
    /**
78
     * Get a connection instance from the global manager.
79
     *
80
     * @param  string|null  $connection
81
     * @return \Illuminate\Contracts\Queue\Queue
82
     */
83
    public static function connection($connection = null)
84
    {
85
        return static::$instance->getConnection($connection);
86
    }
87
 
88
    /**
89
     * Push a new job onto the queue.
90
     *
91
     * @param  string  $job
92
     * @param  mixed  $data
93
     * @param  string|null  $queue
94
     * @param  string|null  $connection
95
     * @return mixed
96
     */
97
    public static function push($job, $data = '', $queue = null, $connection = null)
98
    {
99
        return static::$instance->connection($connection)->push($job, $data, $queue);
100
    }
101
 
102
    /**
103
     * Push a new an array of jobs onto the queue.
104
     *
105
     * @param  array  $jobs
106
     * @param  mixed  $data
107
     * @param  string|null  $queue
108
     * @param  string|null  $connection
109
     * @return mixed
110
     */
111
    public static function bulk($jobs, $data = '', $queue = null, $connection = null)
112
    {
113
        return static::$instance->connection($connection)->bulk($jobs, $data, $queue);
114
    }
115
 
116
    /**
117
     * Push a new job onto the queue after (n) seconds.
118
     *
119
     * @param  \DateTimeInterface|\DateInterval|int  $delay
120
     * @param  string  $job
121
     * @param  mixed  $data
122
     * @param  string|null  $queue
123
     * @param  string|null  $connection
124
     * @return mixed
125
     */
126
    public static function later($delay, $job, $data = '', $queue = null, $connection = null)
127
    {
128
        return static::$instance->connection($connection)->later($delay, $job, $data, $queue);
129
    }
130
 
131
    /**
132
     * Get a registered connection instance.
133
     *
134
     * @param  string|null  $name
135
     * @return \Illuminate\Contracts\Queue\Queue
136
     */
137
    public function getConnection($name = null)
138
    {
139
        return $this->manager->connection($name);
140
    }
141
 
142
    /**
143
     * Register a connection with the manager.
144
     *
145
     * @param  array  $config
146
     * @param  string  $name
147
     * @return void
148
     */
149
    public function addConnection(array $config, $name = 'default')
150
    {
151
        $this->container['config']["queue.connections.{$name}"] = $config;
152
    }
153
 
154
    /**
155
     * Get the queue manager instance.
156
     *
157
     * @return \Illuminate\Queue\QueueManager
158
     */
159
    public function getQueueManager()
160
    {
161
        return $this->manager;
162
    }
163
 
164
    /**
165
     * Pass dynamic instance methods to the manager.
166
     *
167
     * @param  string  $method
168
     * @param  array  $parameters
169
     * @return mixed
170
     */
171
    public function __call($method, $parameters)
172
    {
173
        return $this->manager->$method(...$parameters);
174
    }
175
 
176
    /**
177
     * Dynamically pass methods to the default connection.
178
     *
179
     * @param  string  $method
180
     * @param  array  $parameters
181
     * @return mixed
182
     */
183
    public static function __callStatic($method, $parameters)
184
    {
185
        return static::connection()->$method(...$parameters);
186
    }
187
}