Skip to content

Commit d41435a

Browse files
committed
Merge branch '5.4'
2 parents 4d74518 + 4e85a9a commit d41435a

File tree

12 files changed

+198
-57
lines changed

12 files changed

+198
-57
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
namespace Illuminate\Events;
4+
5+
use Illuminate\Container\Container;
6+
use Illuminate\Contracts\Queue\Job;
7+
use Illuminate\Queue\InteractsWithQueue;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
10+
class CallQueuedListener implements ShouldQueue
11+
{
12+
use InteractsWithQueue;
13+
14+
/**
15+
* The listener class name.
16+
*
17+
* @var string
18+
*/
19+
public $class;
20+
21+
/**
22+
* The listener method.
23+
*
24+
* @var string
25+
*/
26+
public $method;
27+
28+
/**
29+
* The data to be passed to the listener.
30+
*
31+
* @var string
32+
*/
33+
public $data;
34+
35+
/**
36+
* Create a new job instance.
37+
*
38+
* @param string $class
39+
* @param string $method
40+
* @param string $data
41+
* @return void
42+
*/
43+
public function __construct($class, $method, $data)
44+
{
45+
$this->data = $data;
46+
$this->class = $class;
47+
$this->method = $method;
48+
}
49+
50+
/**
51+
* Handle the queued job.
52+
*
53+
* @param \Illuminate\Container\Container $container
54+
* @return void
55+
*/
56+
public function handle(Container $container)
57+
{
58+
$handler = $this->setJobInstanceIfNecessary(
59+
$this->job, $container->make($this->class)
60+
);
61+
62+
call_user_func_array(
63+
[$handler, $this->method], unserialize($this->data)
64+
);
65+
}
66+
67+
/**
68+
* Set the job instance of the given class if necessary.
69+
*
70+
* @param \Illuminate\Contracts\Queue\Job $job
71+
* @param mixed $instance
72+
* @return mixed
73+
*/
74+
protected function setJobInstanceIfNecessary(Job $job, $instance)
75+
{
76+
if (in_array(InteractsWithQueue::class, class_uses_recursive(get_class($instance)))) {
77+
$instance->setJob($job);
78+
}
79+
80+
return $instance;
81+
}
82+
83+
/**
84+
* Call the failed method on the job instance.
85+
*
86+
* The event instance and the exception will be passed.
87+
*
88+
* @param \Exception $e
89+
* @return void
90+
*/
91+
public function failed($e)
92+
{
93+
$handler = Container::getInstance()->make($this->class);
94+
95+
$parameters = array_merge(unserialize($this->data), [$e]);
96+
97+
if (method_exists($handler, 'failed')) {
98+
call_user_func_array([$handler, 'failed'], $parameters);
99+
}
100+
}
101+
}

src/Illuminate/Events/Dispatcher.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -450,19 +450,15 @@ protected function callQueueMethodOnHandler($class, $method, $arguments)
450450
*/
451451
protected function queueHandler($class, $method, $arguments)
452452
{
453-
$handler = (new ReflectionClass($class))->newInstanceWithoutConstructor();
453+
$listener = (new ReflectionClass($class))->newInstanceWithoutConstructor();
454454

455-
$connection = isset($handler->connection) ? $handler->connection : null;
455+
$connection = isset($listener->connection) ? $listener->connection : null;
456456

457-
$queue = isset($handler->queue) ? $handler->queue : null;
457+
$queue = isset($listener->queue) ? $listener->queue : null;
458458

459459
$this->resolveQueue()
460460
->connection($connection)
461-
->pushOn($queue, 'Illuminate\Events\CallQueuedHandler@call', [
462-
'class' => $class,
463-
'method' => $method,
464-
'data' => serialize($arguments),
465-
]);
461+
->pushOn($queue, new CallQueuedListener($class, $method, serialize($arguments)));
466462
}
467463

468464
/**

src/Illuminate/Foundation/Console/Kernel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public function call($command, array $parameters = [], $outputBuffer = null)
231231
public function queue($command, array $parameters = [])
232232
{
233233
$this->app[QueueContract::class]->push(
234-
QueuedJob::class, func_get_args()
234+
new QueuedCommand(func_get_args())
235235
);
236236
}
237237

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Illuminate\Foundation\Console;
4+
5+
use Illuminate\Contracts\Queue\ShouldQueue;
6+
use Illuminate\Contracts\Console\Kernel as KernelContract;
7+
8+
class QueuedCommand implements ShouldQueue
9+
{
10+
/**
11+
* The data to pass to the Artisan command.
12+
*
13+
* @var array
14+
*/
15+
protected $data;
16+
17+
/**
18+
* Create a new job instance.
19+
*
20+
* @param array $data
21+
* @return void
22+
*/
23+
public function __construct($data)
24+
{
25+
$this->data = $data;
26+
}
27+
28+
/**
29+
* Handle the job.
30+
*
31+
* @param \Illuminate\Contracts\Console\Kernel $kernel
32+
* @return void
33+
*/
34+
public function handle(KernelContract $kernel)
35+
{
36+
call_user_func_array([$kernel, 'call'], $this->data);
37+
}
38+
}

src/Illuminate/Foundation/Console/QueuedJob.php

-40
This file was deleted.

src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ protected function loadCachedRoutes()
6666
*/
6767
protected function loadRoutes()
6868
{
69-
$this->app->call([$this, 'map']);
69+
if (method_exists($this, 'map')) {
70+
$this->app->call([$this, 'map']);
71+
}
7072
}
7173

7274
/**

src/Illuminate/Log/Writer.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,12 @@ public function useDailyFiles($path, $days = 0, $level = 'debug')
239239
*
240240
* @param string $name
241241
* @param string $level
242+
* @param mixed $facility
242243
* @return \Psr\Log\LoggerInterface
243244
*/
244-
public function useSyslog($name = 'laravel', $level = 'debug')
245+
public function useSyslog($name = 'laravel', $level = 'debug', $facility = LOG_USER)
245246
{
246-
return $this->monolog->pushHandler(new SyslogHandler($name, LOG_USER, $level));
247+
return $this->monolog->pushHandler(new SyslogHandler($name, $facility, $level));
247248
}
248249

249250
/**

src/Illuminate/Queue/Jobs/JobName.php

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public static function parse($job)
2727
*/
2828
public static function resolve($name, $payload)
2929
{
30+
if (isset($payload['displayName']) && ! empty($payload['displayName'])) {
31+
return $payload['displayName'];
32+
}
33+
3034
if ($name === 'Illuminate\Queue\CallQueuedHandler@call') {
3135
return Arr::get($payload, 'data.commandName', $name);
3236
}

src/Illuminate/Queue/Queue.php

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Queue;
44

55
use Illuminate\Container\Container;
6+
use Illuminate\Events\CallQueuedListener;
67

78
abstract class Queue
89
{
@@ -116,6 +117,7 @@ protected function createPayloadArray($job, $data = '', $queue = null)
116117
protected function createObjectPayload($job)
117118
{
118119
return [
120+
'displayName' => $this->getDisplayName($job),
119121
'job' => 'Illuminate\Queue\CallQueuedHandler@call',
120122
'maxTries' => isset($job->tries) ? $job->tries : null,
121123
'timeout' => isset($job->timeout) ? $job->timeout : null,
@@ -126,6 +128,21 @@ protected function createObjectPayload($job)
126128
];
127129
}
128130

131+
/**
132+
* Get the display name for the given job.
133+
*
134+
* @param mixed $job
135+
* @return string
136+
*/
137+
protected function getDisplayName($job)
138+
{
139+
if ($job instanceof CallQueuedListener) {
140+
return $job->class;
141+
}
142+
143+
return get_class($job);
144+
}
145+
129146
/**
130147
* Create a typical, string based queue payload array.
131148
*

src/Illuminate/Support/Collection.php

+13
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,19 @@ public function take($limit)
11741174
return $this->slice(0, $limit);
11751175
}
11761176

1177+
/**
1178+
* Pass the collection to the given callback and then return it.
1179+
*
1180+
* @param callable $callback
1181+
* @return $this
1182+
*/
1183+
public function tap(callable $callback)
1184+
{
1185+
$callback(new static($this->items));
1186+
1187+
return $this;
1188+
}
1189+
11771190
/**
11781191
* Transform each item in the collection using a callback.
11791192
*

tests/Events/EventsDispatcherTest.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,7 @@ public function testQueuedEventHandlersAreQueued()
173173

174174
$queue->shouldReceive('connection')->once()->with(null)->andReturnSelf();
175175

176-
$queue->shouldReceive('pushOn')->once()->with(null, 'Illuminate\Events\CallQueuedHandler@call', [
177-
'class' => 'Illuminate\Tests\Events\TestDispatcherQueuedHandler',
178-
'method' => 'someMethod',
179-
'data' => serialize(['foo', 'bar']),
180-
]);
176+
$queue->shouldReceive('pushOn')->once()->with(null, m::type('Illuminate\Events\CallQueuedListener'));
181177

182178
$d->setQueueResolver(function () use ($queue) {
183179
return $queue;

tests/Support/SupportCollectionTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,19 @@ public function testHigherOrderPartition()
18821882

18831883
$this->assertSame(['b' => ['free' => false]], $premium->toArray());
18841884
}
1885+
1886+
public function testTap()
1887+
{
1888+
$collection = new Collection([1, 2, 3]);
1889+
1890+
$fromTap = [];
1891+
$collection = $collection->tap(function ($collection) use (&$fromTap) {
1892+
$fromTap = $collection->slice(0, 1)->toArray();
1893+
});
1894+
1895+
$this->assertSame([1], $fromTap);
1896+
$this->assertSame([1, 2, 3], $collection->toArray());
1897+
}
18851898
}
18861899

18871900
class TestSupportCollectionHigherOrderItem

0 commit comments

Comments
 (0)