From ef20f4b7775278ad6771a4e036948164d2844a17 Mon Sep 17 00:00:00 2001 From: Flugger Date: Sun, 24 Jul 2016 16:17:05 +0200 Subject: [PATCH 001/249] Add relation not found exception --- src/Illuminate/Database/Eloquent/Builder.php | 7 ++++++- .../Database/Eloquent/RelationNotFoundException.php | 10 ++++++++++ tests/Database/DatabaseEloquentBuilderTest.php | 11 +++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 src/Illuminate/Database/Eloquent/RelationNotFoundException.php diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 6b3194416e01..ead238056f49 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -2,6 +2,7 @@ namespace Illuminate\Database\Eloquent; +use BadMethodCallException; use Closure; use Illuminate\Support\Arr; use Illuminate\Support\Str; @@ -677,7 +678,11 @@ public function getRelation($name) // not have to remove these where clauses manually which gets really hacky // and is error prone while we remove the developer's own where clauses. $relation = Relation::noConstraints(function () use ($name) { - return $this->getModel()->$name(); + try { + return $this->getModel()->$name(); + } catch (BadMethodCallException $e) { + throw new RelationNotFoundException("Call to undefined relationship {$name} on Model {$this->getModel()}"); + } }); $nested = $this->nestedRelations($name); diff --git a/src/Illuminate/Database/Eloquent/RelationNotFoundException.php b/src/Illuminate/Database/Eloquent/RelationNotFoundException.php new file mode 100755 index 000000000000..12d037f86356 --- /dev/null +++ b/src/Illuminate/Database/Eloquent/RelationNotFoundException.php @@ -0,0 +1,10 @@ +getRelation('ordersGroups'); } + /** + * @expectedException Illuminate\Database\Eloquent\RelationNotFoundException + */ + public function testGetRelationThrowsException() + { + $builder = $this->getBuilder(); + $builder->setModel($this->getMockModel()); + + $builder->getRelation( 'invalid' ); + } + public function testEagerLoadParsingSetsProperRelationships() { $builder = $this->getBuilder(); From 1028ba3950b0aaa546ed4fd999c4fa07232e897b Mon Sep 17 00:00:00 2001 From: Flugger Date: Sun, 24 Jul 2016 16:43:42 +0200 Subject: [PATCH 002/249] Fix styling --- src/Illuminate/Database/Eloquent/RelationNotFoundException.php | 2 +- tests/Database/DatabaseEloquentBuilderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/RelationNotFoundException.php b/src/Illuminate/Database/Eloquent/RelationNotFoundException.php index 12d037f86356..6541f1cec27b 100755 --- a/src/Illuminate/Database/Eloquent/RelationNotFoundException.php +++ b/src/Illuminate/Database/Eloquent/RelationNotFoundException.php @@ -7,4 +7,4 @@ class RelationNotFoundException extends RuntimeException { // -} \ No newline at end of file +} diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index aaa8a1c0ba81..67dc4d1fe4d7 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -373,7 +373,7 @@ public function testGetRelationThrowsException() $builder = $this->getBuilder(); $builder->setModel($this->getMockModel()); - $builder->getRelation( 'invalid' ); + $builder->getRelation('invalid'); } public function testEagerLoadParsingSetsProperRelationships() From b67e606e348c8d660c14d4798f4b2e6d29b412e7 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 26 Jul 2016 20:43:22 +0100 Subject: [PATCH 003/249] Remove old suggested dependency from support (#14490) --- src/Illuminate/Support/composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Support/composer.json b/src/Illuminate/Support/composer.json index 12be11e2caa6..0e64579f3709 100644 --- a/src/Illuminate/Support/composer.json +++ b/src/Illuminate/Support/composer.json @@ -38,7 +38,6 @@ }, "suggest": { "illuminate/filesystem": "Required to use the composer class (5.2.*).", - "jeremeamia/superclosure": "Required to be able to serialize closures (~2.2).", "symfony/process": "Required to use the composer class (3.1.*).", "symfony/var-dumper": "Required to use the dd function (3.1.*)." }, From 6722e398329e8ddeb7442a43842948bf158890e8 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Tue, 26 Jul 2016 21:43:34 +0200 Subject: [PATCH 004/249] Fix a docblock (#14489) --- src/Illuminate/Auth/RequestGuard.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Auth/RequestGuard.php b/src/Illuminate/Auth/RequestGuard.php index 0d73bd6aef69..e6b9a7e7f73e 100644 --- a/src/Illuminate/Auth/RequestGuard.php +++ b/src/Illuminate/Auth/RequestGuard.php @@ -27,11 +27,10 @@ class RequestGuard implements Guard * Create a new authentication guard. * * @param callable $callback - * @param \Symfony\Component\HttpFoundation\Request $request + * @param \Illuminate\Http\Request $request * @return void */ - public function __construct(callable $callback, - Request $request) + public function __construct(callable $callback, Request $request) { $this->request = $request; $this->callback = $callback; From 678674898f4d9f7d09901228026449b0323a6286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Sj=C3=B6berg?= Date: Tue, 26 Jul 2016 21:46:34 +0200 Subject: [PATCH 005/249] remove the morphclass (#14477) --- src/Illuminate/Database/Eloquent/Model.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index e946d4b81ef9..a414999ff4da 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -182,13 +182,6 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab */ protected $with = []; - /** - * The class name to be used in polymorphic relations. - * - * @var string - */ - protected $morphClass; - /** * Indicates if the model exists. * @@ -2036,7 +2029,7 @@ public function getMorphClass() return array_search($class, $morphMap, true); } - return $this->morphClass ?: $class; + return $class; } /** From 44895e69946044d7396e6073271dfabf62fdab2a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2016 00:29:13 -0400 Subject: [PATCH 006/249] pass notifiable --- src/Illuminate/Foundation/Console/stubs/notification.stub | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/stubs/notification.stub b/src/Illuminate/Foundation/Console/stubs/notification.stub index dce1e296a1c0..66dc9988e372 100644 --- a/src/Illuminate/Foundation/Console/stubs/notification.stub +++ b/src/Illuminate/Foundation/Console/stubs/notification.stub @@ -23,6 +23,7 @@ class DummyClass extends Notification /** * Get the notification channels. * + * @param mixed $notifiable * @return array|string */ public function via($notifiable) @@ -33,9 +34,10 @@ class DummyClass extends Notification /** * Get the notification message. * + * @param mixed $notifiable * @return \Illuminate\Notifications\MessageBuilder */ - public function message() + public function message($notifiable) { return $this->line('The introduction to the notification.') ->action('Notification Action', 'https://laravel.com') From 33be8329fb91a10199cbbea93e1671a6c8bef113 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2016 00:38:34 -0400 Subject: [PATCH 007/249] break down multi lines into single lines on a single line call. --- .../Notifications/Channels/Notification.php | 15 +++++++++++++-- .../NotificationNotificationTest.php | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Notifications/Channels/Notification.php b/src/Illuminate/Notifications/Channels/Notification.php index 600e1d66f907..7962e0343c21 100644 --- a/src/Illuminate/Notifications/Channels/Notification.php +++ b/src/Illuminate/Notifications/Channels/Notification.php @@ -191,14 +191,25 @@ public function with($line) if ($line instanceof Action) { $this->action($line->text, $line->url); } elseif (! $this->actionText) { - $this->introLines[] = trim($line); + $this->introLines[] = $this->formatLine($line); } else { - $this->outroLines[] = trim($line); + $this->outroLines[] = $this->formatLine($line); } return $this; } + /** + * Format the given line of text. + * + * @param string $line + * @return string + */ + protected function formatLine($line) + { + return trim(implode(' ', array_map('trim', explode(PHP_EOL, $line)))); + } + /** * Set the notification's options. * diff --git a/tests/Notifications/NotificationNotificationTest.php b/tests/Notifications/NotificationNotificationTest.php index 1c3f650590b7..cd19e7871168 100644 --- a/tests/Notifications/NotificationNotificationTest.php +++ b/tests/Notifications/NotificationNotificationTest.php @@ -1,6 +1,7 @@ assertInstanceOf('Illuminate\Notifications\MessageBuilder', $notification->line('Something')); } + + public function testChannelNotificationFormatsMultiLineText() + { + $notification = new ChannelNotification([]); + $notification->with(' + This is a + single line of text. + '); + + $this->assertEquals('This is a single line of text.', $notification->introLines[0]); + } } From 0d2bc558884f24ffa366567d96c7c6f7fdeefcf0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2016 00:47:16 -0400 Subject: [PATCH 008/249] fleunt set the notification level --- src/Illuminate/Notifications/Notification.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index 96595fcd9d0a..6de3882c0f5e 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -6,6 +6,13 @@ class Notification { + /** + * The notification priority level. + * + * @var string + */ + protected $level = 'info'; + /** * Get the "level" of the notification. * @@ -13,7 +20,31 @@ class Notification */ public function level() { - return property_exists($this, 'level') ? $this->level : 'info'; + return $this->level; + } + + /** + * Indicate that the notification gives information about a successful operation. + * + * @return $this + */ + public function success() + { + $this->level = 'success'; + + return $this; + } + + /** + * Indicate that the notification gives information about an error. + * + * @return $this + */ + public function error() + { + $this->level = 'error'; + + return $this; } /** From c3169c9ab63e658bc8d97bf717669509834946bd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2016 00:48:50 -0400 Subject: [PATCH 009/249] fluent set the subject --- src/Illuminate/Notifications/Notification.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index 6de3882c0f5e..fc2e98082788 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -13,6 +13,13 @@ class Notification */ protected $level = 'info'; + /** + * The notification's subject. + * + * @var string|null + */ + protected $subject; + /** * Get the "level" of the notification. * @@ -48,15 +55,20 @@ public function error() } /** - * Get the subject of the notification. + * Get or set the subject of the notification. * + * @param string|null $subject * @return string */ - public function subject() + public function subject($subject = null) { - return property_exists($this, 'subject') - ? $this->subject - : Str::title(Str::snake(class_basename($this), ' ')); + if (is_null($subject)) { + return $this->subject ?: Str::title(Str::snake(class_basename($this), ' ')); + } + + $this->subject = $subject; + + return $this; } /** From a16dd5b94c6e0cedbf0696e4f2be9ea3c817ee44 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2016 00:56:35 -0400 Subject: [PATCH 010/249] fix build order --- src/Illuminate/Notifications/Channels/Notification.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Notifications/Channels/Notification.php b/src/Illuminate/Notifications/Channels/Notification.php index 7962e0343c21..3f7da1f023d8 100644 --- a/src/Illuminate/Notifications/Channels/Notification.php +++ b/src/Illuminate/Notifications/Channels/Notification.php @@ -296,16 +296,16 @@ protected static function buildNotification($notifiable, $instance, $channel) { $notification = new static([$notifiable]); - $notification->via($channel) - ->subject($instance->subject()) - ->level($instance->level()); - $method = static::messageMethod($instance, $channel); foreach ($instance->{$method}($notifiable)->elements as $element) { $notification->with($element); } + $notification->via($channel) + ->subject($instance->subject()) + ->level($instance->level()); + $method = static::optionsMethod($instance, $channel); $notification->options($instance->{$method}($notifiable)); From 1614783120bb0e63faf6e4af465ea44ddb0b1532 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2016 11:06:03 -0400 Subject: [PATCH 011/249] allow arrays --- src/Illuminate/Notifications/Channels/Notification.php | 8 ++++++-- tests/Notifications/NotificationNotificationTest.php | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Notifications/Channels/Notification.php b/src/Illuminate/Notifications/Channels/Notification.php index 3f7da1f023d8..97d9891f928e 100644 --- a/src/Illuminate/Notifications/Channels/Notification.php +++ b/src/Illuminate/Notifications/Channels/Notification.php @@ -183,7 +183,7 @@ public function line($line) /** * Add a line of text to the notification. * - * @param \Illuminate\Notifications\Action|string $line + * @param \Illuminate\Notifications\Action|string|array $line * @return $this */ public function with($line) @@ -202,11 +202,15 @@ public function with($line) /** * Format the given line of text. * - * @param string $line + * @param string|array $line * @return string */ protected function formatLine($line) { + if (is_array($line)) { + return implode(' ', array_map('trim', $line)); + } + return trim(implode(' ', array_map('trim', explode(PHP_EOL, $line)))); } diff --git a/tests/Notifications/NotificationNotificationTest.php b/tests/Notifications/NotificationNotificationTest.php index cd19e7871168..18e09eec19b3 100644 --- a/tests/Notifications/NotificationNotificationTest.php +++ b/tests/Notifications/NotificationNotificationTest.php @@ -38,6 +38,14 @@ public function testChannelNotificationFormatsMultiLineText() '); $this->assertEquals('This is a single line of text.', $notification->introLines[0]); + + $notification = new ChannelNotification([]); + $notification->with([ + 'This is a', + 'single line of text.', + ]); + + $this->assertEquals('This is a single line of text.', $notification->introLines[0]); } } From a17f4171c3c9317ad745e91df0c3280f1a2842fe Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2016 11:22:15 -0400 Subject: [PATCH 012/249] allow a few more methods --- .../Notifications/MessageBuilder.php | 60 ++++++++++++++++++- src/Illuminate/Notifications/Notification.php | 2 +- .../NotificationMessageBuilderTest.php | 2 +- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Notifications/MessageBuilder.php b/src/Illuminate/Notifications/MessageBuilder.php index c548a6dcbeae..4bccbaf9cb55 100644 --- a/src/Illuminate/Notifications/MessageBuilder.php +++ b/src/Illuminate/Notifications/MessageBuilder.php @@ -8,6 +8,13 @@ class MessageBuilder { use Macroable; + /** + * The underlying notfication instance. + * + * @var mixed + */ + protected $instance; + /** * All of the message elements. * @@ -18,10 +25,11 @@ class MessageBuilder /** * Create a new message builder instance. * + * @param mixed $instance * @param string $line * @return void */ - public function __construct($line) + public function __construct($instance, $line) { $this->elements[] = $line; } @@ -52,4 +60,54 @@ public function action($text, $url) return $this; } + + /** + * Set the "level" of the notification (success, error, etc.). + * + * @param string $level + * @return $this + */ + public function level($level) + { + $this->instance->level($level); + + return $this; + } + + /** + * Indicate that the notification gives information about a successful operation. + * + * @return $this + */ + public function success() + { + $this->instance->level('success'); + + return $this; + } + + /** + * Indicate that the notification gives information about an error. + * + * @return $this + */ + public function error() + { + $this->instance->level('error'); + + return $this; + } + + /** + * Set the subject of the notification. + * + * @param string $subject + * @return $this + */ + public function subject($subject) + { + $this->instance->subject($subject); + + return $this; + } } diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index fc2e98082788..98e36d23eaf1 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -79,7 +79,7 @@ public function subject($subject = null) */ public function line($line) { - return new MessageBuilder($line); + return new MessageBuilder($this, $line); } /** diff --git a/tests/Notifications/NotificationMessageBuilderTest.php b/tests/Notifications/NotificationMessageBuilderTest.php index d37c2ea9be88..ff3cb58cbdfd 100644 --- a/tests/Notifications/NotificationMessageBuilderTest.php +++ b/tests/Notifications/NotificationMessageBuilderTest.php @@ -6,7 +6,7 @@ class MessageBuilderTest extends PHPUnit_Framework_TestCase { public function testMessageBuilderAddsActionsCorrectly() { - $builder = new MessageBuilder('line 1'); + $builder = new MessageBuilder(new StdClass, 'line 1'); $builder->action('Text', 'url'); $builder->line('line 2'); From a41d646246e0bfb337025215a4e1c91fe1950078 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2016 12:39:53 -0400 Subject: [PATCH 013/249] totally simplify and refactor notifications --- .../Contracts/Notifications/Dispatcher.php | 18 +- .../Console/stubs/notification.stub | 3 +- .../Notifications/ChannelManager.php | 85 ++-- .../Channels/DatabaseChannel.php | 9 +- .../Notifications/Channels/MailChannel.php | 19 +- .../Channels/NexmoSmsChannel.php | 10 +- .../Notifications/Channels/Notification.php | 367 ------------------ .../Channels/SlackWebhookChannel.php | 6 +- .../Notifications/Events/NotificationSent.php | 17 +- .../Notifications/MessageBuilder.php | 113 ------ src/Illuminate/Notifications/Notification.php | 196 ++++++++-- .../Notifications/RoutesNotifications.php | 14 +- .../Notifications/SendQueuedNotifications.php | 28 +- .../NotificationChannelManagerTest.php | 8 +- .../NotificationDatabaseChannelTest.php | 7 +- .../NotificationMailChannelTest.php | 7 +- .../NotificationMessageBuilderTest.php | 18 - .../NotificationNexmoChannelTest.php | 7 +- .../NotificationNotificationTest.php | 25 +- .../NotificationRoutesNotificationsTest.php | 15 +- ...NotificationSendQueuedNotificationTest.php | 4 +- .../NotificationSlackChannelTest.php | 7 +- 22 files changed, 302 insertions(+), 681 deletions(-) delete mode 100644 src/Illuminate/Notifications/Channels/Notification.php delete mode 100644 src/Illuminate/Notifications/MessageBuilder.php delete mode 100644 tests/Notifications/NotificationMessageBuilderTest.php diff --git a/src/Illuminate/Contracts/Notifications/Dispatcher.php b/src/Illuminate/Contracts/Notifications/Dispatcher.php index 17b8d3e9e2cb..696376620cd6 100644 --- a/src/Illuminate/Contracts/Notifications/Dispatcher.php +++ b/src/Illuminate/Contracts/Notifications/Dispatcher.php @@ -4,13 +4,13 @@ interface Dispatcher { - /** - * Dispatch the given notification instance to the given notifiable. - * - * @param mixed $notifiable - * @param mixed $instance - * @param array $channels - * @return void - */ - public function dispatch($notifiable, $instance, array $channels = []); + // * + // * Dispatch the given notification instance to the given notifiable. + // * + // * @param mixed $notifiable + // * @param mixed $instance + // * @param array $channels + // * @return void + + // public function dispatch($notifiable, $instance, array $channels = []); } diff --git a/src/Illuminate/Foundation/Console/stubs/notification.stub b/src/Illuminate/Foundation/Console/stubs/notification.stub index 66dc9988e372..31e2260c8494 100644 --- a/src/Illuminate/Foundation/Console/stubs/notification.stub +++ b/src/Illuminate/Foundation/Console/stubs/notification.stub @@ -34,10 +34,9 @@ class DummyClass extends Notification /** * Get the notification message. * - * @param mixed $notifiable * @return \Illuminate\Notifications\MessageBuilder */ - public function message($notifiable) + public function message() { return $this->line('The introduction to the notification.') ->action('Notification Action', 'https://laravel.com') diff --git a/src/Illuminate/Notifications/ChannelManager.php b/src/Illuminate/Notifications/ChannelManager.php index 20e77c214bb8..c301a31c0219 100644 --- a/src/Illuminate/Notifications/ChannelManager.php +++ b/src/Illuminate/Notifications/ChannelManager.php @@ -22,83 +22,64 @@ class ChannelManager extends Manager implements DispatcherContract, FactoryContr protected $defaultChannels = ['mail', 'database']; /** - * Create a new notification for the given notifiable entities. + * Send the given notification to the given notifiable entities. * - * @param array $notifiables - * @return \Illuminate\Notifications\Channels\Notification + * @param \Illuminate\Support\Collection|array $notifiables + * @param mixed $notification + * @return void */ - public function to($notifiables) + public function send($notifiables, $notification) { - return new Channels\Notification($notifiables); + if ($notification instanceof ShouldQueue) { + return $this->queueNotification($notifiables, $notification); + } + + return $this->sendNow($notifiables, $notification); } /** - * Dispatch the given notification instance to the given notifiable. + * Send the given notification immtediately. * - * @param mixed $notifiable - * @param mixed $instance - * @param array $channels + * @param \Illuminate\Support\Collection|array $notifiables + * @param mixed $notification * @return void */ - public function dispatch($notifiable, $instance, array $channels = []) + public function sendNow($notifiables, $notification) { - $notifications = $this->notificationsFromInstance( - $notifiable, $instance - ); + $notification->message(); - if (count($channels) > 0) { - foreach ($notifications as $notification) { - $notification->via((array) $channels); - } + if (! $notification->application) { + $notification->application( + $this->app['config']['app.name'], + $this->app['config']['app.logo'] + ); } - if ($instance instanceof ShouldQueue) { - return $this->queueNotifications($instance, $notifications); - } + foreach ($notifiables as $notifiable) { + foreach ($notification->via($notifiable) as $channel) { + $this->driver($channel)->send(collect([$notifiable]), $notification); - foreach ($notifications as $notification) { - $this->send($notification); + $this->app->make('events')->fire( + new Events\NotificationSent($notifiable, $notification) + ); + } } } /** * Queue the given notification instances. * - * @param mixed $instance + * @param mixed $notification * @param array[\Illuminate\Notifcations\Channels\Notification] * @return void */ - protected function queueNotifications($instance, array $notifications) + protected function queueNotification($notifiables, $notification) { $this->app->make(Bus::class)->dispatch( - (new SendQueuedNotifications($notifications)) - ->onConnection($instance->connection) - ->onQueue($instance->queue) - ->delay($instance->delay) - ); - } - - /** - * Send the given notification. - * - * @param \Illuminate\Notifications\Channels\Notification $notification - * @return void - */ - public function send(Channels\Notification $notification) - { - if (! $notification->application) { - $notification->application( - $this->app['config']['app.name'], - $this->app['config']['app.logo'] - ); - } - - foreach ($notification->via ?: $this->deliversVia() as $channel) { - $this->driver($channel)->send($notification); - } - - $this->app->make('events')->fire( - new Events\NotificationSent($notification) + (new SendQueuedNotifications($notifiables, $notification)) + ->onConnection($notification->connection) + ->onQueue($notification->queue) + ->delay($notification->delay) ); } diff --git a/src/Illuminate/Notifications/Channels/DatabaseChannel.php b/src/Illuminate/Notifications/Channels/DatabaseChannel.php index 696a5bdbbf88..d449309390cd 100644 --- a/src/Illuminate/Notifications/Channels/DatabaseChannel.php +++ b/src/Illuminate/Notifications/Channels/DatabaseChannel.php @@ -2,17 +2,20 @@ namespace Illuminate\Notifications\Channels; +use Illuminate\Notifications\Notification; + class DatabaseChannel { /** * Send the given notification. * - * @param \Illuminate\Notifications\Channels\Notification $notification + * @param \Illuminate\Support\Collection $notifiables + * @param \Illuminate\Notifications\Notification $notification * @return void */ - public function send(Notification $notification) + public function send($notifiables, Notification $notification) { - foreach ($notification->notifiables as $notifiable) { + foreach ($notifiables as $notifiable) { $notifiable->routeNotificationFor('database')->create([ 'level' => $notification->level, 'intro' => $notification->introLines, diff --git a/src/Illuminate/Notifications/Channels/MailChannel.php b/src/Illuminate/Notifications/Channels/MailChannel.php index 8e54bd7c211b..a4abc2a7a123 100644 --- a/src/Illuminate/Notifications/Channels/MailChannel.php +++ b/src/Illuminate/Notifications/Channels/MailChannel.php @@ -3,7 +3,9 @@ namespace Illuminate\Notifications\Channels; use Illuminate\Support\Arr; +use Illuminate\Support\Str; use Illuminate\Contracts\Mail\Mailer; +use Illuminate\Notifications\Notification; class MailChannel { @@ -28,14 +30,15 @@ public function __construct(Mailer $mailer) /** * Send the given notification. * - * @param \Illuminate\Notifications\Channels\Notification $notification + * @param \Illuminate\Support\Collection $notifiables + * @param \Illuminate\Notifications\Notification $notification * @return void */ - public function send(Notification $notification) + public function send($notifiables, Notification $notification) { $data = $this->prepareNotificationData($notification); - $emails = $notification->notifiables->map(function ($n) { + $emails = $notifiables->map(function ($n) { return $n->routeNotificationFor('mail'); })->filter()->all(); @@ -45,18 +48,20 @@ public function send(Notification $notification) $view = data_get($notification, 'options.view', 'notifications::email'); - $this->mailer->send($view, $data, function ($m) use ($notification, $emails) { - count($notification->notifiables) === 1 + $this->mailer->send($view, $data, function ($m) use ($notifiables, $notification, $emails) { + count($notifiables) === 1 ? $m->to($emails) : $m->bcc($emails); - $m->subject($notification->subject); + $m->subject($notification->subject ?: Str::title( + Str::snake(class_basename($notification), ' ') + )); }); } /** * Prepare the data from the given notification. * - * @param \Illuminate\Notifications\Channels\Notification $notification + * @param \Illuminate\Notifications\Notification $notification * @return array */ protected function prepareNotificationData($notification) diff --git a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php index b3a7ecc92281..7f02332a5a6a 100644 --- a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php +++ b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php @@ -4,6 +4,7 @@ use Illuminate\Support\Arr; use Nexmo\Client as NexmoClient; +use Illuminate\Notifications\Notification; class NexmoSmsChannel { @@ -36,12 +37,13 @@ public function __construct(NexmoClient $nexmo, $from) /** * Send the given notification. * - * @param \Illuminate\Notifications\Channels\Notification $notification + * @param \Illuminate\Support\Collection $notifiables + * @param \Illuminate\Notifications\Notification $notification * @return void */ - public function send(Notification $notification) + public function send($notifiables, Notification $notification) { - foreach ($notification->notifiables as $notifiable) { + foreach ($notifiables as $notifiable) { if (! $to = $notifiable->routeNotificationFor('nexmo')) { continue; } @@ -57,7 +59,7 @@ public function send(Notification $notification) /** * Format the given notification to a single string. * - * @param \Illuminate\Notifications\Channels\Notification $notification + * @param \Illuminate\Notifications\Notification $notification * @return string */ protected function formatNotification(Notification $notification) diff --git a/src/Illuminate/Notifications/Channels/Notification.php b/src/Illuminate/Notifications/Channels/Notification.php deleted file mode 100644 index 97d9891f928e..000000000000 --- a/src/Illuminate/Notifications/Channels/Notification.php +++ /dev/null @@ -1,367 +0,0 @@ -notifiables = Collection::make($notifiables); - } - - /** - * Specify the name of the application sending the notification. - * - * @param string $application - * @param string $logoUrl - * @return $this - */ - public function application($application, $logoUrl = null) - { - $this->application = $application; - $this->logoUrl = $logoUrl; - - return $this; - } - - /** - * Indicate that the notification gives information about a successful operation. - * - * @return $this - */ - public function success() - { - $this->level = 'success'; - - return $this; - } - - /** - * Indicate that the notification gives information about an error. - * - * @return $this - */ - public function error() - { - $this->level = 'error'; - - return $this; - } - - /** - * Set the "level" of the notification (success, error, etc.). - * - * @param string $level - * @return $this - */ - public function level($level) - { - $this->level = $level; - - return $this; - } - - /** - * Set the subject of the notification. - * - * @param string $subject - * @return $this - */ - public function subject($subject) - { - $this->subject = $subject; - - return $this; - } - - /** - * Add a line of text to the notification. - * - * @param \Illuminate\Notifications\Action|string $line - * @return $this - */ - public function line($line) - { - return $this->with($line); - } - - /** - * Add a line of text to the notification. - * - * @param \Illuminate\Notifications\Action|string|array $line - * @return $this - */ - public function with($line) - { - if ($line instanceof Action) { - $this->action($line->text, $line->url); - } elseif (! $this->actionText) { - $this->introLines[] = $this->formatLine($line); - } else { - $this->outroLines[] = $this->formatLine($line); - } - - return $this; - } - - /** - * Format the given line of text. - * - * @param string|array $line - * @return string - */ - protected function formatLine($line) - { - if (is_array($line)) { - return implode(' ', array_map('trim', $line)); - } - - return trim(implode(' ', array_map('trim', explode(PHP_EOL, $line)))); - } - - /** - * Set the notification's options. - * - * @param array $options - * @return $this - */ - public function options(array $options) - { - $this->options = $options; - - return $this; - } - - /** - * Configure the "call to action" button. - * - * @param string $text - * @param string $url - * @return $this - */ - public function action($text, $url) - { - $this->actionText = $text; - $this->actionUrl = $url; - - return $this; - } - - /** - * Set the channels that should be used to deliver the notification. - * - * @param array|string $channels - * @return $this - */ - public function via($channels) - { - $this->via = is_string($channels) ? func_get_args() : (array) $channels; - - return $this; - } - - /** - * Send the notification. - * - * @return void - */ - public function send() - { - return Container::getInstance()->make(ChannelManager::class)->send($this); - } - - /** - * Build new channel notifications from the given object. - * - * @param mixed $notifiable - * @param mixed $instance - * @param array|null $channels - * @return array[static] - */ - public static function notificationsFromInstance($notifiable, $instance, $channels = null) - { - $notifications = []; - - $channels = $channels ?: $instance->via($notifiable); - - $channels = $channels ?: app(ChannelManager::class)->deliversVia(); - - foreach ($channels as $channel) { - $notifications[] = static::buildNotification($notifiable, $instance, $channel); - } - - return $notifications; - } - - /** - * Build a new channel notification. - * - * @param mixed $notifiable - * @param mixed $instance - * @param string $channel - * @return static - */ - protected static function buildNotification($notifiable, $instance, $channel) - { - $notification = new static([$notifiable]); - - $method = static::messageMethod($instance, $channel); - - foreach ($instance->{$method}($notifiable)->elements as $element) { - $notification->with($element); - } - - $notification->via($channel) - ->subject($instance->subject()) - ->level($instance->level()); - - $method = static::optionsMethod($instance, $channel); - - $notification->options($instance->{$method}($notifiable)); - - return $notification; - } - - /** - * Get the proper message method for the given instance and channel. - * - * @param mixed $instance - * @param string $channel - * @return string - */ - protected static function messageMethod($instance, $channel) - { - return method_exists( - $instance, $channelMethod = Str::camel($channel).'Message' - ) ? $channelMethod : 'message'; - } - - /** - * Get the proper data method for the given instance and channel. - * - * @param mixed $instance - * @param string $channel - * @return string - */ - protected static function optionsMethod($instance, $channel) - { - return method_exists( - $instance, $channelMethod = Str::camel($channel).'Options' - ) ? $channelMethod : 'options'; - } - - /** - * Get the instance as an array. - * - * @return array - */ - public function toArray() - { - return [ - 'notifiables' => $this->notifiables, - 'application' => $this->application, - 'logoUrl' => $this->logoUrl, - 'level' => $this->level, - 'subject' => $this->subject, - 'introLines' => $this->introLines, - 'outroLines' => $this->outroLines, - 'actionText' => $this->actionText, - 'actionUrl' => $this->actionUrl, - ]; - } -} diff --git a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php index 4e68e904842f..f2eb6217f263 100644 --- a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php +++ b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php @@ -3,6 +3,7 @@ namespace Illuminate\Notifications\Channels; use GuzzleHttp\Client as HttpClient; +use Illuminate\Notifications\Notification; class SlackWebhookChannel { @@ -27,12 +28,13 @@ public function __construct(HttpClient $http) /** * Send the given notification. * + * @param \Illuminate\Support\Collection $notifiables * @param \Illuminate\Notifications\Channels\Notification $notification * @return void */ - public function send(Notification $notification) + public function send($notifiables, Notification $notification) { - foreach ($notification->notifiables as $notifiable) { + foreach ($notifiables as $notifiable) { if (! $url = $notifiable->routeNotificationFor('slack')) { continue; } diff --git a/src/Illuminate/Notifications/Events/NotificationSent.php b/src/Illuminate/Notifications/Events/NotificationSent.php index 1361f1ad6764..d27388e39c2e 100644 --- a/src/Illuminate/Notifications/Events/NotificationSent.php +++ b/src/Illuminate/Notifications/Events/NotificationSent.php @@ -2,25 +2,34 @@ namespace Illuminate\Notifications\Events; -use Illuminate\Notifications\Channels\Notification; +use Illuminate\Notifications\Notification; class NotificationSent { + /** + * The notifiable entity who received the notification. + * + * @var mixed + */ + public $notifiable; + /** * The notification instance. * - * @var \Illuminate\Notifications\Channels\Notification + * @var \Illuminate\Notifications\Notification */ public $notification; /** * Create a new event instance. * - * @param \Illuminate\Notifications\Channels\Notification $notification + * @param mixed $notifiable + * @param \Illuminate\Notifications\Notification $notification * @return void */ - public function __construct(Notification $notification) + public function __construct($notifiable, $notification) { + $this->notifiable = $notifiable; $this->notification = $notification; } } diff --git a/src/Illuminate/Notifications/MessageBuilder.php b/src/Illuminate/Notifications/MessageBuilder.php deleted file mode 100644 index 4bccbaf9cb55..000000000000 --- a/src/Illuminate/Notifications/MessageBuilder.php +++ /dev/null @@ -1,113 +0,0 @@ -elements[] = $line; - } - - /** - * Add a line to the message. - * - * @param string $line - * @return $this - */ - public function line($line) - { - $this->elements[] = $line; - - return $this; - } - - /** - * Add an action to the message. - * - * @param string $text - * @param string $url - * @return $this - */ - public function action($text, $url) - { - $this->elements[] = new Action($text, $url); - - return $this; - } - - /** - * Set the "level" of the notification (success, error, etc.). - * - * @param string $level - * @return $this - */ - public function level($level) - { - $this->instance->level($level); - - return $this; - } - - /** - * Indicate that the notification gives information about a successful operation. - * - * @return $this - */ - public function success() - { - $this->instance->level('success'); - - return $this; - } - - /** - * Indicate that the notification gives information about an error. - * - * @return $this - */ - public function error() - { - $this->instance->level('error'); - - return $this; - } - - /** - * Set the subject of the notification. - * - * @param string $subject - * @return $this - */ - public function subject($subject) - { - $this->instance->subject($subject); - - return $this; - } -} diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index 98e36d23eaf1..d44166b44386 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -3,31 +3,100 @@ namespace Illuminate\Notifications; use Illuminate\Support\Str; +use Illuminate\Queue\SerializesModels; class Notification { + use SerializesModels; + + /** + * The entities that should receive the notification. + * + * @var \Illuminate\Support\Collection + */ + public $notifiables; + + /** + * The channels that the notification should be sent through. + */ + public $via = []; + /** - * The notification priority level. + * The name of the application sending the notification. * * @var string */ - protected $level = 'info'; + public $application; /** - * The notification's subject. + * The URL to the application's logo. * - * @var string|null + * @var string */ - protected $subject; + public $logoUrl; /** - * Get the "level" of the notification. + * The "level" of the notification (info, success, error). * - * @return string + * @var string + */ + public $level = 'info'; + + /** + * The subject of the notification. + * + * @var string + */ + public $subject; + + /** + * The "intro" lines of the notification. + * + * @var array + */ + public $introLines = []; + + /** + * The "outro" lines of the notification. + * + * @var array */ - public function level() + public $outroLines = []; + + /** + * The text / label for the action. + * + * @var string + */ + public $actionText; + + /** + * The action URL. + * + * @var string + */ + public $actionUrl; + + /** + * The notification's options. + * + * @var array + */ + public $options = []; + + /** + * Specify the name of the application sending the notification. + * + * @param string $application + * @param string $logoUrl + * @return $this + */ + public function application($application, $logoUrl = null) { - return $this->level; + $this->application = $application; + $this->logoUrl = $logoUrl; + + return $this; } /** @@ -55,40 +124,121 @@ public function error() } /** - * Get or set the subject of the notification. + * Set the "level" of the notification (success, error, etc.). * - * @param string|null $subject - * @return string + * @param string $level + * @return $this */ - public function subject($subject = null) + public function level($level) { - if (is_null($subject)) { - return $this->subject ?: Str::title(Str::snake(class_basename($this), ' ')); - } + $this->level = $level; + + return $this; + } + /** + * Set the subject of the notification. + * + * @param string $subject + * @return $this + */ + public function subject($subject) + { $this->subject = $subject; return $this; } /** - * Create a new message builder instance. + * Add a line of text to the notification. * - * @param string $line - * @return \Illuminate\Notifications\MessageBuilder + * @param \Illuminate\Notifications\Action|string $line + * @return $this */ public function line($line) { - return new MessageBuilder($this, $line); + return $this->with($line); + } + + /** + * Add a line of text to the notification. + * + * @param \Illuminate\Notifications\Action|string|array $line + * @return $this + */ + public function with($line) + { + if ($line instanceof Action) { + $this->action($line->text, $line->url); + } elseif (! $this->actionText) { + $this->introLines[] = $this->formatLine($line); + } else { + $this->outroLines[] = $this->formatLine($line); + } + + return $this; + } + + /** + * Format the given line of text. + * + * @param string|array $line + * @return string + */ + protected function formatLine($line) + { + if (is_array($line)) { + return implode(' ', array_map('trim', $line)); + } + + return trim(implode(' ', array_map('trim', explode(PHP_EOL, $line)))); + } + + /** + * Set the notification's options. + * + * @param array $options + * @return $this + */ + public function options(array $options) + { + $this->options = $options; + + return $this; + } + + /** + * Configure the "call to action" button. + * + * @param string $text + * @param string $url + * @return $this + */ + public function action($text, $url) + { + $this->actionText = $text; + $this->actionUrl = $url; + + return $this; } /** - * Get the notification's options. + * Get the instance as an array. * * @return array */ - public function options() + public function toArray() { - return property_exists($this, 'options') ? $this->options : []; + return [ + 'notifiables' => $this->notifiables, + 'application' => $this->application, + 'logoUrl' => $this->logoUrl, + 'level' => $this->level, + 'subject' => $this->subject, + 'introLines' => $this->introLines, + 'outroLines' => $this->outroLines, + 'actionText' => $this->actionText, + 'actionUrl' => $this->actionUrl, + ]; } } diff --git a/src/Illuminate/Notifications/RoutesNotifications.php b/src/Illuminate/Notifications/RoutesNotifications.php index 9619ad3d7eb5..f73cdffc1571 100644 --- a/src/Illuminate/Notifications/RoutesNotifications.php +++ b/src/Illuminate/Notifications/RoutesNotifications.php @@ -15,19 +15,7 @@ trait RoutesNotifications */ public function notify($instance) { - app(Dispatcher::class)->dispatch($this, $instance); - } - - /** - * Send the given notification via the given channels. - * - * @param array|string $channels - * @param mixed $instance - * @return void - */ - public function notifyVia($channels, $instance) - { - app(Dispatcher::class)->dispatch($this, $instance, $channels); + app(Dispatcher::class)->send([$this], $instance); } /** diff --git a/src/Illuminate/Notifications/SendQueuedNotifications.php b/src/Illuminate/Notifications/SendQueuedNotifications.php index deab7c803128..c829bec7f487 100644 --- a/src/Illuminate/Notifications/SendQueuedNotifications.php +++ b/src/Illuminate/Notifications/SendQueuedNotifications.php @@ -3,28 +3,38 @@ namespace Illuminate\Notifications; use Illuminate\Bus\Queueable; +use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; class SendQueuedNotifications implements ShouldQueue { - use Queueable; + use Queueable, SerializesModels; /** - * The notifications to be sent. + * The notifiable entities that should receive the notification. * - * @var array + * @var \Illuminate\Support\Collection */ - protected $notifications; + protected $notifiables; + + /** + * The notification to be sent. + * + * @var \Illuminate\Notifications\Notification + */ + protected $notification; /** * Create a new job instance. * - * @param array[\Illuminate\Notifications\Channels\Notification] $notifications + * @param \Illuminate\Support\Collection $notifiables + * @param \Illuminate\Notifications\Notification $notification * @return void */ - public function __construct(array $notifications) + public function __construct($notifiables, $notification) { - $this->notifications = $notifications; + $this->notifiables = $notifiables; + $this->notification = $notification; } /** @@ -35,8 +45,6 @@ public function __construct(array $notifications) */ public function handle(ChannelManager $manager) { - foreach ($this->notifications as $notification) { - $manager->send($notification); - } + $manager->sendNow($this->notifiables, $this->notification); } } diff --git a/tests/Notifications/NotificationChannelManagerTest.php b/tests/Notifications/NotificationChannelManagerTest.php index 6d4e4157dd8a..79540f5bfd13 100644 --- a/tests/Notifications/NotificationChannelManagerTest.php +++ b/tests/Notifications/NotificationChannelManagerTest.php @@ -20,18 +20,16 @@ public function testNotificationCanBeDispatchedToDriver() Container::setInstance($container); $manager = Mockery::mock(ChannelManager::class.'[driver]', [$container]); $manager->shouldReceive('driver')->andReturn($driver = Mockery::mock()); - $driver->shouldReceive('send')->andReturnUsing(function ($notification) { + $driver->shouldReceive('send')->andReturnUsing(function ($notifiables, $notification) { $this->assertEquals('Name', $notification->application); $this->assertEquals('Logo', $notification->logoUrl); - $this->assertEquals(['test'], $notification->via); - $this->assertEquals('Notification Channel Manager Test Notification', $notification->subject); $this->assertEquals('test', $notification->introLines[0]); $this->assertEquals('Text', $notification->actionText); $this->assertEquals('url', $notification->actionUrl); }); $events->shouldReceive('fire')->with(Mockery::type(Illuminate\Notifications\Events\NotificationSent::class)); - $manager->dispatch(new NotificationChannelManagerTestNotifiable, new NotificationChannelManagerTestNotification); + $manager->send([new NotificationChannelManagerTestNotifiable], new NotificationChannelManagerTestNotification); } public function testNotificationCanBeQueued() @@ -43,7 +41,7 @@ public function testNotificationCanBeQueued() Container::setInstance($container); $manager = Mockery::mock(ChannelManager::class.'[driver]', [$container]); - $manager->dispatch(new NotificationChannelManagerTestNotifiable, new NotificationChannelManagerTestQueuedNotification); + $manager->send([new NotificationChannelManagerTestNotifiable], new NotificationChannelManagerTestQueuedNotification); } } diff --git a/tests/Notifications/NotificationDatabaseChannelTest.php b/tests/Notifications/NotificationDatabaseChannelTest.php index 07a8f28bb9db..e0aec2e9b9a6 100644 --- a/tests/Notifications/NotificationDatabaseChannelTest.php +++ b/tests/Notifications/NotificationDatabaseChannelTest.php @@ -1,6 +1,6 @@ notifiables = collect([$notifiable = Mockery::mock()]); $notifiable->shouldReceive('routeNotificationFor->create')->with([ 'level' => 'info', diff --git a/tests/Notifications/NotificationMailChannelTest.php b/tests/Notifications/NotificationMailChannelTest.php index da50ec494159..ee80bbda0aba 100644 --- a/tests/Notifications/NotificationMailChannelTest.php +++ b/tests/Notifications/NotificationMailChannelTest.php @@ -1,6 +1,6 @@ shouldReceive('send')->with('notifications::email', $array, Mockery::type('Closure')); - $channel->send($notification); + $channel->send($notifiables, $notification); } } diff --git a/tests/Notifications/NotificationMessageBuilderTest.php b/tests/Notifications/NotificationMessageBuilderTest.php deleted file mode 100644 index ff3cb58cbdfd..000000000000 --- a/tests/Notifications/NotificationMessageBuilderTest.php +++ /dev/null @@ -1,18 +0,0 @@ -action('Text', 'url'); - $builder->line('line 2'); - - $this->assertEquals('line 1', $builder->elements[0]); - $this->assertEquals('Text', $builder->elements[1]->text); - $this->assertEquals('url', $builder->elements[1]->url); - $this->assertEquals('line 2', $builder->elements[2]); - } -} diff --git a/tests/Notifications/NotificationNexmoChannelTest.php b/tests/Notifications/NotificationNexmoChannelTest.php index cf06bf230098..15e4d16bdce5 100644 --- a/tests/Notifications/NotificationNexmoChannelTest.php +++ b/tests/Notifications/NotificationNexmoChannelTest.php @@ -1,6 +1,6 @@ send($notification); + $channel->send($notifiables, $notification); } } diff --git a/tests/Notifications/NotificationNotificationTest.php b/tests/Notifications/NotificationNotificationTest.php index 18e09eec19b3..18aaf88530d3 100644 --- a/tests/Notifications/NotificationNotificationTest.php +++ b/tests/Notifications/NotificationNotificationTest.php @@ -1,37 +1,22 @@ assertEquals('info', $notification->level()); + $this->assertEquals('info', $notification->level); $notification = new NotificationTestNotification; - $this->assertEquals('error', $notification->level()); - } - - public function testSubjectCanBeRetrieved() - { - $notification = new NotificationTestNotification; - $this->assertEquals('Notification Test Notification', $notification->subject()); - - $notification = new NotificationTestNotificationWithSubject; - $this->assertEquals('Zonda', $notification->subject()); - } - - public function testMessageBuilderCanBeRetrieved() - { - $notification = new Notification; - $this->assertInstanceOf('Illuminate\Notifications\MessageBuilder', $notification->line('Something')); + $notification->level('error'); + $this->assertEquals('error', $notification->level); } public function testChannelNotificationFormatsMultiLineText() { - $notification = new ChannelNotification([]); + $notification = new Notification([]); $notification->with(' This is a single line of text. @@ -39,7 +24,7 @@ public function testChannelNotificationFormatsMultiLineText() $this->assertEquals('This is a single line of text.', $notification->introLines[0]); - $notification = new ChannelNotification([]); + $notification = new Notification([]); $notification->with([ 'This is a', 'single line of text.', diff --git a/tests/Notifications/NotificationRoutesNotificationsTest.php b/tests/Notifications/NotificationRoutesNotificationsTest.php index f8740a430365..199b2bf8063e 100644 --- a/tests/Notifications/NotificationRoutesNotificationsTest.php +++ b/tests/Notifications/NotificationRoutesNotificationsTest.php @@ -17,25 +17,12 @@ public function testNotificationCanBeDispatched() $container->instance(Dispatcher::class, $factory); $notifiable = new RoutesNotificationsTestInstance; $instance = new StdClass; - $factory->shouldReceive('dispatch')->with($notifiable, $instance); + $factory->shouldReceive('send')->with([$notifiable], $instance); Container::setInstance($container); $notifiable->notify($instance); } - public function testNotificationCanBeDispatchedToGivenChannels() - { - $container = new Container; - $factory = Mockery::mock(Dispatcher::class); - $container->instance(Dispatcher::class, $factory); - $notifiable = new RoutesNotificationsTestInstance; - $instance = new StdClass; - $factory->shouldReceive('dispatch')->with($notifiable, $instance, ['channel']); - Container::setInstance($container); - - $notifiable->notifyVia(['channel'], $instance); - } - public function testNotificationOptionRouting() { $instance = new RoutesNotificationsTestInstance; diff --git a/tests/Notifications/NotificationSendQueuedNotificationTest.php b/tests/Notifications/NotificationSendQueuedNotificationTest.php index 63eea35f74e1..9991cdc04d6d 100644 --- a/tests/Notifications/NotificationSendQueuedNotificationTest.php +++ b/tests/Notifications/NotificationSendQueuedNotificationTest.php @@ -11,9 +11,9 @@ public function tearDown() public function testNotificationsCanBeSent() { - $job = new SendQueuedNotifications([$notification = new Illuminate\Notifications\Channels\Notification([])]); + $job = new SendQueuedNotifications('notifiables', 'notification'); $manager = Mockery::mock('Illuminate\Notifications\ChannelManager'); - $manager->shouldReceive('send')->once()->with($notification); + $manager->shouldReceive('sendNow')->once()->with('notifiables', 'notification'); $job->handle($manager); } } diff --git a/tests/Notifications/NotificationSlackChannelTest.php b/tests/Notifications/NotificationSlackChannelTest.php index 74bb956d7a95..4b961c27f9ab 100644 --- a/tests/Notifications/NotificationSlackChannelTest.php +++ b/tests/Notifications/NotificationSlackChannelTest.php @@ -1,6 +1,6 @@ send($notification); + $channel->send($notifiables, $notification); } } From c9e28f3bbfe77e1ab1f36811c54909b44cd7723e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2016 12:40:26 -0400 Subject: [PATCH 014/249] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Illuminate/Notifications/Notification.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index d44166b44386..f842aec0a462 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -2,7 +2,6 @@ namespace Illuminate\Notifications; -use Illuminate\Support\Str; use Illuminate\Queue\SerializesModels; class Notification From bb8dc89ad15d06dab29f0dca023f3cfca41dcb13 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 27 Jul 2016 12:41:44 -0400 Subject: [PATCH 015/249] tweak stub --- src/Illuminate/Foundation/Console/stubs/notification.stub | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Foundation/Console/stubs/notification.stub b/src/Illuminate/Foundation/Console/stubs/notification.stub index 31e2260c8494..db6800c1c4f8 100644 --- a/src/Illuminate/Foundation/Console/stubs/notification.stub +++ b/src/Illuminate/Foundation/Console/stubs/notification.stub @@ -34,12 +34,12 @@ class DummyClass extends Notification /** * Get the notification message. * - * @return \Illuminate\Notifications\MessageBuilder + * @return void */ public function message() { - return $this->line('The introduction to the notification.') - ->action('Notification Action', 'https://laravel.com') - ->line('Thank you for using our application!'); + $this->line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); } } From 01cf6b22f65564171a2d3da0425316f2a934d8bc Mon Sep 17 00:00:00 2001 From: danilcha Date: Thu, 28 Jul 2016 06:14:34 +0300 Subject: [PATCH 016/249] Fix #14506 (#14510) Shorten too broad PhpDoc @return tag from `@return \Illuminate\Database\Query\Builder|static` to `@return \Illuminate\Database\Query\Builder`. --- src/Illuminate/Database/Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index ead238056f49..a35c52cba0a3 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1292,7 +1292,7 @@ protected function nestWhereSlice($whereSlice, $boolean = 'and') /** * Get the underlying query builder instance. * - * @return \Illuminate\Database\Query\Builder|static + * @return \Illuminate\Database\Query\Builder */ public function getQuery() { From f134d3d0057b49e8ba6552d45602e07376172f39 Mon Sep 17 00:00:00 2001 From: Saeed Prez Date: Thu, 28 Jul 2016 05:17:26 +0200 Subject: [PATCH 017/249] [5.2] Update Str::plural() to use intval() (#14502) * Update Str::plural() to use intval() A lot of the time when you use str_plural() you get the $count value from a form request which returns the number as a string and therefore this plural won't work as expected. This small change should make sure the $count is in integer format. Thanks to @barryvdh for suggesting to do this change deeper in the code. * Changed to type casting Using `(int) $count` instead of `intval($count)` as requested. --- src/Illuminate/Support/Pluralizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Pluralizer.php b/src/Illuminate/Support/Pluralizer.php index f95b99d85d8b..82f8d6e96783 100755 --- a/src/Illuminate/Support/Pluralizer.php +++ b/src/Illuminate/Support/Pluralizer.php @@ -50,7 +50,7 @@ class Pluralizer */ public static function plural($value, $count = 2) { - if ($count === 1 || static::uncountable($value)) { + if ((int) $count === 1 || static::uncountable($value)) { return $value; } From 4444f546474ff284dc9b839fa309fb68d05123d5 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 27 Jul 2016 23:20:51 -0400 Subject: [PATCH 018/249] Added resolveName to the job contract (#14513) --- src/Illuminate/Contracts/Queue/Job.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Illuminate/Contracts/Queue/Job.php b/src/Illuminate/Contracts/Queue/Job.php index 50d849dd2740..577b75e0c8f9 100644 --- a/src/Illuminate/Contracts/Queue/Job.php +++ b/src/Illuminate/Contracts/Queue/Job.php @@ -54,6 +54,13 @@ public function attempts(); */ public function getName(); + /** + * Get the resolved name of the queued job class. + * + * @return string + */ + public function resolveName(); + /** * Call the failed method on the job instance. * From d2e55f0ba62a37785bbd22756172edbd5e844261 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 28 Jul 2016 09:41:09 -0400 Subject: [PATCH 019/249] [5.3] Introduce a timeout exception for the queue (#14519) * Introduce a timeout exception for the queue * Make sure the timeout variable is available --- src/Illuminate/Queue/TimeoutException.php | 10 ++++++++++ src/Illuminate/Queue/Worker.php | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/Illuminate/Queue/TimeoutException.php diff --git a/src/Illuminate/Queue/TimeoutException.php b/src/Illuminate/Queue/TimeoutException.php new file mode 100644 index 000000000000..1fe5e1e57985 --- /dev/null +++ b/src/Illuminate/Queue/TimeoutException.php @@ -0,0 +1,10 @@ +exceptions->report(new Exception('Queue child process timed out.')); + $this->exceptions->report(new TimeoutException("Queue child process timed out after {$timeout} seconds.")); }, true); pcntl_alarm($timeout); From b35360c102871e0c48e78ea14cffa011355f4027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AE=A1=E5=AE=9C=E5=B0=A7?= Date: Thu, 28 Jul 2016 21:41:35 +0800 Subject: [PATCH 020/249] Remove duplicate interface implementation (#14515) Because the interface `QueueingDispatcher` inherits from the interface `Illuminate\Contracts\Bus\Dispatcher`, there is no need to implement the interface `Illuminate\Contracts\Bus\Dispatcher` again. --- src/Illuminate/Bus/Dispatcher.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Illuminate/Bus/Dispatcher.php b/src/Illuminate/Bus/Dispatcher.php index 6c87a4a66e2c..70e9b67e2485 100644 --- a/src/Illuminate/Bus/Dispatcher.php +++ b/src/Illuminate/Bus/Dispatcher.php @@ -9,9 +9,8 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Container\Container; use Illuminate\Contracts\Bus\QueueingDispatcher; -use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract; -class Dispatcher implements DispatcherContract, QueueingDispatcher +class Dispatcher implements QueueingDispatcher { /** * The container implementation. From 8226c8512d352900e8d154a70b0b9a9eedd5d711 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 28 Jul 2016 11:55:06 -0400 Subject: [PATCH 021/249] single event for notification per notifiable --- src/Illuminate/Notifications/ChannelManager.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Notifications/ChannelManager.php b/src/Illuminate/Notifications/ChannelManager.php index c301a31c0219..d630c56b2ffb 100644 --- a/src/Illuminate/Notifications/ChannelManager.php +++ b/src/Illuminate/Notifications/ChannelManager.php @@ -56,12 +56,18 @@ public function sendNow($notifiables, $notification) } foreach ($notifiables as $notifiable) { - foreach ($notification->via($notifiable) as $channel) { - $this->driver($channel)->send(collect([$notifiable]), $notification); + $channels = $notification->via($notifiable); + + if (empty($channels)) { + continue; + } - $this->app->make('events')->fire( - new Events\NotificationSent($notifiable, $notification) - ); + $this->app->make('events')->fire( + new Events\NotificationSent($notifiable, $notification) + ); + + foreach ($channels as $channel) { + $this->driver($channel)->send(collect([$notifiable]), $notification); } } } From c6298db6a791faf00392b8c317e5d40c39be80c4 Mon Sep 17 00:00:00 2001 From: John Paul Medina Date: Thu, 28 Jul 2016 16:54:27 -0400 Subject: [PATCH 022/249] Add where time support query --- src/Illuminate/Database/Query/Builder.php | 28 ++++++++++++++++++- .../Database/Query/Grammars/Grammar.php | 12 ++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 42e7c810d6c2..5681a0094876 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1078,6 +1078,32 @@ public function orWhereDate($column, $operator, $value) return $this->whereDate($column, $operator, $value, 'or'); } + /** + * Add a "where time" statement to the query. + * + * @param string $column + * @param string $operator + * @param int $value + * @param string $boolean + * @return \Illuminate\Database\Query\Builder|static + */ + public function whereTime($column, $operator, $value, $boolean = 'and') + { + return $this->addDateBasedWhere('Time', $column, $operator, $value, $boolean); + } + /** + * Add an "or where time" statement to the query. + * + * @param string $column + * @param string $operator + * @param int $value + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereTime($column, $operator, $value) + { + return $this->whereTime($column, $operator, $value, 'or'); + } + /** * Add a "where day" statement to the query. * @@ -1133,7 +1159,7 @@ public function whereYear($column, $operator, $value = null, $boolean = 'and') } /** - * Add a date based (year, month, day) statement to the query. + * Add a date based (year, month, day, time) statement to the query. * * @param string $type * @param string $column diff --git a/src/Illuminate/Database/Query/Grammars/Grammar.php b/src/Illuminate/Database/Query/Grammars/Grammar.php index e51e6ec4047a..47beabc26398 100755 --- a/src/Illuminate/Database/Query/Grammars/Grammar.php +++ b/src/Illuminate/Database/Query/Grammars/Grammar.php @@ -389,6 +389,18 @@ protected function whereDate(Builder $query, $where) return $this->dateBasedWhere('date', $query, $where); } + /** + * Compile a "where time" clause. + * + * @param \Illuminate\Database\Query\Builder $query + * @param array $where + * @return string + */ + protected function whereTime(Builder $query, $where) + { + return $this->dateBasedWhere('time', $query, $where); + } + /** * Compile a "where day" clause. * From 5af14a6d10fa146770386a674bfafc9e71ec528f Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Fri, 29 Jul 2016 01:02:15 -0300 Subject: [PATCH 023/249] [5.3] Arr::where() - Simplifies and makes it faster (#14530) --- src/Illuminate/Support/Arr.php | 10 +--------- tests/Support/SupportArrTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Support/Arr.php b/src/Illuminate/Support/Arr.php index 074f48ff232a..77378766e61c 100755 --- a/src/Illuminate/Support/Arr.php +++ b/src/Illuminate/Support/Arr.php @@ -485,14 +485,6 @@ public static function sortRecursive($array) */ public static function where($array, callable $callback) { - $filtered = []; - - foreach ($array as $key => $value) { - if (call_user_func($callback, $value, $key)) { - $filtered[$key] = $value; - } - } - - return $filtered; + return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH); } } diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index 68ca2ba798bd..14bc7c6b93cd 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -426,6 +426,17 @@ public function testWhere() $this->assertEquals([1 => 200, 3 => 400], $array); } + public function testWhereKey() + { + $array = ['10' => 1, 'foo' => 3, 20 => 2]; + + $array = Arr::where($array, function ($value, $key) { + return is_numeric($key); + }); + + $this->assertEquals(['10' => 1, 20 => 2], $array); + } + public function testForget() { $array = ['products' => ['desk' => ['price' => 100]]]; From 0542a9a2903c0fb922905c761836d3bdfae5b40f Mon Sep 17 00:00:00 2001 From: Jordan Hoff Date: Fri, 29 Jul 2016 00:02:31 -0400 Subject: [PATCH 024/249] Unit tests for Collection::slice (#14529) --- tests/Support/SupportCollectionTest.php | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index de893a7430bd..5cbe300db0c0 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1421,6 +1421,42 @@ public function testWithMultipleModeValues() $collection = new Collection([1, 2, 2, 1]); $this->assertEquals([1, 2], $collection->mode()); } + + public function testSliceOffset() + { + $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]); + $this->assertEquals([4, 5, 6, 7, 8], $collection->slice(3)->values()->toArray()); + } + + public function testSliceNegativeOffset() + { + $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]); + $this->assertEquals([6, 7, 8], $collection->slice(-3)->values()->toArray()); + } + + public function testSliceOffsetAndLength() + { + $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]); + $this->assertEquals([4, 5, 6], $collection->slice(3, 3)->values()->toArray()); + } + + public function testSliceOffsetAndNegativeLength() + { + $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]); + $this->assertEquals([4, 5, 6, 7], $collection->slice(3, -1)->values()->toArray()); + } + + public function testSliceNegativeOffsetAndLength() + { + $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]); + $this->assertEquals([4, 5, 6], $collection->slice(-5, 3)->values()->toArray()); + } + + public function testSliceNegativeOffsetAndNegativeLength() + { + $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]); + $this->assertEquals([3, 4, 5, 6], $collection->slice(-6, -2)->values()->toArray()); + } } class TestAccessorEloquentTestStub From 0baed0638d020dbd3e7a310881e8a7c4749c055e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gonz=C3=A1lez?= Date: Fri, 29 Jul 2016 00:03:54 -0400 Subject: [PATCH 025/249] Fix pokemon plural form (#14525) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As with the words deer and sheep, the singular and plural forms of the word "Pokémon" do not differ, nor does each individual species name; in short, it is grammatically correct to say both "one Pokémon" and "many Pokémon" --- src/Illuminate/Support/Pluralizer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Support/Pluralizer.php b/src/Illuminate/Support/Pluralizer.php index 82f8d6e96783..871257226add 100755 --- a/src/Illuminate/Support/Pluralizer.php +++ b/src/Illuminate/Support/Pluralizer.php @@ -32,6 +32,7 @@ class Pluralizer 'nutrition', 'offspring', 'plankton', + 'pokemon', 'police', 'rice', 'series', From 77651826a973924aa25e052d9a97846f2ff5a0f6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 29 Jul 2016 00:05:38 -0400 Subject: [PATCH 026/249] just test on php --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 20d73d042e04..37a59740861d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ language: php php: - 5.6 - 7.0 - - hhvm env: global: From b6682c01e6a323799dc0539bc7572ceae7b44086 Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Fri, 29 Jul 2016 01:19:50 -0300 Subject: [PATCH 027/249] [5.3] URL Generator - Call array_filter directly (#14531) Looks good to me. --- src/Illuminate/Routing/UrlGenerator.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Routing/UrlGenerator.php b/src/Illuminate/Routing/UrlGenerator.php index 5154dcd9bec7..a56af31be4d8 100755 --- a/src/Illuminate/Routing/UrlGenerator.php +++ b/src/Illuminate/Routing/UrlGenerator.php @@ -483,9 +483,7 @@ protected function getRouteQueryString(array $parameters) */ protected function getStringParameters(array $parameters) { - return Arr::where($parameters, function ($v, $k) { - return is_string($k); - }); + return array_filter($parameters, 'is_string', ARRAY_FILTER_USE_KEY); } /** @@ -496,9 +494,7 @@ protected function getStringParameters(array $parameters) */ protected function getNumericParameters(array $parameters) { - return Arr::where($parameters, function ($v, $k) { - return is_numeric($k); - }); + return array_filter($parameters, 'is_numeric', ARRAY_FILTER_USE_KEY); } /** From d3242a1ac6abe264fe6368ddd62d81fdd2fbb0f6 Mon Sep 17 00:00:00 2001 From: Jordan Hoff Date: Fri, 29 Jul 2016 09:42:55 -0400 Subject: [PATCH 028/249] Cron rules should be commutative (#14534) --- src/Illuminate/Console/Scheduling/Event.php | 31 ++++++++++++++------- tests/Console/ConsoleScheduledEventTest.php | 19 +++++++++++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/Event.php b/src/Illuminate/Console/Scheduling/Event.php index ae10b0aa3311..1971d2a40ab3 100644 --- a/src/Illuminate/Console/Scheduling/Event.php +++ b/src/Illuminate/Console/Scheduling/Event.php @@ -341,7 +341,7 @@ public function cron($expression) */ public function hourly() { - return $this->cron('0 * * * * *'); + return $this->spliceIntoPosition(1, 0); } /** @@ -351,7 +351,8 @@ public function hourly() */ public function daily() { - return $this->cron('0 0 * * * *'); + return $this->spliceIntoPosition(1, 0) + ->spliceIntoPosition(2, 0); } /** @@ -481,7 +482,9 @@ public function sundays() */ public function weekly() { - return $this->cron('0 0 * * 0 *'); + return $this->spliceIntoPosition(1, 0) + ->spliceIntoPosition(2, 0) + ->spliceIntoPosition(5, 0); } /** @@ -505,7 +508,9 @@ public function weeklyOn($day, $time = '0:0') */ public function monthly() { - return $this->cron('0 0 1 * * *'); + return $this->spliceIntoPosition(1, 0) + ->spliceIntoPosition(2, 0) + ->spliceIntoPosition(3, 1); } /** @@ -529,7 +534,10 @@ public function monthlyOn($day = 1, $time = '0:0') */ public function quarterly() { - return $this->cron('0 0 1 */3 *'); + return $this->spliceIntoPosition(1, 0) + ->spliceIntoPosition(2, 0) + ->spliceIntoPosition(3, 1) + ->spliceIntoPosition(4, '*/3'); } /** @@ -539,7 +547,10 @@ public function quarterly() */ public function yearly() { - return $this->cron('0 0 1 1 * *'); + return $this->spliceIntoPosition(1, 0) + ->spliceIntoPosition(2, 0) + ->spliceIntoPosition(3, 1) + ->spliceIntoPosition(4, 1); } /** @@ -549,7 +560,7 @@ public function yearly() */ public function everyMinute() { - return $this->cron('* * * * * *'); + return $this->spliceIntoPosition(1, '*'); } /** @@ -559,7 +570,7 @@ public function everyMinute() */ public function everyFiveMinutes() { - return $this->cron('*/5 * * * * *'); + return $this->spliceIntoPosition(1, '*/5'); } /** @@ -569,7 +580,7 @@ public function everyFiveMinutes() */ public function everyTenMinutes() { - return $this->cron('*/10 * * * * *'); + return $this->spliceIntoPosition(1, '*/10'); } /** @@ -579,7 +590,7 @@ public function everyTenMinutes() */ public function everyThirtyMinutes() { - return $this->cron('0,30 * * * * *'); + return $this->spliceIntoPosition(1, '0,30'); } /** diff --git a/tests/Console/ConsoleScheduledEventTest.php b/tests/Console/ConsoleScheduledEventTest.php index 4ddf07a197b8..bdf3de170e4c 100644 --- a/tests/Console/ConsoleScheduledEventTest.php +++ b/tests/Console/ConsoleScheduledEventTest.php @@ -69,6 +69,25 @@ public function testBasicCronCompilation() $event = new Event('php foo'); $this->assertEquals('0 15 4 * * *', $event->monthlyOn(4, '15:00')->getExpression()); + + $event = new Event('php foo'); + $this->assertEquals('0 0 * * 1-5 *', $event->weekdays()->daily()->getExpression()); + + $event = new Event('php foo'); + $this->assertEquals('0 * * * 1-5 *', $event->weekdays()->hourly()->getExpression()); + + // chained rules should be commutative + $eventA = new Event('php foo'); + $eventB = new Event('php foo'); + $this->assertEquals( + $eventA->daily()->hourly()->getExpression(), + $eventB->hourly()->daily()->getExpression()); + + $eventA = new Event('php foo'); + $eventB = new Event('php foo'); + $this->assertEquals( + $eventA->weekdays()->hourly()->getExpression(), + $eventB->hourly()->weekdays()->getExpression()); } public function testEventIsDueCheck() From 4945be33ad5bc2d75c5b4782187531f2f283728f Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Fri, 29 Jul 2016 10:45:55 -0300 Subject: [PATCH 029/249] [5.3] Collection filter() - Make use of Arr::where() (#14533) --- src/Illuminate/Support/Collection.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index b9bc47d6702e..4003b4264f59 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -256,15 +256,7 @@ public function except($keys) public function filter(callable $callback = null) { if ($callback) { - $return = []; - - foreach ($this->items as $key => $value) { - if ($callback($value, $key)) { - $return[$key] = $value; - } - } - - return new static($return); + return new static(Arr::where($this->items, $callback)); } return new static(array_filter($this->items)); From 6a17a5e0f4fd7b2fd43c0c9ff39d60c43081a744 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 29 Jul 2016 09:51:54 -0400 Subject: [PATCH 030/249] format code --- src/Illuminate/Database/Query/Builder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 5681a0094876..a9430f750208 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1091,6 +1091,7 @@ public function whereTime($column, $operator, $value, $boolean = 'and') { return $this->addDateBasedWhere('Time', $column, $operator, $value, $boolean); } + /** * Add an "or where time" statement to the query. * From 7da8c6c28315209c50af2e1237baad59213b585e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 29 Jul 2016 09:52:16 -0400 Subject: [PATCH 031/249] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Illuminate/Database/Query/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index a9430f750208..6b14ad182aaf 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1089,7 +1089,7 @@ public function orWhereDate($column, $operator, $value) */ public function whereTime($column, $operator, $value, $boolean = 'and') { - return $this->addDateBasedWhere('Time', $column, $operator, $value, $boolean); + return $this->addDateBasedWhere('Time', $column, $operator, $value, $boolean); } /** @@ -1102,7 +1102,7 @@ public function whereTime($column, $operator, $value, $boolean = 'and') */ public function orWhereTime($column, $operator, $value) { - return $this->whereTime($column, $operator, $value, 'or'); + return $this->whereTime($column, $operator, $value, 'or'); } /** From 075728772709b179533390b0533cd00d24971247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sercan=20=C3=87ak=C4=B1r?= Date: Fri, 29 Jul 2016 21:13:20 +0300 Subject: [PATCH 032/249] fix phpDocs (#14540) --- .../Notifications/Channels/SlackWebhookChannel.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php index f2eb6217f263..e8e313938601 100644 --- a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php +++ b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php @@ -29,7 +29,7 @@ public function __construct(HttpClient $http) * Send the given notification. * * @param \Illuminate\Support\Collection $notifiables - * @param \Illuminate\Notifications\Channels\Notification $notification + * @param \Illuminate\Notifications\Notification $notification * @return void */ public function send($notifiables, Notification $notification) @@ -57,7 +57,7 @@ public function send($notifiables, Notification $notification) /** * Format the given notification. * - * @param \Illuminate\Notifications\Channels\Notification $notification + * @param \Illuminate\Notifications\Notification $notification * @return string */ protected function format(Notification $notification) @@ -76,7 +76,7 @@ protected function format(Notification $notification) /** * Get the color that should be applied to the notification. * - * @param \Illuminate\Notifications\Channels\Notification $notification + * @param \Illuminate\Notifications\Notification $notification * @return string|null */ protected function color(Notification $notification) From 0ad3f8af0fb6337dcf8d17559a9a104d3c367b24 Mon Sep 17 00:00:00 2001 From: Christopher L Bray Date: Fri, 29 Jul 2016 19:13:44 +0100 Subject: [PATCH 033/249] Alias Mailer as MailerContract (#14539) Mailable#send was throwing the following exception: "Cannot use Mailer as Mailer because the name is already in use in Mailable.php on line 10." Therefore, I aliased the Mailer dependency as MailerContract. So when the function attempts to build an instance of Mailable, it won't choke on the existing reference. --- src/Illuminate/Mail/Mailable.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index 85091e4c887d..16aef7ba2b9c 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -7,7 +7,7 @@ use Illuminate\Support\Str; use Illuminate\Support\Collection; use Illuminate\Container\Container; -use Illuminate\Contracts\Mail\Mailer; +use Illuminate\Contracts\Mail\Mailer as MailerContract; use Illuminate\Contracts\Queue\Factory as Queue; use Illuminate\Contracts\Mail\Mailable as MailableContract; @@ -100,10 +100,10 @@ class Mailable implements MailableContract /** * Send the message using the given mailer. * - * @param Mailer $mailer + * @param MailerContract $mailer * @return void */ - public function send(Mailer $mailer) + public function send(MailerContract $mailer) { Container::getInstance()->call([$this, 'build']); From 352b3a9882d6ea7dd26ff96a3777b4766f5f5c22 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 29 Jul 2016 14:14:13 -0400 Subject: [PATCH 034/249] order imports --- src/Illuminate/Mail/Mailable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index 16aef7ba2b9c..fccf5bae9f6f 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -7,8 +7,8 @@ use Illuminate\Support\Str; use Illuminate\Support\Collection; use Illuminate\Container\Container; -use Illuminate\Contracts\Mail\Mailer as MailerContract; use Illuminate\Contracts\Queue\Factory as Queue; +use Illuminate\Contracts\Mail\Mailer as MailerContract; use Illuminate\Contracts\Mail\Mailable as MailableContract; class Mailable implements MailableContract From 7d60cbecbb1996ac4523592a6803aa3656df5c86 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 29 Jul 2016 16:27:42 -0400 Subject: [PATCH 035/249] finish test --- tests/Notifications/NotificationDatabaseChannelTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Notifications/NotificationDatabaseChannelTest.php b/tests/Notifications/NotificationDatabaseChannelTest.php index e0aec2e9b9a6..9c00a091799e 100644 --- a/tests/Notifications/NotificationDatabaseChannelTest.php +++ b/tests/Notifications/NotificationDatabaseChannelTest.php @@ -1,6 +1,7 @@ notifiables = collect([$notifiable = Mockery::mock()]); + $notifiables = collect([$notifiable = Mockery::mock()]); $notifiable->shouldReceive('routeNotificationFor->create')->with([ 'level' => 'info', @@ -22,5 +23,8 @@ public function testDatabaseChannelCreatesDatabaseRecordWithProperData() 'action_url' => null, 'read' => false, ]); + + $channel = new DatabaseChannel; + $channel->send($notifiables, $notification); } } From 27f0880a894ac5c22dda01fdc07e5f6bf9ed364a Mon Sep 17 00:00:00 2001 From: Flugger Date: Sat, 30 Jul 2016 09:34:06 +0100 Subject: [PATCH 036/249] Change exception message to actual model path --- src/Illuminate/Database/Eloquent/Builder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index a35c52cba0a3..8f482a950620 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -681,7 +681,8 @@ public function getRelation($name) try { return $this->getModel()->$name(); } catch (BadMethodCallException $e) { - throw new RelationNotFoundException("Call to undefined relationship {$name} on Model {$this->getModel()}"); + $className = get_class($this->getModel()); + throw new RelationNotFoundException("Call to undefined relationship {$name} on Model {$className}"); } }); From 20e2abfc3520176623ae881e0bd573360e65b912 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sat, 30 Jul 2016 18:08:50 +0200 Subject: [PATCH 037/249] Fix some docblocks. --- src/Illuminate/Mail/Mailable.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index fccf5bae9f6f..bfd040076957 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -100,7 +100,7 @@ class Mailable implements MailableContract /** * Send the message using the given mailer. * - * @param MailerContract $mailer + * @param \Illuminate\Contracts\Mail\Mailer $mailer * @return void */ public function send(MailerContract $mailer) @@ -119,7 +119,7 @@ public function send(MailerContract $mailer) /** * Queue the message for sending. * - * @param Queue $queue + * @param \Illuminate\Contracts\Queue\Factory $queue * @return mixed */ public function queue(Queue $queue) @@ -395,7 +395,7 @@ public function view($view, array $data = []) /** * Set the plain text view for the message. * - * @param string $view + * @param string $textView * @param array $data * @return $this */ From 346706859ed731b0f89060ceb58595c3d0df3a19 Mon Sep 17 00:00:00 2001 From: Brandon Shar Date: Sat, 30 Jul 2016 23:16:23 -0400 Subject: [PATCH 038/249] Turn the collection into a base collection if map loses models --- .../Database/Eloquent/Collection.php | 20 +++++++++++++ src/Illuminate/Support/Collection.php | 2 +- .../DatabaseEloquentCollectionTest.php | 29 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index d52c4d8c5992..124903d833cd 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -5,6 +5,7 @@ use LogicException; use Illuminate\Support\Arr; use Illuminate\Contracts\Queue\QueueableCollection; +use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection as BaseCollection; class Collection extends BaseCollection implements QueueableCollection @@ -114,6 +115,25 @@ public function merge($items) return new static(array_values($dictionary)); } + /** + * Run a map over each of the items. + * + * @param callable $callback + * @return static + */ + public function map(callable $callback) + { + $keys = array_keys($this->items); + + $items = array_map($callback, $this->items, $keys); + + $result = new static(array_combine($keys, $items)); + + return $result->contains(function ($_, $item) { + return !($item instanceof Model); + }) ? $result->toBase() : $result; + } + /** * Diff the collection with the given items. * diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 4003b4264f59..2518ece7e662 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -178,7 +178,7 @@ public function contains($key, $value = null) * @return static */ public function diff($items) - { + { return new static(array_diff($this->items, $this->getArrayableItems($items))); } diff --git a/tests/Database/DatabaseEloquentCollectionTest.php b/tests/Database/DatabaseEloquentCollectionTest.php index ccea6437af44..af121d855923 100755 --- a/tests/Database/DatabaseEloquentCollectionTest.php +++ b/tests/Database/DatabaseEloquentCollectionTest.php @@ -146,6 +146,35 @@ public function testCollectionMergesWithGivenCollection() $this->assertEquals(new Collection([$one, $two, $three]), $c1->merge($c2)); } + public function testMap() + { + $one = m::mock('Illuminate\Database\Eloquent\Model'); + $two = m::mock('Illuminate\Database\Eloquent\Model'); + + $c = new Collection([$one, $two]); + + $cAfterMap = $c->map(function($item) { + return $item; + }); + + $this->assertEquals($c->all(), $cAfterMap->all()); + $this->assertInstanceOf(Collection::class, $cAfterMap); + } + + public function testCollectionChangesToBaseCollectionIfMapLosesModels() + { + $one = m::mock('Illuminate\Database\Eloquent\Model'); + $two = m::mock('Illuminate\Database\Eloquent\Model'); + + $c = new Collection([$one, $two]); + + $cAfterMap = $c->map(function($item) { + return []; + }); + + $this->assertInstanceOf(BaseCollection::class, $cAfterMap); + } + public function testCollectionDiffsWithGivenCollection() { $one = m::mock('Illuminate\Database\Eloquent\Model'); From 6ce6bf3a56e8ff1f6b634c23b7d788179fca3088 Mon Sep 17 00:00:00 2001 From: Brandon Shar Date: Sat, 30 Jul 2016 23:19:41 -0400 Subject: [PATCH 039/249] this is cleaner --- src/Illuminate/Database/Eloquent/Collection.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index 124903d833cd..456c1fdd63fa 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -123,11 +123,7 @@ public function merge($items) */ public function map(callable $callback) { - $keys = array_keys($this->items); - - $items = array_map($callback, $this->items, $keys); - - $result = new static(array_combine($keys, $items)); + $result = parent::map($callback); return $result->contains(function ($_, $item) { return !($item instanceof Model); From 35b5f510cf20f408a44157e0842fd035e919bfce Mon Sep 17 00:00:00 2001 From: Brandon Shar Date: Sat, 30 Jul 2016 23:20:38 -0400 Subject: [PATCH 040/249] accidentally a space --- src/Illuminate/Support/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 2518ece7e662..4003b4264f59 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -178,7 +178,7 @@ public function contains($key, $value = null) * @return static */ public function diff($items) - { + { return new static(array_diff($this->items, $this->getArrayableItems($items))); } From 10bae535d80457b4adbea4ad2b7539d5df31aacd Mon Sep 17 00:00:00 2001 From: Brandon Shar Date: Sun, 31 Jul 2016 00:05:54 -0400 Subject: [PATCH 041/249] fixing style issues --- src/Illuminate/Database/Eloquent/Collection.php | 2 +- tests/Database/DatabaseEloquentCollectionTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index 456c1fdd63fa..d61798697ca1 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -126,7 +126,7 @@ public function map(callable $callback) $result = parent::map($callback); return $result->contains(function ($_, $item) { - return !($item instanceof Model); + return ! ($item instanceof Model); }) ? $result->toBase() : $result; } diff --git a/tests/Database/DatabaseEloquentCollectionTest.php b/tests/Database/DatabaseEloquentCollectionTest.php index af121d855923..47bfb1d55273 100755 --- a/tests/Database/DatabaseEloquentCollectionTest.php +++ b/tests/Database/DatabaseEloquentCollectionTest.php @@ -153,7 +153,7 @@ public function testMap() $c = new Collection([$one, $two]); - $cAfterMap = $c->map(function($item) { + $cAfterMap = $c->map(function ($item) { return $item; }); @@ -168,7 +168,7 @@ public function testCollectionChangesToBaseCollectionIfMapLosesModels() $c = new Collection([$one, $two]); - $cAfterMap = $c->map(function($item) { + $cAfterMap = $c->map(function ($item) { return []; }); From 7d8fc24501ae592833edb5d2c5dfed8203159ace Mon Sep 17 00:00:00 2001 From: Brandon Shar Date: Sun, 31 Jul 2016 00:17:58 -0400 Subject: [PATCH 042/249] removed unnecessary use --- src/Illuminate/Database/Eloquent/Collection.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index d61798697ca1..dbf85300915b 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -5,7 +5,6 @@ use LogicException; use Illuminate\Support\Arr; use Illuminate\Contracts\Queue\QueueableCollection; -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection as BaseCollection; class Collection extends BaseCollection implements QueueableCollection From 27f0d93d586ceb5e01c4d2048b0111f444f0c30a Mon Sep 17 00:00:00 2001 From: Brandon Shar Date: Sun, 31 Jul 2016 19:35:12 -0400 Subject: [PATCH 043/249] add toBase to support collection so change isnt breaking --- src/Illuminate/Support/Collection.php | 10 ++++++++++ tests/Support/SupportCollectionTest.php | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 4003b4264f59..76563b2f66c5 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -1094,6 +1094,16 @@ public function zip($items) return new static(call_user_func_array('array_map', $params)); } + /** + * Return self to allow compatibility with Illuminate\Database\Eloquent\Collection. + * + * @return \Illuminate\Support\Collection + */ + public function toBase() + { + return $this; + } + /** * Get the collection of items as a plain array. * diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 5cbe300db0c0..f9ebb2c86482 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1457,6 +1457,12 @@ public function testSliceNegativeOffsetAndNegativeLength() $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]); $this->assertEquals([3, 4, 5, 6], $collection->slice(-6, -2)->values()->toArray()); } + + public function testToBase() + { + $collection = new Collection([1, 2, 3]); + $this->assertSame($collection, $collection->toBase()); + } } class TestAccessorEloquentTestStub From 9b17ae511787e599f3a7d5b6af2ca6d9f0917778 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Mon, 1 Aug 2016 15:30:49 +0200 Subject: [PATCH 044/249] Ignore case in blade foreach compiler (#14581) --- src/Illuminate/View/Compilers/BladeCompiler.php | 2 +- tests/View/ViewBladeCompilerTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index 6f2b8597e953..df382b9f237e 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -579,7 +579,7 @@ protected function compileFor($expression) */ protected function compileForeach($expression) { - preg_match('/\( *(.*) +as *([^\)]*)/', $expression, $matches); + preg_match('/\( *(.*) +as *([^\)]*)/i', $expression, $matches); $iteratee = trim($matches[1]); diff --git a/tests/View/ViewBladeCompilerTest.php b/tests/View/ViewBladeCompilerTest.php index 8a663eb0cb19..71ed30662bdd 100644 --- a/tests/View/ViewBladeCompilerTest.php +++ b/tests/View/ViewBladeCompilerTest.php @@ -439,6 +439,18 @@ public function testForeachStatementsAreCompiled() $this->assertEquals($expected, $compiler->compileString($string)); } + public function testForeachStatementsAreCompileWithUppercaseSyntax() + { + $compiler = new BladeCompiler($this->getFiles(), __DIR__); + $string = '@foreach ($this->getUsers() AS $user) +test +@endforeach'; + $expected = 'getUsers(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getFirstLoop(); ?> +test +popLoop(); $loop = $__env->getFirstLoop(); ?>'; + $this->assertEquals($expected, $compiler->compileString($string)); + } + public function testNestedForeachStatementsAreCompiled() { $compiler = new BladeCompiler($this->getFiles(), __DIR__); From 9b579afd8d8e339fe5084dcf9de77f029a62b0a1 Mon Sep 17 00:00:00 2001 From: macku99 Date: Mon, 1 Aug 2016 23:31:05 +1000 Subject: [PATCH 045/249] Add missing return statement (#14580) --- src/Illuminate/Mail/Mailable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index bfd040076957..a459fbc5fe1a 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -289,7 +289,7 @@ protected function runCallbacks($message) */ public function from($address, $name = null) { - $this->setAddress($address, $name, 'from'); + return $this->setAddress($address, $name, 'from'); } /** From d6af018aec2de522ec4cded43b65a21fbcb83f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20van=20Dijk?= Date: Mon, 1 Aug 2016 15:31:15 +0200 Subject: [PATCH 046/249] [5.3] Update docblock - add missing parameter (#14576) * Update docblock - add missing parameter * Add return void --- src/Illuminate/Notifications/Action.php | 1 + src/Illuminate/Notifications/Channels/NexmoSmsChannel.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Illuminate/Notifications/Action.php b/src/Illuminate/Notifications/Action.php index f59f86836d1a..071db2d9efdc 100644 --- a/src/Illuminate/Notifications/Action.php +++ b/src/Illuminate/Notifications/Action.php @@ -23,6 +23,7 @@ class Action * * @param string $text * @param string $url + * @return void */ public function __construct($text, $url) { diff --git a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php index 7f02332a5a6a..4c4bd63ae768 100644 --- a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php +++ b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php @@ -26,6 +26,7 @@ class NexmoSmsChannel * Create a new Nexmo channel instance. * * @param \Nexmo\Client $nexmo + * @param string $from * @return void */ public function __construct(NexmoClient $nexmo, $from) From 0edd8f6fd9fa12505bd15c451021ab005d0f222e Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Mon, 1 Aug 2016 09:39:52 -0400 Subject: [PATCH 047/249] Cleanup model factory for mutiple models (#14571) --- src/Illuminate/Database/Eloquent/FactoryBuilder.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/FactoryBuilder.php b/src/Illuminate/Database/Eloquent/FactoryBuilder.php index 3fdb4b0b2e9a..8107dc788760 100644 --- a/src/Illuminate/Database/Eloquent/FactoryBuilder.php +++ b/src/Illuminate/Database/Eloquent/FactoryBuilder.php @@ -104,15 +104,11 @@ public function make(array $attributes = []) { if ($this->amount === 1) { return $this->makeInstance($attributes); - } else { - $results = []; - - for ($i = 0; $i < $this->amount; $i++) { - $results[] = $this->makeInstance($attributes); - } - - return new Collection($results); } + + return new Collection(array_map(function () use ($attributes) { + return $this->makeInstance($attributes); + }, range(1, $this->amount))); } /** From 2645a899be1d56a2f539fda9ba284725f382da95 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 1 Aug 2016 14:41:53 +0100 Subject: [PATCH 048/249] [5.3] Removed all HHVM code (#14570) * Removed all HHVM code * Applied fixes from StyleCI [ci skip] [skip ci] --- src/Illuminate/Console/Scheduling/Schedule.php | 10 +--------- src/Illuminate/Foundation/Console/ServeCommand.php | 11 +---------- src/Illuminate/Queue/Listener.php | 10 +--------- src/Illuminate/Support/Composer.php | 4 ---- tests/Console/ConsoleEventSchedulerTest.php | 2 +- tests/Filesystem/FilesystemTest.php | 6 ------ tests/Foundation/FoundationComposerTest.php | 2 +- tests/Queue/QueueListenerTest.php | 2 +- 8 files changed, 6 insertions(+), 41 deletions(-) diff --git a/src/Illuminate/Console/Scheduling/Schedule.php b/src/Illuminate/Console/Scheduling/Schedule.php index b9bd265912ed..f5ee9cf813bc 100644 --- a/src/Illuminate/Console/Scheduling/Schedule.php +++ b/src/Illuminate/Console/Scheduling/Schedule.php @@ -39,15 +39,7 @@ public function command($command, array $parameters = []) { $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)); - if (defined('HHVM_VERSION')) { - $binary .= ' --php'; - } - - if (defined('ARTISAN_BINARY')) { - $artisan = ProcessUtils::escapeArgument(ARTISAN_BINARY); - } else { - $artisan = 'artisan'; - } + $artisan = defined('ARTISAN_BINARY') ? ProcessUtils::escapeArgument(ARTISAN_BINARY) : 'artisan'; return $this->exec("{$binary} {$artisan} {$command}", $parameters); } diff --git a/src/Illuminate/Foundation/Console/ServeCommand.php b/src/Illuminate/Foundation/Console/ServeCommand.php index 90e596e9788e..9c3478cca3f9 100644 --- a/src/Illuminate/Foundation/Console/ServeCommand.php +++ b/src/Illuminate/Foundation/Console/ServeCommand.php @@ -2,7 +2,6 @@ namespace Illuminate\Foundation\Console; -use Exception; use Illuminate\Console\Command; use Symfony\Component\Process\ProcessUtils; use Symfony\Component\Console\Input\InputOption; @@ -45,15 +44,7 @@ public function fire() $this->info("Laravel development server started on http://{$host}:{$port}/"); - if (defined('HHVM_VERSION')) { - if (version_compare(HHVM_VERSION, '3.8.0') >= 0) { - passthru("{$binary} -m server -v Server.Type=proxygen -v Server.SourceRoot={$base}/ -v Server.IP={$host} -v Server.Port={$port} -v Server.DefaultDocument=server.php -v Server.ErrorDocument404=server.php"); - } else { - throw new Exception("HHVM's built-in server requires HHVM >= 3.8.0."); - } - } else { - passthru("{$binary} -S {$host}:{$port} {$base}/server.php"); - } + passthru("{$binary} -S {$host}:{$port} {$base}/server.php"); } /** diff --git a/src/Illuminate/Queue/Listener.php b/src/Illuminate/Queue/Listener.php index b19d46c4479d..c3f08d35543a 100755 --- a/src/Illuminate/Queue/Listener.php +++ b/src/Illuminate/Queue/Listener.php @@ -72,15 +72,7 @@ protected function buildWorkerCommand() { $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)); - if (defined('HHVM_VERSION')) { - $binary .= ' --php'; - } - - if (defined('ARTISAN_BINARY')) { - $artisan = ProcessUtils::escapeArgument(ARTISAN_BINARY); - } else { - $artisan = 'artisan'; - } + $artisan = defined('ARTISAN_BINARY') ? ProcessUtils::escapeArgument(ARTISAN_BINARY) : 'artisan'; $command = 'queue:work %s --queue=%s --delay=%s --memory=%s --sleep=%s --tries=%s'; diff --git a/src/Illuminate/Support/Composer.php b/src/Illuminate/Support/Composer.php index 50bed398a136..11ce9caabe38 100644 --- a/src/Illuminate/Support/Composer.php +++ b/src/Illuminate/Support/Composer.php @@ -74,10 +74,6 @@ protected function findComposer() $binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)); - if (defined('HHVM_VERSION')) { - $binary .= ' --php'; - } - return "{$binary} composer.phar"; } diff --git a/tests/Console/ConsoleEventSchedulerTest.php b/tests/Console/ConsoleEventSchedulerTest.php index 640d13db90d9..9e08544c6239 100644 --- a/tests/Console/ConsoleEventSchedulerTest.php +++ b/tests/Console/ConsoleEventSchedulerTest.php @@ -42,7 +42,7 @@ public function testCommandCreatesNewArtisanCommand() $schedule->command('queue:listen', ['--tries' => 3]); $events = $schedule->events(); - $binary = $escape.PHP_BINARY.$escape.(defined('HHVM_VERSION') ? ' --php' : ''); + $binary = $escape.PHP_BINARY.$escape; $this->assertEquals($binary.' artisan queue:listen', $events[0]->command); $this->assertEquals($binary.' artisan queue:listen --tries=3', $events[1]->command); $this->assertEquals($binary.' artisan queue:listen --tries=3', $events[2]->command); diff --git a/tests/Filesystem/FilesystemTest.php b/tests/Filesystem/FilesystemTest.php index 017ea9e1ae5d..0ce7e9f9a3d1 100755 --- a/tests/Filesystem/FilesystemTest.php +++ b/tests/Filesystem/FilesystemTest.php @@ -312,12 +312,6 @@ public function testMakeDirectory() */ public function testSharedGet() { - if (defined('HHVM_VERSION')) { - $this->markTestSkipped('Skip HHVM test due to bug: https://github.com/facebook/hhvm/issues/5657'); - - return; - } - $content = ''; for ($i = 0; $i < 1000000; ++$i) { $content .= $i; diff --git a/tests/Foundation/FoundationComposerTest.php b/tests/Foundation/FoundationComposerTest.php index 6e22afba7147..97cd12c57fc0 100755 --- a/tests/Foundation/FoundationComposerTest.php +++ b/tests/Foundation/FoundationComposerTest.php @@ -17,7 +17,7 @@ public function testDumpAutoloadRunsTheCorrectCommand() $files->shouldReceive('exists')->once()->with(__DIR__.'/composer.phar')->andReturn(true); $process = m::mock('stdClass'); $composer->expects($this->once())->method('getProcess')->will($this->returnValue($process)); - $process->shouldReceive('setCommandLine')->once()->with($escape.PHP_BINARY.$escape.(defined('HHVM_VERSION') ? ' --php' : '').' composer.phar dump-autoload'); + $process->shouldReceive('setCommandLine')->once()->with($escape.PHP_BINARY.$escape.' composer.phar dump-autoload'); $process->shouldReceive('run')->once(); $composer->dumpAutoloads(); diff --git a/tests/Queue/QueueListenerTest.php b/tests/Queue/QueueListenerTest.php index adf5cce44bcb..a67541126013 100755 --- a/tests/Queue/QueueListenerTest.php +++ b/tests/Queue/QueueListenerTest.php @@ -39,6 +39,6 @@ public function testMakeProcessCorrectlyFormatsCommandLine() $this->assertInstanceOf('Symfony\Component\Process\Process', $process); $this->assertEquals(__DIR__, $process->getWorkingDirectory()); $this->assertEquals(3, $process->getTimeout()); - $this->assertEquals($escape.PHP_BINARY.$escape.(defined('HHVM_VERSION') ? ' --php' : '')." artisan queue:work {$escape}connection{$escape} --queue={$escape}queue{$escape} --delay=1 --memory=2 --sleep=3 --tries=0", $process->getCommandLine()); + $this->assertEquals($escape.PHP_BINARY.$escape." artisan queue:work {$escape}connection{$escape} --queue={$escape}queue{$escape} --delay=1 --memory=2 --sleep=3 --tries=0", $process->getCommandLine()); } } From b23d1e356b605b0c3df7e2d3ccb6c5708de5cd38 Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Mon, 1 Aug 2016 18:43:53 +0500 Subject: [PATCH 049/249] Fix empty api key authentication error. (#14568) --- src/Illuminate/Auth/TokenGuard.php | 4 ++++ tests/Auth/AuthTokenGuardTest.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Illuminate/Auth/TokenGuard.php b/src/Illuminate/Auth/TokenGuard.php index e9d3602fca57..2a33ab0e61f4 100644 --- a/src/Illuminate/Auth/TokenGuard.php +++ b/src/Illuminate/Auth/TokenGuard.php @@ -101,6 +101,10 @@ protected function getTokenForRequest() */ public function validate(array $credentials = []) { + if (empty($credentials[$this->inputKey])) { + return false; + } + $credentials = [$this->storageKey => $credentials[$this->inputKey]]; if ($this->provider->retrieveByCredentials($credentials)) { diff --git a/tests/Auth/AuthTokenGuardTest.php b/tests/Auth/AuthTokenGuardTest.php index e820667f16a3..2f192f0cfd6c 100644 --- a/tests/Auth/AuthTokenGuardTest.php +++ b/tests/Auth/AuthTokenGuardTest.php @@ -80,6 +80,18 @@ public function testValidateCanDetermineIfCredentialsAreInvalid() $this->assertFalse($guard->validate(['api_token' => 'foo'])); } + + public function testValidateIfApiTokenIsEmpty() + { + $provider = Mockery::mock(UserProvider::class); + $user = new AuthTokenGuardTestUser; + $user->id = 1; + $request = Request::create('/', 'GET', ['api_token' => '']); + + $guard = new TokenGuard($provider, $request); + + $this->assertFalse($guard->validate(['api_token' => ''])); + } } class AuthTokenGuardTestUser From fc5786b500142c763b99fad2a109f349761e6fb3 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Mon, 1 Aug 2016 15:49:14 +0200 Subject: [PATCH 050/249] Update author email (#14561) --- src/Illuminate/Auth/composer.json | 2 +- src/Illuminate/Broadcasting/composer.json | 2 +- src/Illuminate/Bus/composer.json | 2 +- src/Illuminate/Cache/composer.json | 2 +- src/Illuminate/Config/composer.json | 2 +- src/Illuminate/Console/composer.json | 2 +- src/Illuminate/Container/composer.json | 2 +- src/Illuminate/Contracts/composer.json | 2 +- src/Illuminate/Cookie/composer.json | 2 +- src/Illuminate/Database/composer.json | 2 +- src/Illuminate/Encryption/composer.json | 2 +- src/Illuminate/Events/composer.json | 2 +- src/Illuminate/Filesystem/composer.json | 2 +- src/Illuminate/Hashing/composer.json | 2 +- src/Illuminate/Http/composer.json | 2 +- src/Illuminate/Log/composer.json | 2 +- src/Illuminate/Mail/composer.json | 2 +- src/Illuminate/Pagination/composer.json | 2 +- src/Illuminate/Pipeline/composer.json | 2 +- src/Illuminate/Queue/composer.json | 2 +- src/Illuminate/Redis/composer.json | 2 +- src/Illuminate/Routing/composer.json | 2 +- src/Illuminate/Session/composer.json | 2 +- src/Illuminate/Support/composer.json | 2 +- src/Illuminate/Translation/composer.json | 2 +- src/Illuminate/Validation/composer.json | 2 +- src/Illuminate/View/composer.json | 2 +- 27 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Illuminate/Auth/composer.json b/src/Illuminate/Auth/composer.json index 9e3fba321fcb..ded351dd3198 100644 --- a/src/Illuminate/Auth/composer.json +++ b/src/Illuminate/Auth/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Broadcasting/composer.json b/src/Illuminate/Broadcasting/composer.json index b7de1953718c..be0f0204774f 100644 --- a/src/Illuminate/Broadcasting/composer.json +++ b/src/Illuminate/Broadcasting/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Bus/composer.json b/src/Illuminate/Bus/composer.json index 57a578a1f1f2..f52e5e3ebf8e 100644 --- a/src/Illuminate/Bus/composer.json +++ b/src/Illuminate/Bus/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Cache/composer.json b/src/Illuminate/Cache/composer.json index 1eaa26b83b2f..34d042791b05 100755 --- a/src/Illuminate/Cache/composer.json +++ b/src/Illuminate/Cache/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Config/composer.json b/src/Illuminate/Config/composer.json index d61855ad86a3..8c9aff3aebb7 100755 --- a/src/Illuminate/Config/composer.json +++ b/src/Illuminate/Config/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Console/composer.json b/src/Illuminate/Console/composer.json index 6c3464d7e6aa..c293fa14d48f 100755 --- a/src/Illuminate/Console/composer.json +++ b/src/Illuminate/Console/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Container/composer.json b/src/Illuminate/Container/composer.json index c4ea9ad0b34a..313f17565574 100755 --- a/src/Illuminate/Container/composer.json +++ b/src/Illuminate/Container/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Contracts/composer.json b/src/Illuminate/Contracts/composer.json index 18e4c9f7d683..f6c439f4d6f7 100644 --- a/src/Illuminate/Contracts/composer.json +++ b/src/Illuminate/Contracts/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Cookie/composer.json b/src/Illuminate/Cookie/composer.json index aeccfa7ddbe2..4e780dadd48a 100755 --- a/src/Illuminate/Cookie/composer.json +++ b/src/Illuminate/Cookie/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Database/composer.json b/src/Illuminate/Database/composer.json index 4f7e03144db7..1a1cd2794ab8 100644 --- a/src/Illuminate/Database/composer.json +++ b/src/Illuminate/Database/composer.json @@ -11,7 +11,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Encryption/composer.json b/src/Illuminate/Encryption/composer.json index 0c79358ca1aa..74c8740e9a72 100644 --- a/src/Illuminate/Encryption/composer.json +++ b/src/Illuminate/Encryption/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Events/composer.json b/src/Illuminate/Events/composer.json index ca5c9c7deea6..26feba1f0dc4 100755 --- a/src/Illuminate/Events/composer.json +++ b/src/Illuminate/Events/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Filesystem/composer.json b/src/Illuminate/Filesystem/composer.json index 0242fac70fdf..0de543fa921a 100644 --- a/src/Illuminate/Filesystem/composer.json +++ b/src/Illuminate/Filesystem/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Hashing/composer.json b/src/Illuminate/Hashing/composer.json index 09548cf731f3..f7c2f62cb2cf 100755 --- a/src/Illuminate/Hashing/composer.json +++ b/src/Illuminate/Hashing/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Http/composer.json b/src/Illuminate/Http/composer.json index 52ef78494686..d1fe638244f9 100755 --- a/src/Illuminate/Http/composer.json +++ b/src/Illuminate/Http/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Log/composer.json b/src/Illuminate/Log/composer.json index 7e406a863de6..a15c6733876c 100755 --- a/src/Illuminate/Log/composer.json +++ b/src/Illuminate/Log/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Mail/composer.json b/src/Illuminate/Mail/composer.json index 0986a9d8e803..9d3bf0d60e36 100755 --- a/src/Illuminate/Mail/composer.json +++ b/src/Illuminate/Mail/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Pagination/composer.json b/src/Illuminate/Pagination/composer.json index 9211f1ade95a..882abb09d1e3 100755 --- a/src/Illuminate/Pagination/composer.json +++ b/src/Illuminate/Pagination/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Pipeline/composer.json b/src/Illuminate/Pipeline/composer.json index 4d90531b1f21..7a6a8196fa9d 100644 --- a/src/Illuminate/Pipeline/composer.json +++ b/src/Illuminate/Pipeline/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Queue/composer.json b/src/Illuminate/Queue/composer.json index 0516bed51e18..33e9f4db9d3d 100644 --- a/src/Illuminate/Queue/composer.json +++ b/src/Illuminate/Queue/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Redis/composer.json b/src/Illuminate/Redis/composer.json index 120b16fea298..72f8f3b2c4b6 100755 --- a/src/Illuminate/Redis/composer.json +++ b/src/Illuminate/Redis/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Routing/composer.json b/src/Illuminate/Routing/composer.json index 98758dbea197..9f6b14d6c7dd 100644 --- a/src/Illuminate/Routing/composer.json +++ b/src/Illuminate/Routing/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Session/composer.json b/src/Illuminate/Session/composer.json index 1ed3116ece51..b7bd07aab797 100755 --- a/src/Illuminate/Session/composer.json +++ b/src/Illuminate/Session/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Support/composer.json b/src/Illuminate/Support/composer.json index 0e64579f3709..0df41454f574 100644 --- a/src/Illuminate/Support/composer.json +++ b/src/Illuminate/Support/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Translation/composer.json b/src/Illuminate/Translation/composer.json index 7a919da1e5d5..c76849de4985 100755 --- a/src/Illuminate/Translation/composer.json +++ b/src/Illuminate/Translation/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/Validation/composer.json b/src/Illuminate/Validation/composer.json index d1523889b222..121342caa413 100755 --- a/src/Illuminate/Validation/composer.json +++ b/src/Illuminate/Validation/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { diff --git a/src/Illuminate/View/composer.json b/src/Illuminate/View/composer.json index 9df4c4a881da..66b5ebc41386 100644 --- a/src/Illuminate/View/composer.json +++ b/src/Illuminate/View/composer.json @@ -10,7 +10,7 @@ "authors": [ { "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" + "email": "taylor@laravel.com" } ], "require": { From 73a57aec1016e7c1d985461c184b1f718d0f6876 Mon Sep 17 00:00:00 2001 From: Jordan Hoff Date: Mon, 1 Aug 2016 09:50:01 -0400 Subject: [PATCH 051/249] Adds unit test for whereTime on mysql (#14557) --- tests/Database/DatabaseQueryBuilderTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 01a569f25caa..59c8da84e99d 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -193,6 +193,14 @@ public function testWhereYearMySql() $this->assertEquals([0 => 2014], $builder->getBindings()); } + public function testWhereTimeMySql() + { + $builder = $this->getMySqlBuilder(); + $builder->select('*')->from('users')->whereTime('created_at', '>=', '22:00'); + $this->assertEquals('select * from `users` where time(`created_at`) >= ?', $builder->toSql()); + $this->assertEquals([0 => '22:00'], $builder->getBindings()); + } + public function testWhereDatePostgres() { $builder = $this->getPostgresBuilder(); From 96efc7ee3949584c4edb11f6dc711670ecdc4f74 Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Mon, 1 Aug 2016 10:52:33 -0300 Subject: [PATCH 052/249] [5.3] Request - Minor change and tests added to fingerprint() (#14551) * [5.3] Request - Minor change and tests to fingerprint() * Update fingerprint() method --- src/Illuminate/Http/Request.php | 11 +++++------ tests/Http/HttpRequestTest.php | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index 2ef5cadfc187..d69b4867f061 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -923,16 +923,15 @@ public function route($param = null) */ public function fingerprint() { - if (! $this->route()) { + if (! $route = $this->route()) { throw new RuntimeException('Unable to generate fingerprint. Route unavailable.'); } - return sha1( - implode('|', $this->route()->methods()). - '|'.$this->route()->domain(). - '|'.$this->route()->uri(). - '|'.$this->ip() + $values = array_merge( + $route->methods(), [$route->domain(), $route->uri(), $this->ip()] ); + + return sha1(implode('|', $values)); } /** diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index e555d0858388..cea56ec146c7 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -594,6 +594,28 @@ public function testUserResolverMakesUserAvailableAsMagicProperty() $this->assertEquals('user', $request->user()); } + public function testFingerprintMethod() + { + $request = Request::create('/', 'GET', [], [], [], []); + $request->setRouteResolver(function () use ($request) { + $route = new Route('GET', '/foo/bar/{id}', []); + $route->bind($request); + + return $route; + }); + + $this->assertEquals(40, mb_strlen($request->fingerprint())); + } + + /** + * @expectedException RuntimeException + */ + public function testFingerprintWithoutRoute() + { + $request = Request::create('/', 'GET', [], [], [], []); + $request->fingerprint(); + } + public function testCreateFromBase() { $body = [ From 7c3b00d72ef3c104abb0421085f585e34b34a231 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Aug 2016 08:53:44 -0500 Subject: [PATCH 053/249] inline temp --- src/Illuminate/Http/Request.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index d69b4867f061..149539b56ee5 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -927,11 +927,9 @@ public function fingerprint() throw new RuntimeException('Unable to generate fingerprint. Route unavailable.'); } - $values = array_merge( + return sha1(implode('|', array_merge( $route->methods(), [$route->domain(), $route->uri(), $this->ip()] - ); - - return sha1(implode('|', $values)); + ))); } /** From 1c27d9589c9b888b916982deae9ab5010d54a725 Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Mon, 1 Aug 2016 10:54:36 -0300 Subject: [PATCH 054/249] [5.3] Request - Dry's up a bit more (#14550) --- src/Illuminate/Http/Request.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index 149539b56ee5..fcf0bf4532b9 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -1023,7 +1023,7 @@ public function offsetGet($offset) */ public function offsetSet($offset, $value) { - return $this->getInputSource()->set($offset, $value); + $this->getInputSource()->set($offset, $value); } /** @@ -1034,7 +1034,7 @@ public function offsetSet($offset, $value) */ public function offsetUnset($offset) { - return $this->getInputSource()->remove($offset); + $this->getInputSource()->remove($offset); } /** @@ -1056,12 +1056,10 @@ public function __isset($key) */ public function __get($key) { - $all = $this->all(); - - if (array_key_exists($key, $all)) { - return $all[$key]; - } else { - return $this->route($key); + if ($this->offsetExists($key)) { + return $this->offsetGet($key); } + + return $this->route($key); } } From 669b6f69f0a194547f9335084df076d68e92f761 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 1 Aug 2016 14:55:14 +0100 Subject: [PATCH 055/249] [5.1] Fixed support for PHP 7.1 (#14549) * Test on PHP 7.1 * Fixed cache incrementing on php 7.1 * Skipped the legacy encrypter test on PHP 7.1+ --- src/Illuminate/Cache/ArrayStore.php | 2 +- src/Illuminate/Cache/DatabaseStore.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Cache/ArrayStore.php b/src/Illuminate/Cache/ArrayStore.php index efc94c001b88..caf83750acd6 100644 --- a/src/Illuminate/Cache/ArrayStore.php +++ b/src/Illuminate/Cache/ArrayStore.php @@ -50,7 +50,7 @@ public function put($key, $value, $minutes) */ public function increment($key, $value = 1) { - $this->storage[$key] = $this->storage[$key] + $value; + $this->storage[$key] = ((int) $this->storage[$key]) + $value; return $this->storage[$key]; } diff --git a/src/Illuminate/Cache/DatabaseStore.php b/src/Illuminate/Cache/DatabaseStore.php index 5617c2f56564..3ecc628f9748 100755 --- a/src/Illuminate/Cache/DatabaseStore.php +++ b/src/Illuminate/Cache/DatabaseStore.php @@ -165,7 +165,7 @@ protected function incrementOrDecrement($key, $value, Closure $callback) } $current = $this->encrypter->decrypt($cache->value); - $new = $callback($current, $value); + $new = $callback((int) $current, $value); if (! is_numeric($current)) { return false; From 266698bbd931c7beab9603107900a893be186cd1 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Mon, 1 Aug 2016 09:56:25 -0400 Subject: [PATCH 056/249] Add some missing methods to the Gate interface (#14546) --- src/Illuminate/Contracts/Auth/Access/Gate.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Illuminate/Contracts/Auth/Access/Gate.php b/src/Illuminate/Contracts/Auth/Access/Gate.php index 04f3e5e41968..9d8389089515 100644 --- a/src/Illuminate/Contracts/Auth/Access/Gate.php +++ b/src/Illuminate/Contracts/Auth/Access/Gate.php @@ -38,6 +38,14 @@ public function policy($class, $policy); */ public function before(callable $callback); + /** + * Register a callback to run after all Gate checks. + * + * @param callable $callback + * @return $this + */ + public function after(callable $callback); + /** * Determine if the given ability should be granted for the current user. * @@ -65,6 +73,27 @@ public function denies($ability, $arguments = []); */ public function check($ability, $arguments = []); + /** + * Determine if the given ability should be granted for the current user. + * + * @param string $ability + * @param array|mixed $arguments + * @return \Illuminate\Auth\Access\Response + * + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function authorize($ability, $arguments = []); + + /** + * Get a policy instance for a given class. + * + * @param object|string $class + * @return mixed + * + * @throws \InvalidArgumentException + */ + public function getPolicyFor($class); + /** * Get a guard instance for the given user. * From 0257c750d834e2ff864a694c5d3672638d304f13 Mon Sep 17 00:00:00 2001 From: Brandon Shar Date: Mon, 1 Aug 2016 10:48:22 -0400 Subject: [PATCH 057/249] remove legacy non-breaking code --- src/Illuminate/Support/Collection.php | 10 ---------- tests/Support/SupportCollectionTest.php | 6 ------ 2 files changed, 16 deletions(-) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 76563b2f66c5..4003b4264f59 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -1094,16 +1094,6 @@ public function zip($items) return new static(call_user_func_array('array_map', $params)); } - /** - * Return self to allow compatibility with Illuminate\Database\Eloquent\Collection. - * - * @return \Illuminate\Support\Collection - */ - public function toBase() - { - return $this; - } - /** * Get the collection of items as a plain array. * diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index f9ebb2c86482..5cbe300db0c0 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1457,12 +1457,6 @@ public function testSliceNegativeOffsetAndNegativeLength() $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]); $this->assertEquals([3, 4, 5, 6], $collection->slice(-6, -2)->values()->toArray()); } - - public function testToBase() - { - $collection = new Collection([1, 2, 3]); - $this->assertSame($collection, $collection->toBase()); - } } class TestAccessorEloquentTestStub From 3bc140c0000fa196191d2332a9e84d08cf26d8b9 Mon Sep 17 00:00:00 2001 From: henriklippke Date: Mon, 1 Aug 2016 16:49:27 +0200 Subject: [PATCH 058/249] Fixed race condition between DatabaseMigration and DatabaseTransaction (#14470) --- src/Illuminate/Foundation/Testing/TestCase.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index 42c4e1da4500..979c2f38d542 100755 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -100,14 +100,14 @@ protected function setUpTraits() { $uses = array_flip(class_uses_recursive(static::class)); - if (isset($uses[DatabaseTransactions::class])) { - $this->beginDatabaseTransaction(); - } - if (isset($uses[DatabaseMigrations::class])) { $this->runDatabaseMigrations(); } + if (isset($uses[DatabaseTransactions::class])) { + $this->beginDatabaseTransaction(); + } + if (isset($uses[WithoutMiddleware::class])) { $this->disableMiddlewareForAllTests(); } From 3dd6d3da33772bab431e2b88384148b858b24627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregorio=20Hern=C3=A1ndez=20Caso?= Date: Mon, 1 Aug 2016 17:09:22 +0200 Subject: [PATCH 059/249] Add toggle() method to BelongsToMany relation --- .../Eloquent/Relations/BelongsToMany.php | 63 ++++++++++++++++++- .../DatabaseEloquentBelongsToManyTest.php | 52 +++++++++++++-- 2 files changed, 108 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php index 449c5c325158..592a6ff2d9b3 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php @@ -817,7 +817,7 @@ public function sync($ids, $detaching = true) // if they exist in the array of current ones, and if not we will insert. $current = $this->newPivotQuery()->pluck($this->otherKey)->all(); - $records = $this->formatSyncList($ids); + $records = $this->formatRecordsList($ids); $detach = array_diff($current, array_keys($records)); @@ -847,12 +847,12 @@ public function sync($ids, $detaching = true) } /** - * Format the sync list so that it is keyed by ID. + * Format the sync/toggle list so that it is keyed by ID. * * @param array $records * @return array */ - protected function formatSyncList(array $records) + protected function formatRecordsList(array $records) { $results = []; @@ -1124,6 +1124,63 @@ protected function touchingParent() return $this->getRelated()->touches($this->guessInverseRelation()); } + /** + * Toggles a model (or models) from the parent. + * + * Each existing model is detached, and non existing ones are attached. + * + * @param mixed $ids + * @return array + */ + public function toggle($ids) + { + $changes = [ + 'attached' => [], 'detached' => [], + ]; + + if ($ids instanceof Model) { + $ids = $ids->getKey(); + } + + if ($ids instanceof Collection) { + $ids = $ids->modelKeys(); + } + + // First, we need to know which are the currently associated models. + $current = $this->newPivotQuery()->pluck($this->otherKey)->all(); + + $records = $this->formatRecordsList((array) $ids); + + // Next, we will take the intersection of the currents and given records, + // and detach all of the entities that are in the common in "current" + // array and in the array of the new records. + $detach = array_values(array_intersect($current, array_keys($records))); + + if (count($detach) > 0) { + $this->detach($detach, false); + + $changes['detached'] = (array) array_map(function ($v) { + return is_numeric($v) ? (int) $v : (string) $v; + }, $detach); + } + + // Finally, we attach the remaining records (those have not been detached + // and not are in the "current" array) + $attach = array_diff_key($records, array_flip($detach)); + + if (count($attach) > 0) { + $this->attach($attach, [], false); + + $changes['attached'] = array_keys($attach); + } + + if (count($changes['attached']) || count($changes['detached'])) { + $this->touchIfTouching(); + } + + return $changes; + } + /** * Attempt to guess the name of the inverse of the relation. * diff --git a/tests/Database/DatabaseEloquentBelongsToManyTest.php b/tests/Database/DatabaseEloquentBelongsToManyTest.php index 3ef49981afe4..491852b3ef45 100755 --- a/tests/Database/DatabaseEloquentBelongsToManyTest.php +++ b/tests/Database/DatabaseEloquentBelongsToManyTest.php @@ -554,6 +554,50 @@ public function testTouchMethodSyncsTimestamps() $relation->touch(); } + /** + * @dataProvider toggleMethodListProvider + */ + public function testToggleMethodTogglesIntermediateTableWithGivenArray($list) + { + $relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['attach', 'detach'])->setConstructorArgs($this->getRelationArguments())->getMock(); + $query = m::mock('stdClass'); + $query->shouldReceive('from')->once()->with('user_role')->andReturn($query); + $query->shouldReceive('where')->once()->with('user_id', 1)->andReturn($query); + $relation->getQuery()->shouldReceive('getQuery')->andReturn($mockQueryBuilder = m::mock('StdClass')); + $mockQueryBuilder->shouldReceive('newQuery')->once()->andReturn($query); + $query->shouldReceive('pluck')->once()->with('role_id')->andReturn(new BaseCollection([1, 2, 3])); + $relation->expects($this->once())->method('attach')->with($this->equalTo(['x' => []]), $this->equalTo([]), $this->equalTo(false)); + $relation->expects($this->once())->method('detach')->with($this->equalTo([2, 3])); + $relation->getRelated()->shouldReceive('touches')->andReturn(false); + $relation->getParent()->shouldReceive('touches')->andReturn(false); + + $this->assertEquals(['attached' => ['x'], 'detached' => [2, 3]], $relation->toggle($list)); + } + + public function toggleMethodListProvider() + { + return [ + [[2, 3, 'x']], + [['2', '3', 'x']], + ]; + } + + public function testToggleMethodTogglesIntermediateTableWithGivenArrayAndAttributes() + { + $relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['attach', 'detach', 'touchIfTouching', 'updateExistingPivot'])->setConstructorArgs($this->getRelationArguments())->getMock(); + $query = m::mock('stdClass'); + $query->shouldReceive('from')->once()->with('user_role')->andReturn($query); + $query->shouldReceive('where')->once()->with('user_id', 1)->andReturn($query); + $relation->getQuery()->shouldReceive('getQuery')->andReturn($mockQueryBuilder = m::mock('StdClass')); + $mockQueryBuilder->shouldReceive('newQuery')->once()->andReturn($query); + $query->shouldReceive('pluck')->once()->with('role_id')->andReturn(new BaseCollection([1, 2, 3])); + $relation->expects($this->once())->method('attach')->with($this->equalTo([4 => ['foo' => 'bar']]), [], $this->equalTo(false)); + $relation->expects($this->once())->method('detach')->with($this->equalTo([2, 3])); + $relation->expects($this->once())->method('touchIfTouching'); + + $this->assertEquals(['attached' => [4], 'detached' => [2, 3]], $relation->toggle([2, 3, 4 => ['foo' => 'bar']])); + } + public function testTouchIfTouching() { $relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['touch', 'touchingParent'])->setConstructorArgs($this->getRelationArguments())->getMock(); @@ -567,7 +611,7 @@ public function testTouchIfTouching() public function testSyncMethodConvertsCollectionToArrayOfKeys() { - $relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['attach', 'detach', 'touchIfTouching', 'formatSyncList'])->setConstructorArgs($this->getRelationArguments())->getMock(); + $relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['attach', 'detach', 'touchIfTouching', 'formatRecordsList'])->setConstructorArgs($this->getRelationArguments())->getMock(); $query = m::mock('stdClass'); $query->shouldReceive('from')->once()->with('user_role')->andReturn($query); $query->shouldReceive('where')->once()->with('user_id', 1)->andReturn($query); @@ -580,13 +624,13 @@ public function testSyncMethodConvertsCollectionToArrayOfKeys() m::mock(['getKey' => 2]), m::mock(['getKey' => 3]), ]); - $relation->expects($this->once())->method('formatSyncList')->with([1, 2, 3])->will($this->returnValue([1 => [], 2 => [], 3 => []])); + $relation->expects($this->once())->method('formatRecordsList')->with([1, 2, 3])->will($this->returnValue([1 => [], 2 => [], 3 => []])); $relation->sync($collection); } public function testWherePivotParamsUsedForNewQueries() { - $relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['attach', 'detach', 'touchIfTouching', 'formatSyncList'])->setConstructorArgs($this->getRelationArguments())->getMock(); + $relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['attach', 'detach', 'touchIfTouching', 'formatRecordsList'])->setConstructorArgs($this->getRelationArguments())->getMock(); // we expect to call $relation->wherePivot() $relation->getQuery()->shouldReceive('where')->once()->andReturn($relation); @@ -608,7 +652,7 @@ public function testWherePivotParamsUsedForNewQueries() // This is so $relation->sync() works $query->shouldReceive('pluck')->once()->with('role_id')->andReturn(new BaseCollection([1, 2, 3])); - $relation->expects($this->once())->method('formatSyncList')->with([1, 2, 3])->will($this->returnValue([1 => [], 2 => [], 3 => []])); + $relation->expects($this->once())->method('formatRecordsList')->with([1, 2, 3])->will($this->returnValue([1 => [], 2 => [], 3 => []])); $relation = $relation->wherePivot('foo', '=', 'bar'); // these params are to be stored $relation->sync([1, 2, 3]); // triggers the whole process above From 7d0694139eda81114ac552fe0ea9e440825dc889 Mon Sep 17 00:00:00 2001 From: Brandon Shar Date: Mon, 1 Aug 2016 11:20:58 -0400 Subject: [PATCH 060/249] good change in arguments for contains closure in 5.3 --- src/Illuminate/Database/Eloquent/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index dbf85300915b..5fb18d6fcf65 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -124,7 +124,7 @@ public function map(callable $callback) { $result = parent::map($callback); - return $result->contains(function ($_, $item) { + return $result->contains(function ($item) { return ! ($item instanceof Model); }) ? $result->toBase() : $result; } From 936a0292b1ea6ab33690d823a7af5c73dd063218 Mon Sep 17 00:00:00 2001 From: Pantelis Peslis Date: Mon, 1 Aug 2016 20:48:54 +0300 Subject: [PATCH 061/249] Add the opposite method of isDirty, the isClean --- src/Illuminate/Database/Eloquent/Model.php | 11 +++++++++++ tests/Database/DatabaseEloquentModelTest.php | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index a414999ff4da..9f683d04413d 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -3132,6 +3132,17 @@ public function isDirty($attributes = null) return false; } + /** + * Determine if the model or given attribute(s) have been remained the same. + * + * @param array|string|null $attributes + * @return bool + */ + public function isClean($attributes = null) + { + return ! $this->isDirty(...func_get_args()); + } + /** * Get the attributes that have been changed since last sync. * diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 8e33364e4a8e..7dba5bd583da 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -46,6 +46,21 @@ public function testDirtyAttributes() $this->assertTrue($model->isDirty(['foo', 'bar'])); } + public function testCleanAttributes() + { + $model = new EloquentModelStub(['foo' => '1', 'bar' => 2, 'baz' => 3]); + $model->syncOriginal(); + $model->foo = 1; + $model->bar = 20; + $model->baz = 30; + + $this->assertFalse($model->isClean()); + $this->assertTrue($model->isClean('foo')); + $this->assertFalse($model->isClean('bar')); + $this->assertFalse($model->isClean('foo', 'bar')); + $this->assertFalse($model->isClean(['foo', 'bar'])); + } + public function testCalculatedAttributes() { $model = new EloquentModelStub; From e36400abf6e2fecf3905e4f808d132f28283d9a7 Mon Sep 17 00:00:00 2001 From: Ashwani Agarwal Date: Tue, 2 Aug 2016 00:09:06 +0530 Subject: [PATCH 062/249] bcc mail issue (mailgun) (#10650) --- .../Mail/Transport/MailgunTransport.php | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/Illuminate/Mail/Transport/MailgunTransport.php b/src/Illuminate/Mail/Transport/MailgunTransport.php index 21bffea0e5a4..3f7da1a1c4d4 100644 --- a/src/Illuminate/Mail/Transport/MailgunTransport.php +++ b/src/Illuminate/Mail/Transport/MailgunTransport.php @@ -60,18 +60,18 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null) $options = ['auth' => ['api', $this->key]]; - $to = $this->getTo($message); - - $message->setBcc([]); - if (version_compare(ClientInterface::VERSION, '6') === 1) { $options['multipart'] = [ - ['name' => 'to', 'contents' => $to], + ['name' => 'to', 'contents' => $this->getTo($message)], + ['name' => 'cc', 'contents' => $this->getCc($message)], + ['name' => 'bcc', 'contents' => $this->getBcc($message)], ['name' => 'message', 'contents' => $message->toString(), 'filename' => 'message.mime'], ]; } else { $options['body'] = [ - 'to' => $to, + 'to' => $this->getTo($message), + 'cc' => $this->getCc($message), + 'bcc' => $this->getBcc($message), 'message' => new PostFile('message', $message->toString()), ]; } @@ -85,15 +85,44 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null) * Get the "to" payload field for the API request. * * @param \Swift_Mime_Message $message - * @return array + * @return string */ protected function getTo(Swift_Mime_Message $message) { - $formatted = []; + return $this->formatAddress($message->getTo()); + } + + /** + * Get the "cc" payload field for the API request. + * + * @param \Swift_Mime_Message $message + * @return string + */ + protected function getCc(Swift_Mime_Message $message) + { + return $this->formatAddress($message->getCc()); + } - $contacts = array_merge( - (array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc() - ); + /** + * Get the "bcc" payload field for the API request. + * + * @param \Swift_Mime_Message $message + * @return string + */ + protected function getBcc(Swift_Mime_Message $message) + { + return $this->formatAddress($message->getBcc()); + } + + /** + * Get Comma-Separated Address (with name, if available) for the API request. + * + * @param array $contacts + * @return string + */ + protected function formatAddress($contacts) + { + $formatted = []; foreach ($contacts as $address => $display) { $formatted[] = $display ? $display." <{$address}>" : $address; From 59a09738f11f026b3a7beae5629f923f3c6a1fe5 Mon Sep 17 00:00:00 2001 From: Jeffrey Way Date: Mon, 1 Aug 2016 14:47:35 -0400 Subject: [PATCH 063/249] Alias Mailer --- src/Illuminate/Mail/SendQueuedMailable.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Mail/SendQueuedMailable.php b/src/Illuminate/Mail/SendQueuedMailable.php index 1d5bd36601e5..995b5a88d536 100644 --- a/src/Illuminate/Mail/SendQueuedMailable.php +++ b/src/Illuminate/Mail/SendQueuedMailable.php @@ -2,7 +2,7 @@ namespace Illuminate\Mail; -use Illuminate\Contracts\Mail\Mailer; +use Illuminate\Contracts\Mail\Mailer as MailerContract; use Illuminate\Contracts\Mail\Mailable as MailableContract; class SendQueuedMailable @@ -28,10 +28,10 @@ public function __construct(MailableContract $mailable) /** * Handle the queued job. * - * @param Mailer $mailer + * @param MailerContract $mailer * @return void */ - public function handle(Mailer $mailer) + public function handle(MailerContract $mailer) { $mailer->send($this->mailable); } From 168d4c4df7304678e2a188b5f396b0caa02602c6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 1 Aug 2016 15:08:14 -0500 Subject: [PATCH 064/249] working on pagination --- src/Illuminate/Pagination/AbstractPaginator.php | 4 ++-- .../views/{bootstrap-3.blade.php => default.blade.php} | 0 ...{simple-bootstrap-3.blade.php => simple-default.blade.php} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/Illuminate/Pagination/resources/views/{bootstrap-3.blade.php => default.blade.php} (100%) rename src/Illuminate/Pagination/resources/views/{simple-bootstrap-3.blade.php => simple-default.blade.php} (100%) diff --git a/src/Illuminate/Pagination/AbstractPaginator.php b/src/Illuminate/Pagination/AbstractPaginator.php index 8025bcd2dc61..cb63745eb62a 100644 --- a/src/Illuminate/Pagination/AbstractPaginator.php +++ b/src/Illuminate/Pagination/AbstractPaginator.php @@ -85,14 +85,14 @@ abstract class AbstractPaginator implements Htmlable * * @var string */ - public static $defaultView = 'pagination::bootstrap-3'; + public static $defaultView = 'pagination::default'; /** * The default "simple" pagination view. * * @var string */ - public static $defaultSimpleView = 'pagination::simple-bootstrap-3'; + public static $defaultSimpleView = 'pagination::simple-default'; /** * Determine if the given value is a valid page number. diff --git a/src/Illuminate/Pagination/resources/views/bootstrap-3.blade.php b/src/Illuminate/Pagination/resources/views/default.blade.php similarity index 100% rename from src/Illuminate/Pagination/resources/views/bootstrap-3.blade.php rename to src/Illuminate/Pagination/resources/views/default.blade.php diff --git a/src/Illuminate/Pagination/resources/views/simple-bootstrap-3.blade.php b/src/Illuminate/Pagination/resources/views/simple-default.blade.php similarity index 100% rename from src/Illuminate/Pagination/resources/views/simple-bootstrap-3.blade.php rename to src/Illuminate/Pagination/resources/views/simple-default.blade.php From 775eb87700dbcbcba49ef12504657d8082a5fdf1 Mon Sep 17 00:00:00 2001 From: Mulia Arifandi Nasution Date: Tue, 2 Aug 2016 14:48:05 +0700 Subject: [PATCH 065/249] Fix typo on docblock --- src/Illuminate/Cache/Console/CacheTableCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Cache/Console/CacheTableCommand.php b/src/Illuminate/Cache/Console/CacheTableCommand.php index 2feedfd27d9a..7c3f4b62d519 100644 --- a/src/Illuminate/Cache/Console/CacheTableCommand.php +++ b/src/Illuminate/Cache/Console/CacheTableCommand.php @@ -35,7 +35,7 @@ class CacheTableCommand extends Command protected $composer; /** - * Create a new session table command instance. + * Create a new cache table command instance. * * @param \Illuminate\Filesystem\Filesystem $files * @param \Illuminate\Support\Composer $composer From 8434fa42f05aba946ab83509f818db4b5f175cf2 Mon Sep 17 00:00:00 2001 From: Hamid Alaei Varnosfaderani Date: Tue, 2 Aug 2016 17:14:26 +0430 Subject: [PATCH 066/249] DateTime delay (#14600) --- src/Illuminate/Bus/Queueable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Bus/Queueable.php b/src/Illuminate/Bus/Queueable.php index b850c5e44a7a..a7d306a89ba3 100644 --- a/src/Illuminate/Bus/Queueable.php +++ b/src/Illuminate/Bus/Queueable.php @@ -21,7 +21,7 @@ trait Queueable /** * The number of seconds before the job should be made available. * - * @var int|null + * @var \DateTime|int|null */ public $delay; From 79d8f7b82ff39b3fc511c1ae6999f16691d27f7d Mon Sep 17 00:00:00 2001 From: butschster Date: Tue, 2 Aug 2016 15:45:16 +0300 Subject: [PATCH 067/249] Add missed import (#14595) --- .../Foundation/Support/Providers/RouteServiceProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php b/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php index c14313c3e9a8..ad0435851b1b 100644 --- a/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php +++ b/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php @@ -2,6 +2,7 @@ namespace Illuminate\Foundation\Support\Providers; +use Illuminate\Routing\Router; use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Routing\UrlGenerator; From c47ee865493a294fee41d1f02986168a3629fa12 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 2 Aug 2016 07:50:24 -0500 Subject: [PATCH 068/249] fix comment --- src/Illuminate/Database/Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 9f683d04413d..435fb7dcb151 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -3133,7 +3133,7 @@ public function isDirty($attributes = null) } /** - * Determine if the model or given attribute(s) have been remained the same. + * Determine if the model or given attribute(s) have remained the same. * * @param array|string|null $attributes * @return bool From 513c804fb0e555d9af21155fd68bb5969ed47a86 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 2 Aug 2016 08:25:30 -0500 Subject: [PATCH 069/249] tweaking format --- src/Illuminate/Database/Eloquent/Collection.php | 2 +- src/Illuminate/Support/Collection.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index 5fb18d6fcf65..fe678d61eb0a 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -125,7 +125,7 @@ public function map(callable $callback) $result = parent::map($callback); return $result->contains(function ($item) { - return ! ($item instanceof Model); + return ! $item instanceof Model; }) ? $result->toBase() : $result; } diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 4003b4264f59..34e829aab5df 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -1168,6 +1168,18 @@ public function count() return count($this->items); } + /** + * Get a base Support collection instance from this collection. + * + * Provided for API compatibility with Eloquent collections. + * + * @return \Illuminate\Support\Collection + */ + public function toBase() + { + return $this; + } + /** * Determine if an item exists at an offset. * From 162f4745fb9bdf59aa362dd1db22a90d0d243997 Mon Sep 17 00:00:00 2001 From: Simon Hunt Date: Tue, 2 Aug 2016 15:57:55 +0100 Subject: [PATCH 070/249] Add seeRouteIs() to Illuminate\Foundation\Testing\Concerns\InteractsWithPages. --- .../Testing/Concerns/InteractsWithPages.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php index 28db9d42a06b..e515947b7f50 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php @@ -172,6 +172,22 @@ protected function seePageIs($uri) return $this; } + /** + * Assert that the current page matches a given named route. + * + * @param string $route + * @param array $parameters + * @return $this + */ + protected function seeRouteIs($route, $parameters = []) + { + $uri = route($route, $parameters); + + $this->seePageIs($uri); + + return $this; + } + /** * Assert that a given page successfully loaded. * From d91476cc5dc5e48853af068848d1cee106dacdf0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 2 Aug 2016 14:42:19 -0500 Subject: [PATCH 071/249] allow array keys to request helper --- src/Illuminate/Foundation/helpers.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index 0f798a6fea12..d9893df23bc2 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -599,7 +599,11 @@ function request($key = null, $default = null) return app('request'); } - return app('request')->input($key, $default); + if (is_array($key)) { + return app('request')->only($key); + } else { + return app('request')->input($key, $default); + } } } From 05a944da5491edb0dcec77b2624126a8503a1b66 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 2 Aug 2016 14:42:54 -0500 Subject: [PATCH 072/249] adjust type hint --- src/Illuminate/Foundation/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index d9893df23bc2..58a90c873c0b 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -589,7 +589,7 @@ function redirect($to = null, $status = 302, $headers = [], $secure = null) /** * Get an instance of the current request or an input item from the request. * - * @param string $key + * @param array|string $key * @param mixed $default * @return \Illuminate\Http\Request|string|array */ From 0f0a3b345533873d866cb9a6a01cc6df40e20908 Mon Sep 17 00:00:00 2001 From: Vignesh Gurusamy Date: Wed, 3 Aug 2016 11:16:52 +0530 Subject: [PATCH 073/249] Fix - Array to string conversion issue in validateIn() method --- src/Illuminate/Validation/Validator.php | 8 ++++++++ tests/Validation/ValidationValidatorTest.php | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index d2124f5e766b..4bc508148702 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -1274,6 +1274,14 @@ protected function getSize($attribute, $value) protected function validateIn($attribute, $value, $parameters) { if (is_array($value) && $this->hasRule($attribute, 'Array')) { + + // Avoid performing validation on multi dimensional array + foreach ($value as $element) { + if (is_array($element)) { + return false; + } + } + return count(array_diff($value, $parameters)) == 0; } diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 767b01a9acb2..46c7c8e73b2a 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1221,6 +1221,9 @@ public function testValidateIn() $v = new Validator($trans, ['name' => ['foo', 'bar']], ['name' => 'Alpha|In:foo,bar']); $this->assertFalse($v->passes()); + + $v = new Validator($trans, ['name' => ['foo', []]], ['name' => 'Array|In:foo,bar']); + $this->assertFalse($v->passes()); } public function testValidateNotIn() From 5eab45b639106214ebb04132252d3361d23c9719 Mon Sep 17 00:00:00 2001 From: Raza Mehdi Date: Wed, 3 Aug 2016 17:54:18 +0500 Subject: [PATCH 074/249] Fix typo (#14609) --- src/Illuminate/Notifications/ChannelManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Notifications/ChannelManager.php b/src/Illuminate/Notifications/ChannelManager.php index d630c56b2ffb..c555fb1c1cfc 100644 --- a/src/Illuminate/Notifications/ChannelManager.php +++ b/src/Illuminate/Notifications/ChannelManager.php @@ -38,7 +38,7 @@ public function send($notifiables, $notification) } /** - * Send the given notification immtediately. + * Send the given notification immediately. * * @param \Illuminate\Support\Collection|array $notifiables * @param mixed $notification From 415badb7490e69a30d08ae3ecd210f56bd5eb0ea Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 3 Aug 2016 13:15:47 -0500 Subject: [PATCH 075/249] Tweak password reset. --- .../stubs/make/views/auth/passwords/reset.stub | 2 +- .../Auth/Notifications/ResetPassword.php | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Illuminate/Auth/Console/stubs/make/views/auth/passwords/reset.stub b/src/Illuminate/Auth/Console/stubs/make/views/auth/passwords/reset.stub index bb4775a99093..3ac82d8c38fd 100644 --- a/src/Illuminate/Auth/Console/stubs/make/views/auth/passwords/reset.stub +++ b/src/Illuminate/Auth/Console/stubs/make/views/auth/passwords/reset.stub @@ -17,7 +17,7 @@
- + @if ($errors->has('email')) diff --git a/src/Illuminate/Auth/Notifications/ResetPassword.php b/src/Illuminate/Auth/Notifications/ResetPassword.php index 488d4e1d0e6b..c8959cf056c5 100644 --- a/src/Illuminate/Auth/Notifications/ResetPassword.php +++ b/src/Illuminate/Auth/Notifications/ResetPassword.php @@ -36,15 +36,17 @@ public function via($notifiable) } /** - * Get the notification message. + * Build the notification message. * - * @param mixed $notifiable - * @return \Illuminate\Notifications\MessageBuilder + * @return $this */ - public function message($notifiable) + public function message() { - return $this->line('You are receiving this email because we received a password reset request for your account. Click the button below to reset your password:') - ->action('Reset Password', url('password/reset', $this->token).'?email='.urlencode($notifiable->email)) - ->line('If you did not request a password reset, no further action is required.'); + return $this->line([ + 'You are receiving this email because we received a password reset request for your account.', + 'Click the button below to reset your password:' + ]) + ->action('Reset Password', url('password/reset', $this->token)) + ->line('If you did not request a password reset, no further action is required.'); } } From dd8b32625982b088c7a29d785d5436ee069df92e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 3 Aug 2016 14:16:02 -0400 Subject: [PATCH 076/249] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Illuminate/Auth/Notifications/ResetPassword.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Auth/Notifications/ResetPassword.php b/src/Illuminate/Auth/Notifications/ResetPassword.php index c8959cf056c5..664ef10f9aa9 100644 --- a/src/Illuminate/Auth/Notifications/ResetPassword.php +++ b/src/Illuminate/Auth/Notifications/ResetPassword.php @@ -44,7 +44,7 @@ public function message() { return $this->line([ 'You are receiving this email because we received a password reset request for your account.', - 'Click the button below to reset your password:' + 'Click the button below to reset your password:', ]) ->action('Reset Password', url('password/reset', $this->token)) ->line('If you did not request a password reset, no further action is required.'); From e5c3e215b73c8f08c49dd625d7942acac02832cd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 3 Aug 2016 13:47:18 -0500 Subject: [PATCH 077/249] add option for bc --- src/Illuminate/Queue/Console/WorkCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Illuminate/Queue/Console/WorkCommand.php b/src/Illuminate/Queue/Console/WorkCommand.php index eb6714836b60..6dd15ea8aa04 100755 --- a/src/Illuminate/Queue/Console/WorkCommand.php +++ b/src/Illuminate/Queue/Console/WorkCommand.php @@ -191,6 +191,8 @@ protected function getOptions() return [ ['queue', null, InputOption::VALUE_OPTIONAL, 'The queue to listen on'], + ['daemon', null, InputOption::VALUE_NONE, 'Run the worker in daemon mode (Deprecated)'], + ['once', null, InputOption::VALUE_NONE, 'Only process the next job on the queue'], ['delay', null, InputOption::VALUE_OPTIONAL, 'Amount of time to delay failed jobs', 0], From b41939ee505267dbeee40177ab71573a2f2da7f9 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Thu, 4 Aug 2016 14:47:50 +0200 Subject: [PATCH 078/249] Added whereStrict to Collections (#14624) --- src/Illuminate/Support/Collection.php | 12 ++++++++++++ tests/Support/SupportCollectionTest.php | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 34e829aab5df..92f8f3fdd446 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -310,6 +310,18 @@ protected function operatorForWhere($key, $operator, $value) }; } + /** + * Filter items by the given key value pair using strict comparison. + * + * @param string $key + * @param mixed $value + * @return static + */ + public function whereStrict($key, $value) + { + return $this->where($key, '===', $value); + } + /** * Filter items by the given key value pair. * diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 5cbe300db0c0..7745400ecbc9 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -335,6 +335,16 @@ public function testWhere() ); } + public function testWhereStrict() + { + $c = new Collection([['v' => 3], ['v' => '3']]); + + $this->assertEquals( + [['v' => 3]], + $c->whereStrict('v', 3)->values()->all() + ); + } + public function testWhereIn() { $c = new Collection([['v' => 1], ['v' => 2], ['v' => 3], ['v' => '3'], ['v' => 4]]); From 722e40e3b695fbe9ee7c0a326d93fc2ef084ec6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20M=C3=A1rquez?= Date: Thu, 4 Aug 2016 07:52:40 -0500 Subject: [PATCH 079/249] remove else from request helper (#14614) --- src/Illuminate/Foundation/helpers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index 58a90c873c0b..3414e3df4c9f 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -601,9 +601,9 @@ function request($key = null, $default = null) if (is_array($key)) { return app('request')->only($key); - } else { - return app('request')->input($key, $default); } + + return app('request')->input($key, $default); } } From 8c4cb7aa5a14c7b1477af3b08e6974a3c64a0a13 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Thu, 4 Aug 2016 08:57:12 -0400 Subject: [PATCH 080/249] [5.3] Make toBase on the base collection actually be useful (#14612) * Fix test: ascertain that the returned collection is not an Eloquent collection * Make the toBase method on the base collection actually work * Delete the toBase method on the Eloquent Collection * Fix tests: pass expected values first --- .../Database/Eloquent/Collection.php | 10 --------- src/Illuminate/Support/Collection.php | 4 +--- .../DatabaseEloquentCollectionTest.php | 22 +++++++++---------- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index fe678d61eb0a..12400f4607ad 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -356,14 +356,4 @@ public function getQueueableIds() { return $this->modelKeys(); } - - /** - * Get a base Support collection instance from this collection. - * - * @return \Illuminate\Support\Collection - */ - public function toBase() - { - return new BaseCollection($this->items); - } } diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 92f8f3fdd446..1e341b39c57e 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -1183,13 +1183,11 @@ public function count() /** * Get a base Support collection instance from this collection. * - * Provided for API compatibility with Eloquent collections. - * * @return \Illuminate\Support\Collection */ public function toBase() { - return $this; + return is_subclass_of($this, self::class) ? new self($this) : $this; } /** diff --git a/tests/Database/DatabaseEloquentCollectionTest.php b/tests/Database/DatabaseEloquentCollectionTest.php index 47bfb1d55273..0ddc4d7d3efd 100755 --- a/tests/Database/DatabaseEloquentCollectionTest.php +++ b/tests/Database/DatabaseEloquentCollectionTest.php @@ -161,18 +161,16 @@ public function testMap() $this->assertInstanceOf(Collection::class, $cAfterMap); } - public function testCollectionChangesToBaseCollectionIfMapLosesModels() + public function testMappingToNonModelsReturnsABaseCollection() { $one = m::mock('Illuminate\Database\Eloquent\Model'); $two = m::mock('Illuminate\Database\Eloquent\Model'); - $c = new Collection([$one, $two]); - - $cAfterMap = $c->map(function ($item) { - return []; + $c = (new Collection([$one, $two]))->map(function ($item) { + return 'not-a-model'; }); - $this->assertInstanceOf(BaseCollection::class, $cAfterMap); + $this->assertEquals(BaseCollection::class, get_class($c)); } public function testCollectionDiffsWithGivenCollection() @@ -276,12 +274,12 @@ public function testNonModelRelatedMethods() { $a = new Collection([['foo' => 'bar'], ['foo' => 'baz']]); $b = new Collection(['a', 'b', 'c']); - $this->assertEquals(get_class($a->pluck('foo')), BaseCollection::class); - $this->assertEquals(get_class($a->keys()), BaseCollection::class); - $this->assertEquals(get_class($a->collapse()), BaseCollection::class); - $this->assertEquals(get_class($a->flatten()), BaseCollection::class); - $this->assertEquals(get_class($a->zip(['a', 'b'], ['c', 'd'])), BaseCollection::class); - $this->assertEquals(get_class($b->flip()), BaseCollection::class); + $this->assertEquals(BaseCollection::class, get_class($a->pluck('foo'))); + $this->assertEquals(BaseCollection::class, get_class($a->keys())); + $this->assertEquals(BaseCollection::class, get_class($a->collapse())); + $this->assertEquals(BaseCollection::class, get_class($a->flatten())); + $this->assertEquals(BaseCollection::class, get_class($a->zip(['a', 'b'], ['c', 'd']))); + $this->assertEquals(BaseCollection::class, get_class($b->flip())); } public function testMakeVisibleRemovesHiddenAndIncludesVisible() From 4bcfa8225af6daf664ffd83c12ba6d25c2e112a2 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Thu, 4 Aug 2016 20:59:56 +0800 Subject: [PATCH 081/249] Remove unused code. (#14610) Signed-off-by: crynobone --- src/Illuminate/Notifications/ChannelManager.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/Illuminate/Notifications/ChannelManager.php b/src/Illuminate/Notifications/ChannelManager.php index c555fb1c1cfc..0b80731eea1d 100644 --- a/src/Illuminate/Notifications/ChannelManager.php +++ b/src/Illuminate/Notifications/ChannelManager.php @@ -197,17 +197,4 @@ public function deliverVia($channels) { $this->defaultChannels = (array) $channels; } - - /** - * Build a new channel notification from the given object. - * - * @param mixed $notifiable - * @param mixed $notification - * @param array|null $channels - * @return array - */ - public function notificationsFromInstance($notifiable, $notification, $channels = null) - { - return Channels\Notification::notificationsFromInstance($notifiable, $notification, $channels); - } } From 248f83e3f0a750063bfc49ba160635caff361782 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Aug 2016 08:09:59 -0500 Subject: [PATCH 082/249] refactor --- .../Foundation/Testing/Concerns/InteractsWithPages.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php index e515947b7f50..6707403cea4c 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php @@ -181,11 +181,7 @@ protected function seePageIs($uri) */ protected function seeRouteIs($route, $parameters = []) { - $uri = route($route, $parameters); - - $this->seePageIs($uri); - - return $this; + return $this->seePageIs(route($route, $parameters)); } /** From ec2a7cedb60cc0d8cc4cb1402755ee1660321673 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Aug 2016 08:12:20 -0500 Subject: [PATCH 083/249] remove comment --- src/Illuminate/Validation/Validator.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 4bc508148702..9fbe01d4ec99 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -1274,8 +1274,6 @@ protected function getSize($attribute, $value) protected function validateIn($attribute, $value, $parameters) { if (is_array($value) && $this->hasRule($attribute, 'Array')) { - - // Avoid performing validation on multi dimensional array foreach ($value as $element) { if (is_array($element)) { return false; From 2bb2b63524d908dac7fe262dd1d1642f62479a6b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Aug 2016 08:37:45 -0500 Subject: [PATCH 084/249] spacing --- src/Illuminate/Mail/Transport/MailgunTransport.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Mail/Transport/MailgunTransport.php b/src/Illuminate/Mail/Transport/MailgunTransport.php index 3f7da1a1c4d4..415dd1112607 100644 --- a/src/Illuminate/Mail/Transport/MailgunTransport.php +++ b/src/Illuminate/Mail/Transport/MailgunTransport.php @@ -46,8 +46,8 @@ class MailgunTransport extends Transport */ public function __construct(ClientInterface $client, $key, $domain) { - $this->client = $client; $this->key = $key; + $this->client = $client; $this->setDomain($domain); } @@ -69,9 +69,9 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null) ]; } else { $options['body'] = [ - 'to' => $this->getTo($message), - 'cc' => $this->getCc($message), - 'bcc' => $this->getBcc($message), + 'to' => $this->getTo($message), + 'cc' => $this->getCc($message), + 'bcc' => $this->getBcc($message), 'message' => new PostFile('message', $message->toString()), ]; } From 04329fb3a68f991789e53f2ee6783d59de0f3799 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Aug 2016 09:02:34 -0500 Subject: [PATCH 085/249] formatting and method extraction --- .../Eloquent/Relations/BelongsToMany.php | 135 ++++++++++-------- 1 file changed, 75 insertions(+), 60 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php index 592a6ff2d9b3..79049d03043f 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php @@ -795,6 +795,67 @@ public function createMany(array $records, array $joinings = []) return $instances; } + /** + * Toggles a model (or models) from the parent. + * + * Each existing model is detached, and non existing ones are attached. + * + * @param mixed $ids + * @return array + */ + public function toggle($ids) + { + $changes = [ + 'attached' => [], 'detached' => [], + ]; + + if ($ids instanceof Model) { + $ids = $ids->getKey(); + } + + if ($ids instanceof Collection) { + $ids = $ids->modelKeys(); + } + + // First we will execute a query to get all of the current attached IDs for + // the relationship, which will allow us to determine which of them will + // be attached and which of them will be detached from the join table. + $current = $this->newPivotQuery() + ->pluck($this->otherKey)->all(); + + $records = $this->formatRecordsList((array) $ids); + + // Next, we will determine which IDs should get removed from the join table + // by checking which of the given ID / records is in the list of current + // records. We will then remove all those rows from the joining table. + $detach = array_values(array_intersect( + $current, array_keys($records) + )); + + if (count($detach) > 0) { + $this->detach($detach, false); + + $changes['detached'] = $this->castKeys($detach); + } + + // Finally, for all of the records that were not detached, we'll attach the + // records into the intermediate table. Then we'll add those attaches to + // the change list and be ready to return these results to the caller. + $attach = array_diff_key($records, array_flip($detach)); + + if (count($attach) > 0) { + $this->attach($attach, [], false); + + $changes['attached'] = array_keys($attach); + } + + if (count($changes['attached']) || count($changes['detached'])) { + $this->touchIfTouching(); + } + + return $changes; + } + /** * Sync the intermediate tables with a list of IDs or collection of models. * @@ -827,9 +888,7 @@ public function sync($ids, $detaching = true) if ($detaching && count($detach) > 0) { $this->detach($detach); - $changes['detached'] = (array) array_map(function ($v) { - return is_numeric($v) ? (int) $v : (string) $v; - }, $detach); + $changes['detached'] = $this->castKeys($detach); } // Now we are finally ready to attach the new records. Note that we'll disable @@ -901,6 +960,19 @@ protected function attachNew(array $records, array $current, $touch = true) return $changes; } + /** + * Cast the given keys to integers if they are numeric and string otherwise. + * + * @param arary $keys + * @return array + */ + protected function castKeys(array $keys) + { + return (array) array_map(function ($v) { + return is_numeric($v) ? (int) $v : (string) $v; + }, $keys); + } + /** * Update an existing pivot record on the table. * @@ -1124,63 +1196,6 @@ protected function touchingParent() return $this->getRelated()->touches($this->guessInverseRelation()); } - /** - * Toggles a model (or models) from the parent. - * - * Each existing model is detached, and non existing ones are attached. - * - * @param mixed $ids - * @return array - */ - public function toggle($ids) - { - $changes = [ - 'attached' => [], 'detached' => [], - ]; - - if ($ids instanceof Model) { - $ids = $ids->getKey(); - } - - if ($ids instanceof Collection) { - $ids = $ids->modelKeys(); - } - - // First, we need to know which are the currently associated models. - $current = $this->newPivotQuery()->pluck($this->otherKey)->all(); - - $records = $this->formatRecordsList((array) $ids); - - // Next, we will take the intersection of the currents and given records, - // and detach all of the entities that are in the common in "current" - // array and in the array of the new records. - $detach = array_values(array_intersect($current, array_keys($records))); - - if (count($detach) > 0) { - $this->detach($detach, false); - - $changes['detached'] = (array) array_map(function ($v) { - return is_numeric($v) ? (int) $v : (string) $v; - }, $detach); - } - - // Finally, we attach the remaining records (those have not been detached - // and not are in the "current" array) - $attach = array_diff_key($records, array_flip($detach)); - - if (count($attach) > 0) { - $this->attach($attach, [], false); - - $changes['attached'] = array_keys($attach); - } - - if (count($changes['attached']) || count($changes['detached'])) { - $this->touchIfTouching(); - } - - return $changes; - } - /** * Attempt to guess the name of the inverse of the relation. * From 04bb8d7011f638c89980c02e46be161be9ba2ca2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Aug 2016 09:14:51 -0500 Subject: [PATCH 086/249] revert broken change to mailgun --- .../Mail/Transport/MailgunTransport.php | 51 ++++--------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/src/Illuminate/Mail/Transport/MailgunTransport.php b/src/Illuminate/Mail/Transport/MailgunTransport.php index 415dd1112607..f8378322868d 100644 --- a/src/Illuminate/Mail/Transport/MailgunTransport.php +++ b/src/Illuminate/Mail/Transport/MailgunTransport.php @@ -60,18 +60,18 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null) $options = ['auth' => ['api', $this->key]]; + $to = $this->getTo($message); + + $message->setBcc([]); + if (version_compare(ClientInterface::VERSION, '6') === 1) { $options['multipart'] = [ - ['name' => 'to', 'contents' => $this->getTo($message)], - ['name' => 'cc', 'contents' => $this->getCc($message)], - ['name' => 'bcc', 'contents' => $this->getBcc($message)], + ['name' => 'to', 'contents' => $to], ['name' => 'message', 'contents' => $message->toString(), 'filename' => 'message.mime'], ]; } else { $options['body'] = [ - 'to' => $this->getTo($message), - 'cc' => $this->getCc($message), - 'bcc' => $this->getBcc($message), + 'to' => $to, 'message' => new PostFile('message', $message->toString()), ]; } @@ -85,45 +85,16 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null) * Get the "to" payload field for the API request. * * @param \Swift_Mime_Message $message - * @return string + * @return array */ protected function getTo(Swift_Mime_Message $message) - { - return $this->formatAddress($message->getTo()); - } - - /** - * Get the "cc" payload field for the API request. - * - * @param \Swift_Mime_Message $message - * @return string - */ - protected function getCc(Swift_Mime_Message $message) - { - return $this->formatAddress($message->getCc()); - } - - /** - * Get the "bcc" payload field for the API request. - * - * @param \Swift_Mime_Message $message - * @return string - */ - protected function getBcc(Swift_Mime_Message $message) - { - return $this->formatAddress($message->getBcc()); - } - - /** - * Get Comma-Separated Address (with name, if available) for the API request. - * - * @param array $contacts - * @return string - */ - protected function formatAddress($contacts) { $formatted = []; + $contacts = array_merge( + (array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc() + ); + foreach ($contacts as $address => $display) { $formatted[] = $display ? $display." <{$address}>" : $address; } From 15c4bb3ddacfb96b483c4da9b4800a276c736cef Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Aug 2016 13:23:51 -0500 Subject: [PATCH 087/249] working on alignmnet --- src/Illuminate/Foundation/Console/stubs/notification.stub | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Console/stubs/notification.stub b/src/Illuminate/Foundation/Console/stubs/notification.stub index db6800c1c4f8..aa06c465d69e 100644 --- a/src/Illuminate/Foundation/Console/stubs/notification.stub +++ b/src/Illuminate/Foundation/Console/stubs/notification.stub @@ -39,7 +39,7 @@ class DummyClass extends Notification public function message() { $this->line('The introduction to the notification.') - ->action('Notification Action', 'https://laravel.com') - ->line('Thank you for using our application!'); + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); } } From df3b77467b57315dba19570e557e30e740864202 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Aug 2016 14:25:27 -0500 Subject: [PATCH 088/249] sort notifications and add unread method --- .../Notifications/HasDatabaseNotifications.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Notifications/HasDatabaseNotifications.php b/src/Illuminate/Notifications/HasDatabaseNotifications.php index d9b8fde4726b..b5b9c0d24f0f 100644 --- a/src/Illuminate/Notifications/HasDatabaseNotifications.php +++ b/src/Illuminate/Notifications/HasDatabaseNotifications.php @@ -9,6 +9,17 @@ trait HasDatabaseNotifications */ public function notifications() { - return $this->morphMany(DatabaseNotification::class, 'notifiable'); + return $this->morphMany(DatabaseNotification::class, 'notifiable') + ->orderBy('created_at', 'desc'); + } + + /** + * Get the entity's unread notifications. + */ + public function unreadNotifications() + { + return $this->morphMany(DatabaseNotification::class, 'notifiable') + ->where('read', false) + ->orderBy('created_at', 'desc'); } } From ee3ad94a4b134d8794f0d94753cdadd3dee2f222 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Aug 2016 21:24:02 -0500 Subject: [PATCH 089/249] remove old property --- src/Illuminate/Notifications/Notification.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index f842aec0a462..08fdd189856f 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -15,11 +15,6 @@ class Notification */ public $notifiables; - /** - * The channels that the notification should be sent through. - */ - public $via = []; - /** * The name of the application sending the notification. * From cb5e9aa241a01e657f80242bb077d78ad4f269bd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 4 Aug 2016 21:47:22 -0500 Subject: [PATCH 090/249] remove updateAny from stub --- src/Illuminate/Foundation/Console/stubs/policy.stub | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Illuminate/Foundation/Console/stubs/policy.stub b/src/Illuminate/Foundation/Console/stubs/policy.stub index 04f73e216413..cbc7535b249b 100644 --- a/src/Illuminate/Foundation/Console/stubs/policy.stub +++ b/src/Illuminate/Foundation/Console/stubs/policy.stub @@ -44,17 +44,6 @@ class DummyClass // } - /** - * Determine whether the user can update dummyPluralModelName. - * - * @param DummyRootNamespaceUser $user - * @return mixed - */ - public function updateAny(User $user) - { - // - } - /** * Determine whether the user can update the dummyModelName. * From b466251bab2759637f893c28677416bd6deaa1a6 Mon Sep 17 00:00:00 2001 From: Johnny van de Laar Date: Fri, 5 Aug 2016 16:05:19 +0200 Subject: [PATCH 091/249] Allow to pass multiple arguments to Authorize. --- src/Illuminate/Auth/Middleware/Authorize.php | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Auth/Middleware/Authorize.php b/src/Illuminate/Auth/Middleware/Authorize.php index 0d1af41b03b3..49cc8fe2e9b2 100644 --- a/src/Illuminate/Auth/Middleware/Authorize.php +++ b/src/Illuminate/Auth/Middleware/Authorize.php @@ -41,17 +41,17 @@ public function __construct(Auth $auth, Gate $gate) * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string $ability - * @param string|null $model + * @param array|null $models * @return mixed * * @throws \Illuminate\Auth\Access\AuthenticationException * @throws \Illuminate\Auth\Access\AuthorizationException */ - public function handle($request, Closure $next, $ability, $model = null) + public function handle($request, Closure $next, $ability, ...$models) { $this->auth->authenticate(); - $this->gate->authorize($ability, $this->getGateArguments($request, $model)); + $this->gate->authorize($ability, $this->getGateArguments($request, $models)); return $next($request); } @@ -60,12 +60,21 @@ public function handle($request, Closure $next, $ability, $model = null) * Get the arguments parameter for the gate. * * @param \Illuminate\Http\Request $request - * @param string|null $model + * @param array|null $models * @return array|string|\Illuminate\Database\Eloquent\Model */ - protected function getGateArguments($request, $model) + protected function getGateArguments($request, $models) { - return is_null($model) ? [] : $this->getModel($request, $model); + if (is_null($models)) { + return []; + } + + $gate_args = []; + foreach ($models as $model) { + $gate_args[] = $this->getModel($request, $model); + } + + return $gate_args; } /** From e4dc61280742e765cbf078455885b9c96b29eaae Mon Sep 17 00:00:00 2001 From: Simon Hunt Date: Fri, 5 Aug 2016 15:47:32 +0100 Subject: [PATCH 092/249] Add visitRoute() to Illuminate\Foundation\Testing\Concerns\InteractsWithPages. (#14630) --- .../Testing/Concerns/InteractsWithPages.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php index 6707403cea4c..e81aa361aa41 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithPages.php @@ -61,6 +61,18 @@ public function visit($uri) return $this->makeRequest('GET', $uri); } + /** + * Visit the given named route with a GET request. + * + * @param string $route + * @param array $parameters + * @return $this + */ + public function visitRoute($route, $parameters = []) + { + return $this->makeRequest('GET', route($route, $parameters)); + } + /** * Make a request to the application and create a Crawler instance. * From 1666d8bee681c84b2b91cebb7c1b62971a26a591 Mon Sep 17 00:00:00 2001 From: Vincent Klaiber Date: Fri, 5 Aug 2016 16:48:10 +0200 Subject: [PATCH 093/249] Update laravel urls with https (#14629) --- CONTRIBUTING.md | 2 +- composer.json | 2 +- readme.md | 4 ++-- src/Illuminate/Auth/composer.json | 2 +- src/Illuminate/Broadcasting/composer.json | 2 +- src/Illuminate/Bus/composer.json | 2 +- src/Illuminate/Cache/composer.json | 2 +- src/Illuminate/Config/composer.json | 2 +- src/Illuminate/Console/composer.json | 2 +- src/Illuminate/Container/composer.json | 2 +- src/Illuminate/Contracts/composer.json | 2 +- src/Illuminate/Cookie/composer.json | 2 +- src/Illuminate/Database/README.md | 2 +- src/Illuminate/Database/composer.json | 2 +- src/Illuminate/Encryption/composer.json | 2 +- src/Illuminate/Events/composer.json | 2 +- src/Illuminate/Filesystem/composer.json | 2 +- src/Illuminate/Hashing/composer.json | 2 +- src/Illuminate/Http/composer.json | 2 +- src/Illuminate/Log/composer.json | 2 +- src/Illuminate/Mail/composer.json | 2 +- src/Illuminate/Notifications/composer.json | 2 +- src/Illuminate/Pagination/composer.json | 2 +- src/Illuminate/Pipeline/composer.json | 2 +- src/Illuminate/Queue/README.md | 2 +- src/Illuminate/Queue/composer.json | 2 +- src/Illuminate/Redis/composer.json | 2 +- src/Illuminate/Routing/composer.json | 2 +- src/Illuminate/Session/composer.json | 2 +- src/Illuminate/Support/composer.json | 2 +- src/Illuminate/Translation/composer.json | 2 +- src/Illuminate/Validation/composer.json | 2 +- src/Illuminate/View/composer.json | 2 +- tests/Validation/ValidationValidatorTest.php | 14 +++++++------- 34 files changed, 41 insertions(+), 41 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2cbf8251054c..500ac3f96bec 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,3 +1,3 @@ # Laravel Contribution Guide -Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions). Please review the entire guide before sending a pull request. +Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). Please review the entire guide before sending a pull request. diff --git a/composer.json b/composer.json index bcbbd3e8bb49..4d14f4174f79 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/readme.md b/readme.md index 76d266ffaf3c..c7d5e0f27848 100644 --- a/readme.md +++ b/readme.md @@ -17,11 +17,11 @@ Laravel is accessible, yet powerful, providing powerful tools needed for large, ## Official Documentation -Documentation for the framework can be found on the [Laravel website](http://laravel.com/docs). +Documentation for the framework can be found on the [Laravel website](https://laravel.com/docs). ## Contributing -Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions). +Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). ## Security Vulnerabilities diff --git a/src/Illuminate/Auth/composer.json b/src/Illuminate/Auth/composer.json index ded351dd3198..08582ba6727d 100644 --- a/src/Illuminate/Auth/composer.json +++ b/src/Illuminate/Auth/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/auth", "description": "The Illuminate Auth package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Broadcasting/composer.json b/src/Illuminate/Broadcasting/composer.json index be0f0204774f..ff1af49db929 100644 --- a/src/Illuminate/Broadcasting/composer.json +++ b/src/Illuminate/Broadcasting/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/broadcasting", "description": "The Illuminate Broadcasting package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Bus/composer.json b/src/Illuminate/Bus/composer.json index f52e5e3ebf8e..805e49f93560 100644 --- a/src/Illuminate/Bus/composer.json +++ b/src/Illuminate/Bus/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/bus", "description": "The Illuminate Bus package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Cache/composer.json b/src/Illuminate/Cache/composer.json index 34d042791b05..568ffb0e8764 100755 --- a/src/Illuminate/Cache/composer.json +++ b/src/Illuminate/Cache/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/cache", "description": "The Illuminate Cache package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Config/composer.json b/src/Illuminate/Config/composer.json index 8c9aff3aebb7..4e44ea7bb79a 100755 --- a/src/Illuminate/Config/composer.json +++ b/src/Illuminate/Config/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/config", "description": "The Illuminate Config package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Console/composer.json b/src/Illuminate/Console/composer.json index c293fa14d48f..f0b4bc02f014 100755 --- a/src/Illuminate/Console/composer.json +++ b/src/Illuminate/Console/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/console", "description": "The Illuminate Console package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Container/composer.json b/src/Illuminate/Container/composer.json index 313f17565574..aa98b334530e 100755 --- a/src/Illuminate/Container/composer.json +++ b/src/Illuminate/Container/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/container", "description": "The Illuminate Container package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Contracts/composer.json b/src/Illuminate/Contracts/composer.json index f6c439f4d6f7..e836001ddcaf 100644 --- a/src/Illuminate/Contracts/composer.json +++ b/src/Illuminate/Contracts/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/contracts", "description": "The Illuminate Contracts package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Cookie/composer.json b/src/Illuminate/Cookie/composer.json index 4e780dadd48a..176cd71fdf06 100755 --- a/src/Illuminate/Cookie/composer.json +++ b/src/Illuminate/Cookie/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/cookie", "description": "The Illuminate Cookie package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Database/README.md b/src/Illuminate/Database/README.md index 1675a9325de9..e7cdeed2c8b4 100755 --- a/src/Illuminate/Database/README.md +++ b/src/Illuminate/Database/README.md @@ -67,4 +67,4 @@ class User extends Illuminate\Database\Eloquent\Model {} $users = User::where('votes', '>', 1)->get(); ``` -For further documentation on using the various database facilities this library provides, consult the [Laravel framework documentation](http://laravel.com/docs). +For further documentation on using the various database facilities this library provides, consult the [Laravel framework documentation](https://laravel.com/docs). diff --git a/src/Illuminate/Database/composer.json b/src/Illuminate/Database/composer.json index 1a1cd2794ab8..7aa0525adcf7 100644 --- a/src/Illuminate/Database/composer.json +++ b/src/Illuminate/Database/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/database", "description": "The Illuminate Database package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Encryption/composer.json b/src/Illuminate/Encryption/composer.json index 74c8740e9a72..481391089a7d 100644 --- a/src/Illuminate/Encryption/composer.json +++ b/src/Illuminate/Encryption/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/encryption", "description": "The Illuminate Encryption package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Events/composer.json b/src/Illuminate/Events/composer.json index 26feba1f0dc4..0605612ddc58 100755 --- a/src/Illuminate/Events/composer.json +++ b/src/Illuminate/Events/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/events", "description": "The Illuminate Events package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Filesystem/composer.json b/src/Illuminate/Filesystem/composer.json index 0de543fa921a..492799d795e6 100644 --- a/src/Illuminate/Filesystem/composer.json +++ b/src/Illuminate/Filesystem/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/filesystem", "description": "The Illuminate Filesystem package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Hashing/composer.json b/src/Illuminate/Hashing/composer.json index f7c2f62cb2cf..8442f35685b1 100755 --- a/src/Illuminate/Hashing/composer.json +++ b/src/Illuminate/Hashing/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/hashing", "description": "The Illuminate Hashing package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Http/composer.json b/src/Illuminate/Http/composer.json index d1fe638244f9..409554dbe3bf 100755 --- a/src/Illuminate/Http/composer.json +++ b/src/Illuminate/Http/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/http", "description": "The Illuminate Http package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Log/composer.json b/src/Illuminate/Log/composer.json index a15c6733876c..0d157d5fe5c9 100755 --- a/src/Illuminate/Log/composer.json +++ b/src/Illuminate/Log/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/log", "description": "The Illuminate Log package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Mail/composer.json b/src/Illuminate/Mail/composer.json index 9d3bf0d60e36..ad96ea5a6bb8 100755 --- a/src/Illuminate/Mail/composer.json +++ b/src/Illuminate/Mail/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/mail", "description": "The Illuminate Mail package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Notifications/composer.json b/src/Illuminate/Notifications/composer.json index 6a9e29c66df2..d21c970dd78d 100644 --- a/src/Illuminate/Notifications/composer.json +++ b/src/Illuminate/Notifications/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/notifications", "description": "The Illuminate Notifications package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Pagination/composer.json b/src/Illuminate/Pagination/composer.json index 882abb09d1e3..96a5af138a77 100755 --- a/src/Illuminate/Pagination/composer.json +++ b/src/Illuminate/Pagination/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/pagination", "description": "The Illuminate Pagination package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Pipeline/composer.json b/src/Illuminate/Pipeline/composer.json index 7a6a8196fa9d..65aff924ff9c 100644 --- a/src/Illuminate/Pipeline/composer.json +++ b/src/Illuminate/Pipeline/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/pipeline", "description": "The Illuminate Pipeline package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Queue/README.md b/src/Illuminate/Queue/README.md index e6a715bc8511..d0f2ba4af0be 100644 --- a/src/Illuminate/Queue/README.md +++ b/src/Illuminate/Queue/README.md @@ -31,4 +31,4 @@ $queue->push('SendEmail', array('message' => $message)); Queue::push('SendEmail', array('message' => $message)); ``` -For further documentation on using the queue, consult the [Laravel framework documentation](http://laravel.com/docs). +For further documentation on using the queue, consult the [Laravel framework documentation](https://laravel.com/docs). diff --git a/src/Illuminate/Queue/composer.json b/src/Illuminate/Queue/composer.json index 33e9f4db9d3d..18ee3ccab332 100644 --- a/src/Illuminate/Queue/composer.json +++ b/src/Illuminate/Queue/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/queue", "description": "The Illuminate Queue package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Redis/composer.json b/src/Illuminate/Redis/composer.json index 72f8f3b2c4b6..c06b4b10bf1d 100755 --- a/src/Illuminate/Redis/composer.json +++ b/src/Illuminate/Redis/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/redis", "description": "The Illuminate Redis package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Routing/composer.json b/src/Illuminate/Routing/composer.json index 9f6b14d6c7dd..2f98fce18212 100644 --- a/src/Illuminate/Routing/composer.json +++ b/src/Illuminate/Routing/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/routing", "description": "The Illuminate Routing package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Session/composer.json b/src/Illuminate/Session/composer.json index b7bd07aab797..8fcbc6d9574e 100755 --- a/src/Illuminate/Session/composer.json +++ b/src/Illuminate/Session/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/session", "description": "The Illuminate Session package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Support/composer.json b/src/Illuminate/Support/composer.json index 0df41454f574..41096f1b8fef 100644 --- a/src/Illuminate/Support/composer.json +++ b/src/Illuminate/Support/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/support", "description": "The Illuminate Support package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Translation/composer.json b/src/Illuminate/Translation/composer.json index c76849de4985..88a77c799166 100755 --- a/src/Illuminate/Translation/composer.json +++ b/src/Illuminate/Translation/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/translation", "description": "The Illuminate Translation package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/Validation/composer.json b/src/Illuminate/Validation/composer.json index 121342caa413..b5cfc39a5458 100755 --- a/src/Illuminate/Validation/composer.json +++ b/src/Illuminate/Validation/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/validation", "description": "The Illuminate Validation package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/src/Illuminate/View/composer.json b/src/Illuminate/View/composer.json index 66b5ebc41386..383f43fee1c2 100644 --- a/src/Illuminate/View/composer.json +++ b/src/Illuminate/View/composer.json @@ -2,7 +2,7 @@ "name": "illuminate/view", "description": "The Illuminate View package.", "license": "MIT", - "homepage": "http://laravel.com", + "homepage": "https://laravel.com", "support": { "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 46c7c8e73b2a..524078dc2971 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1663,16 +1663,16 @@ public function validUrls() ['https://google.com'], ['http://illuminate.dev'], ['http://localhost'], - ['http://laravel.com/?'], + ['https://laravel.com/?'], ['http://президент.рф/'], ['http://스타벅스코리아.com'], ['http://xn--d1abbgf6aiiy.xn--p1ai/'], - ['http://laravel.com?'], - ['http://laravel.com?q=1'], - ['http://laravel.com/?q=1'], - ['http://laravel.com#'], - ['http://laravel.com#fragment'], - ['http://laravel.com/#fragment'], + ['https://laravel.com?'], + ['https://laravel.com?q=1'], + ['https://laravel.com/?q=1'], + ['https://laravel.com#'], + ['https://laravel.com#fragment'], + ['https://laravel.com/#fragment'], ]; } From 6f6a72024671c85a70e7105169c77710dc35c8fa Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Fri, 5 Aug 2016 15:49:58 +0100 Subject: [PATCH 094/249] [5.2] Allow collections to be created from objects that implement Traversable (#14628) * Allow collections to be created from objects that implement Traversable * Style fix; remove exta space character --- src/Illuminate/Support/Collection.php | 3 +++ tests/Support/SupportCollectionTest.php | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 1e341b39c57e..9e741f4e6509 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -4,6 +4,7 @@ use Countable; use ArrayAccess; +use Traversable; use ArrayIterator; use CachingIterator; use JsonSerializable; @@ -1267,6 +1268,8 @@ protected function getArrayableItems($items) return json_decode($items->toJson(), true); } elseif ($items instanceof JsonSerializable) { return $items->jsonSerialize(); + } elseif ($items instanceof Traversable) { + return iterator_to_array($items); } return (array) $items; diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 7745400ecbc9..ea8c1adcb213 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1467,6 +1467,18 @@ public function testSliceNegativeOffsetAndNegativeLength() $collection = new Collection([1, 2, 3, 4, 5, 6, 7, 8]); $this->assertEquals([3, 4, 5, 6], $collection->slice(-6, -2)->values()->toArray()); } + + public function testCollectonFromTraversable() + { + $collection = new Collection(new \ArrayObject([1, 2, 3])); + $this->assertEquals([1, 2, 3], $collection->toArray()); + } + + public function testCollectonFromTraversableWithKeys() + { + $collection = new Collection(new \ArrayObject(['foo' => 1, 'bar' => 2, 'baz' => 3])); + $this->assertEquals(['foo' => 1, 'bar' => 2, 'baz' => 3], $collection->toArray()); + } } class TestAccessorEloquentTestStub From 9bf9319e49c1af372a4021a32eb9eb082eae4367 Mon Sep 17 00:00:00 2001 From: Jelle Breuer Date: Fri, 5 Aug 2016 17:12:31 +0200 Subject: [PATCH 095/249] Added makeHidden method --- src/Illuminate/Database/Eloquent/Model.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 435fb7dcb151..9c5e117d1785 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -2101,6 +2101,23 @@ public function addHidden($attributes = null) $this->hidden = array_merge($this->hidden, $attributes); } + /** + * Make the given, typically visible, attributes hidden. + * + * @param array|string $attributes + * @return $this + */ + public function makeHidden($attributes) + { + $this->visible = array_diff($this->visible, (array) $attributes); + + if (! empty($this->hidden)) { + $this->addHidden($attributes); + } + + return $this; + } + /** * Make the given, typically hidden, attributes visible. * From a00e0fabdc38782cfcf1c735dbc658964cadffd5 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 5 Aug 2016 17:14:25 +0200 Subject: [PATCH 096/249] Add missing docblock --- src/Illuminate/Mail/Mailable.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index a459fbc5fe1a..22312822ff1f 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -345,6 +345,7 @@ public function replyTo($address, $name = null) * * @param object|array|string $address * @param string|null $name + * @param string $property * @return $this */ protected function setAddress($address, $name = null, $property = 'to') From f8e622c1bf54bdb5062186156f11887a0b558cb1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Aug 2016 10:45:19 -0500 Subject: [PATCH 097/249] Tweak default setup of middleware and how authorization methods are called. --- src/Illuminate/Auth/Access/Gate.php | 6 ++---- .../Foundation/Auth/Access/AuthorizesRequests.php | 1 - src/Illuminate/Foundation/Console/stubs/policy.stub | 13 +------------ 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/Illuminate/Auth/Access/Gate.php b/src/Illuminate/Auth/Access/Gate.php index a16966e75e6d..85882567e95d 100644 --- a/src/Illuminate/Auth/Access/Gate.php +++ b/src/Illuminate/Auth/Access/Gate.php @@ -369,11 +369,9 @@ protected function resolvePolicyCallback($user, $ability, array $arguments) } // If the first argument is a string, that means they are passing a class name - // to the policy. We'll append "Any" to this ability name so that users may - // call the policy method with either a class or model name consistently. + // to the policy. We will remove the first argument from this argument list + // because the policy already knows what type of models it can authorize. if (isset($arguments[0]) && is_string($arguments[0])) { - $ability = $ability.'Any'; - array_shift($arguments); } diff --git a/src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php b/src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php index 92ffcbb7ebc2..c678c6e0eeb3 100644 --- a/src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php +++ b/src/Illuminate/Foundation/Auth/Access/AuthorizesRequests.php @@ -98,7 +98,6 @@ public function authorizeResource($model, $parameter = null, array $options = [] protected function resourceAbilityMap() { return [ - 'index' => 'view', 'show' => 'view', 'create' => 'create', 'store' => 'create', diff --git a/src/Illuminate/Foundation/Console/stubs/policy.stub b/src/Illuminate/Foundation/Console/stubs/policy.stub index cbc7535b249b..59dcf5925839 100644 --- a/src/Illuminate/Foundation/Console/stubs/policy.stub +++ b/src/Illuminate/Foundation/Console/stubs/policy.stub @@ -10,17 +10,6 @@ class DummyClass { use HandlesAuthorization; - /** - * Determine whether the user can view dummyPluralModelName. - * - * @param DummyRootNamespaceUser $user - * @return mixed - */ - public function viewAny(User $user) - { - // - } - /** * Determine whether the user can view the dummyModelName. * @@ -39,7 +28,7 @@ class DummyClass * @param DummyRootNamespaceUser $user * @return mixed */ - public function createAny(User $user) + public function create(User $user) { // } From 85779e0e4df16c020868424a4d82eddf831797f3 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Aug 2016 13:39:29 -0500 Subject: [PATCH 098/249] Tweak how channels are handled. --- .../Console/stubs/make/views/layouts/app.stub | 3 ++ .../Broadcasting/BroadcastManager.php | 10 +++--- .../Broadcasting/Broadcasters/Broadcaster.php | 13 +++++++ .../Broadcasters/LogBroadcaster.php | 2 +- .../Broadcasters/PusherBroadcaster.php | 2 +- .../Broadcasters/RedisBroadcaster.php | 2 +- src/Illuminate/Broadcasting/Channel.php | 34 +++++++++++++++++++ .../Broadcasting/PresenceChannel.php | 17 ++++++++++ .../Broadcasting/PrivateChannel.php | 17 ++++++++++ .../Foundation/Console/stubs/event.stub | 5 ++- 10 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 src/Illuminate/Broadcasting/Channel.php create mode 100644 src/Illuminate/Broadcasting/PresenceChannel.php create mode 100644 src/Illuminate/Broadcasting/PrivateChannel.php diff --git a/src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub b/src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub index 71d548a30b11..7c89ec3759f2 100644 --- a/src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub +++ b/src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub @@ -5,6 +5,9 @@ + + + Laravel diff --git a/src/Illuminate/Broadcasting/BroadcastManager.php b/src/Illuminate/Broadcasting/BroadcastManager.php index 8693c7ccb88f..32a6881c2449 100644 --- a/src/Illuminate/Broadcasting/BroadcastManager.php +++ b/src/Illuminate/Broadcasting/BroadcastManager.php @@ -51,15 +51,17 @@ public function __construct($app) * @param array $attributes * @return void */ - public function route(array $attributes = []) + public function routes() { if ($this->app->routesAreCached()) { return; } - $this->app['router']->group($attributes, function () { - $this->app['router']->post('/broadcasting/auth', BroadcastController::class.'@authenticate'); - $this->app['router']->post('/broadcasting/socket', BroadcastController::class.'@rememberSocket'); + $router = $this->app['router']; + + $router->group(['middleware' => ['web']], function () { + $router->post('/broadcasting/auth', BroadcastController::class.'@authenticate'); + $router->post('/broadcasting/socket', BroadcastController::class.'@rememberSocket'); }); } diff --git a/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php index 9607c08e15b1..05e7e47329b6 100644 --- a/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php +++ b/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php @@ -101,4 +101,17 @@ protected function validAuthenticationResponse($request, $result) 'user_info' => $result, ]]); } + + /** + * Format the channel array into an array of strings. + * + * @param array $channels + * @return array + */ + protected function formatChannels(array $channels) + { + return array_map(function ($channel) { + return (string) $channel; + }, $channels); + } } diff --git a/src/Illuminate/Broadcasting/Broadcasters/LogBroadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/LogBroadcaster.php index 3407c9cd78c6..d6c61ff86673 100644 --- a/src/Illuminate/Broadcasting/Broadcasters/LogBroadcaster.php +++ b/src/Illuminate/Broadcasting/Broadcasters/LogBroadcaster.php @@ -29,7 +29,7 @@ public function __construct(LoggerInterface $logger) */ public function broadcast(array $channels, $event, array $payload = []) { - $channels = implode(', ', $channels); + $channels = implode(', ', $this->formatChannels($channels)); $payload = json_encode($payload, JSON_PRETTY_PRINT); diff --git a/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php index 53a7b9215270..17006cc8cad2 100644 --- a/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php +++ b/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php @@ -51,7 +51,7 @@ public function broadcast(array $channels, $event, array $payload = []) { $socket = Arr::pull($payload, 'socket'); - $this->pusher->trigger($channels, $event, $payload, $socket); + $this->pusher->trigger($this->formatChannels($channels), $event, $payload, $socket); } /** diff --git a/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php index fd588aa5bc0c..e00e2653753b 100644 --- a/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php +++ b/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php @@ -47,7 +47,7 @@ public function broadcast(array $channels, $event, array $payload = []) 'event' => $event, 'data' => $payload, 'socket' => $socket, ]); - foreach ($channels as $channel) { + foreach ($this->formatChannels($channels) as $channel) { $connection->publish($channel, $payload); } } diff --git a/src/Illuminate/Broadcasting/Channel.php b/src/Illuminate/Broadcasting/Channel.php new file mode 100644 index 000000000000..798d6026a5f9 --- /dev/null +++ b/src/Illuminate/Broadcasting/Channel.php @@ -0,0 +1,34 @@ +name = $name; + } + + /** + * Convert the channel instance to a string. + * + * @return string + */ + public function __toString() + { + return $this->name; + } +} diff --git a/src/Illuminate/Broadcasting/PresenceChannel.php b/src/Illuminate/Broadcasting/PresenceChannel.php new file mode 100644 index 000000000000..22de12d37f16 --- /dev/null +++ b/src/Illuminate/Broadcasting/PresenceChannel.php @@ -0,0 +1,17 @@ + Date: Fri, 5 Aug 2016 13:42:49 -0500 Subject: [PATCH 099/249] get router in function --- src/Illuminate/Broadcasting/BroadcastManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Broadcasting/BroadcastManager.php b/src/Illuminate/Broadcasting/BroadcastManager.php index 32a6881c2449..250c9a35e8f7 100644 --- a/src/Illuminate/Broadcasting/BroadcastManager.php +++ b/src/Illuminate/Broadcasting/BroadcastManager.php @@ -59,7 +59,7 @@ public function routes() $router = $this->app['router']; - $router->group(['middleware' => ['web']], function () { + $router->group(['middleware' => ['web']], function ($router) { $router->post('/broadcasting/auth', BroadcastController::class.'@authenticate'); $router->post('/broadcasting/socket', BroadcastController::class.'@rememberSocket'); }); From 5c1d07dcb48ea4ba379c557008a3d8b1c6cb73e4 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Aug 2016 15:24:52 -0500 Subject: [PATCH 100/249] Add database notification created event and integrate with broadcasting. --- .../Broadcasting/BroadcastManager.php | 12 +++ .../Broadcasters/NullBroadcaster.php | 14 ++++ .../Channels/DatabaseChannel.php | 26 +++++- .../Events/DatabaseNotificationCreated.php | 81 +++++++++++++++++++ src/Illuminate/Notifications/Notification.php | 8 -- .../NotificationDatabaseChannelTest.php | 5 +- 6 files changed, 136 insertions(+), 10 deletions(-) create mode 100644 src/Illuminate/Broadcasting/Broadcasters/NullBroadcaster.php create mode 100644 src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php diff --git a/src/Illuminate/Broadcasting/BroadcastManager.php b/src/Illuminate/Broadcasting/BroadcastManager.php index 250c9a35e8f7..e44e6f436b7c 100644 --- a/src/Illuminate/Broadcasting/BroadcastManager.php +++ b/src/Illuminate/Broadcasting/BroadcastManager.php @@ -7,6 +7,7 @@ use Illuminate\Support\Arr; use InvalidArgumentException; use Illuminate\Broadcasting\Broadcasters\LogBroadcaster; +use Illuminate\Broadcasting\Broadcasters\NullBroadcaster; use Illuminate\Broadcasting\Broadcasters\RedisBroadcaster; use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster; use Illuminate\Contracts\Broadcasting\Factory as FactoryContract; @@ -225,6 +226,17 @@ protected function createLogDriver(array $config) ); } + /** + * Create an instance of the driver. + * + * @param array $config + * @return \Illuminate\Contracts\Broadcasting\Broadcaster + */ + protected function createNullDriver(array $config) + { + return new NullBroadcaster; + } + /** * Get the connection configuration. * diff --git a/src/Illuminate/Broadcasting/Broadcasters/NullBroadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/NullBroadcaster.php new file mode 100644 index 000000000000..546e3d4cea23 --- /dev/null +++ b/src/Illuminate/Broadcasting/Broadcasters/NullBroadcaster.php @@ -0,0 +1,14 @@ +events = $events; + } + /** * Send the given notification. * @@ -16,7 +36,7 @@ class DatabaseChannel public function send($notifiables, Notification $notification) { foreach ($notifiables as $notifiable) { - $notifiable->routeNotificationFor('database')->create([ + $databaseNotification = $notifiable->routeNotificationFor('database')->create([ 'level' => $notification->level, 'intro' => $notification->introLines, 'outro' => $notification->outroLines, @@ -24,6 +44,10 @@ public function send($notifiables, Notification $notification) 'action_url' => $notification->actionUrl, 'read' => false, ]); + + $this->events->fire(new DatabaseNotificationCreated( + $notifiable, $notification, $databaseNotification + )); } } } diff --git a/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php b/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php new file mode 100644 index 000000000000..15374673fbdf --- /dev/null +++ b/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php @@ -0,0 +1,81 @@ +notifiable = $notifiable; + $this->notification = $notification; + $this->databaseNotification = $databaseNotification; + } + + /** + * Get the channels the event should broadcast on. + * + * @return array + */ + public function broadcastOn() + { + return [new PrivateChannel($this->channelName())]; + } + + /** + * Get the data that should be sent with the broadcasted event. + * + * @return array + */ + public function broadcastWith() + { + return ['notification' => $this->databaseNotification]; + } + + /** + * Get the broadcast channel name for the event. + * + * @return string + */ + protected function channelName() + { + $class = str_replace('\\', '.', get_class($this->notifiable)); + + return $class.'.'.$this->notifiable->getKey(); + } +} diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index 08fdd189856f..2dd5b130c108 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -8,13 +8,6 @@ class Notification { use SerializesModels; - /** - * The entities that should receive the notification. - * - * @var \Illuminate\Support\Collection - */ - public $notifiables; - /** * The name of the application sending the notification. * @@ -224,7 +217,6 @@ public function action($text, $url) public function toArray() { return [ - 'notifiables' => $this->notifiables, 'application' => $this->application, 'logoUrl' => $this->logoUrl, 'level' => $this->level, diff --git a/tests/Notifications/NotificationDatabaseChannelTest.php b/tests/Notifications/NotificationDatabaseChannelTest.php index 9c00a091799e..684217a64a0f 100644 --- a/tests/Notifications/NotificationDatabaseChannelTest.php +++ b/tests/Notifications/NotificationDatabaseChannelTest.php @@ -24,7 +24,10 @@ public function testDatabaseChannelCreatesDatabaseRecordWithProperData() 'read' => false, ]); - $channel = new DatabaseChannel; + $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); + $events->shouldReceive('fire')->once()->with('Illuminate\Notifications\Events\DatabaseNotificationCreated'); + + $channel = new DatabaseChannel($events); $channel->send($notifiables, $notification); } } From e4715edd68a17befebe246dcc20e9b9c689122e6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Aug 2016 15:39:42 -0500 Subject: [PATCH 101/249] Fix a few things. --- .../Notifications/Events/DatabaseNotificationCreated.php | 1 + src/Illuminate/Notifications/composer.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php b/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php index 15374673fbdf..09400d6971e0 100644 --- a/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php +++ b/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php @@ -4,6 +4,7 @@ use Illuminate\Queue\SerializesModels; use Illuminate\Notifications\Notification; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Notifications\DatabaseNotification; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; diff --git a/src/Illuminate/Notifications/composer.json b/src/Illuminate/Notifications/composer.json index d21c970dd78d..285dec42a163 100644 --- a/src/Illuminate/Notifications/composer.json +++ b/src/Illuminate/Notifications/composer.json @@ -16,6 +16,7 @@ "require": { "php": ">=5.6.4", "illuminate/bus": "5.3.*", + "illuminate/broadcasting": "5.3.*", "illuminate/contracts": "5.3.*", "illuminate/support": "5.3.*" }, From a0d89c0fdf5f7d1a1be78be912693dc15f2f62ba Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Aug 2016 17:51:59 -0500 Subject: [PATCH 102/249] separate driver for braodcasting --- .../Notifications/ChannelManager.php | 10 ++++ .../Channels/BroadcastChannel.php | 46 +++++++++++++++++ .../Channels/DatabaseChannel.php | 51 ++++++++----------- .../NotificationBroadcastChannelTest.php | 34 +++++++++++++ .../NotificationDatabaseChannelTest.php | 6 +-- 5 files changed, 112 insertions(+), 35 deletions(-) create mode 100644 src/Illuminate/Notifications/Channels/BroadcastChannel.php create mode 100644 tests/Notifications/NotificationBroadcastChannelTest.php diff --git a/src/Illuminate/Notifications/ChannelManager.php b/src/Illuminate/Notifications/ChannelManager.php index 0b80731eea1d..b95ff2b646e6 100644 --- a/src/Illuminate/Notifications/ChannelManager.php +++ b/src/Illuminate/Notifications/ChannelManager.php @@ -110,6 +110,16 @@ protected function createDatabaseDriver() return $this->app->make(Channels\DatabaseChannel::class); } + /** + * Create an instance of the broadcast driver. + * + * @return \Illuminate\Notifications\Channels\BroadcastChannel + */ + protected function createBroadcastDriver() + { + return $this->app->make(Channels\BroadcastChannel::class); + } + /** * Create an instance of the mail driver. * diff --git a/src/Illuminate/Notifications/Channels/BroadcastChannel.php b/src/Illuminate/Notifications/Channels/BroadcastChannel.php new file mode 100644 index 000000000000..7a02549f451a --- /dev/null +++ b/src/Illuminate/Notifications/Channels/BroadcastChannel.php @@ -0,0 +1,46 @@ +events = $events; + } + + /** + * Send the given notification. + * + * @param \Illuminate\Support\Collection $notifiables + * @param \Illuminate\Notifications\Notification $notification + * @return void + */ + public function send($notifiables, Notification $notification) + { + foreach ($notifiables as $notifiable) { + $databaseNotification = $this->createNotification($notifiable, $notification); + + $this->events->fire(new DatabaseNotificationCreated( + $notifiable, $notification, $databaseNotification + )); + } + } +} diff --git a/src/Illuminate/Notifications/Channels/DatabaseChannel.php b/src/Illuminate/Notifications/Channels/DatabaseChannel.php index 0b07e8a0d340..96d8cfb69a59 100644 --- a/src/Illuminate/Notifications/Channels/DatabaseChannel.php +++ b/src/Illuminate/Notifications/Channels/DatabaseChannel.php @@ -3,51 +3,40 @@ namespace Illuminate\Notifications\Channels; use Illuminate\Notifications\Notification; -use Illuminate\Contracts\Events\Dispatcher; -use Illuminate\Notifications\Events\DatabaseNotificationCreated; class DatabaseChannel { /** - * The event dispatcher. - * - * @var \Illuminate\Contracts\Events\Dispatcher - */ - protected $events; - - /** - * Create a new database channel. + * Send the given notification. * - * @param \Illuminate\Contracts\Events\Dispatcher $events + * @param \Illuminate\Support\Collection $notifiables + * @param \Illuminate\Notifications\Notification $notification * @return void */ - public function __construct(Dispatcher $events) + public function send($notifiables, Notification $notification) { - $this->events = $events; + foreach ($notifiables as $notifiable) { + $this->createNotification($notifiable, $notification); + } } /** - * Send the given notification. + * Create a database notification record for the notifiable. * - * @param \Illuminate\Support\Collection $notifiables + * @param mixed $notifiable * @param \Illuminate\Notifications\Notification $notification - * @return void + * @return \Illuminate\Notifications\DatabaseNotification */ - public function send($notifiables, Notification $notification) + protected function createNotification($notifiable, Notification $notification) { - foreach ($notifiables as $notifiable) { - $databaseNotification = $notifiable->routeNotificationFor('database')->create([ - 'level' => $notification->level, - 'intro' => $notification->introLines, - 'outro' => $notification->outroLines, - 'action_text' => $notification->actionText, - 'action_url' => $notification->actionUrl, - 'read' => false, - ]); - - $this->events->fire(new DatabaseNotificationCreated( - $notifiable, $notification, $databaseNotification - )); - } + return $notifiable->routeNotificationFor('database')->create([ + 'type' => get_class($notification), + 'level' => $notification->level, + 'intro' => $notification->introLines, + 'outro' => $notification->outroLines, + 'action_text' => $notification->actionText, + 'action_url' => $notification->actionUrl, + 'read' => false, + ]); } } diff --git a/tests/Notifications/NotificationBroadcastChannelTest.php b/tests/Notifications/NotificationBroadcastChannelTest.php new file mode 100644 index 000000000000..22d92ad94d95 --- /dev/null +++ b/tests/Notifications/NotificationBroadcastChannelTest.php @@ -0,0 +1,34 @@ +shouldReceive('routeNotificationFor->create')->with([ + 'type' => get_class($notification), + 'level' => 'info', + 'intro' => [], + 'outro' => [], + 'action_text' => null, + 'action_url' => null, + 'read' => false, + ]); + + $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); + $events->shouldReceive('fire')->once()->with('Illuminate\Notifications\Events\DatabaseNotificationCreated'); + + $channel = new BroadcastChannel($events); + $channel->send($notifiables, $notification); + } +} diff --git a/tests/Notifications/NotificationDatabaseChannelTest.php b/tests/Notifications/NotificationDatabaseChannelTest.php index 684217a64a0f..3104f4809c8f 100644 --- a/tests/Notifications/NotificationDatabaseChannelTest.php +++ b/tests/Notifications/NotificationDatabaseChannelTest.php @@ -16,6 +16,7 @@ public function testDatabaseChannelCreatesDatabaseRecordWithProperData() $notifiables = collect([$notifiable = Mockery::mock()]); $notifiable->shouldReceive('routeNotificationFor->create')->with([ + 'type' => get_class($notification), 'level' => 'info', 'intro' => [], 'outro' => [], @@ -24,10 +25,7 @@ public function testDatabaseChannelCreatesDatabaseRecordWithProperData() 'read' => false, ]); - $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); - $events->shouldReceive('fire')->once()->with('Illuminate\Notifications\Events\DatabaseNotificationCreated'); - - $channel = new DatabaseChannel($events); + $channel = new DatabaseChannel; $channel->send($notifiables, $notification); } } From 1020b312c0fdebddaa02a8246ca6e3ed5a8208e9 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Sat, 6 Aug 2016 00:57:59 +0200 Subject: [PATCH 103/249] fixes #14647 by correct digits validation (#14650) --- src/Illuminate/Validation/Validator.php | 4 ++-- tests/Validation/ValidationValidatorTest.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 9fbe01d4ec99..274c7cf0f252 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -1149,7 +1149,7 @@ protected function validateDigits($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'digits'); - return $this->validateNumeric($attribute, $value) + return ! preg_match('/[^0-9]/', $value) && strlen((string) $value) == $parameters[0]; } @@ -1167,7 +1167,7 @@ protected function validateDigitsBetween($attribute, $value, $parameters) $length = strlen((string) $value); - return $this->validateNumeric($attribute, $value) + return ! preg_match('/[^0-9]/', $value) && $length >= $parameters[0] && $length <= $parameters[1]; } diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 524078dc2971..6bf4c01f18e8 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1016,6 +1016,12 @@ public function testValidateDigits() $v = new Validator($trans, ['foo' => '123'], ['foo' => 'Digits:200']); $this->assertFalse($v->passes()); + $v = new Validator($trans, ['foo' => '+2.37'], ['foo' => 'Digits:5']); + $this->assertTrue($v->fails()); + + $v = new Validator($trans, ['foo' => '2e7'], ['foo' => 'Digits:3']); + $this->assertTrue($v->fails()); + $trans = $this->getRealTranslator(); $v = new Validator($trans, ['foo' => '12345'], ['foo' => 'digits_between:1,6']); $this->assertTrue($v->passes()); @@ -1025,6 +1031,9 @@ public function testValidateDigits() $v = new Validator($trans, ['foo' => '123'], ['foo' => 'digits_between:4,5']); $this->assertFalse($v->passes()); + + $v = new Validator($trans, ['foo' => '+12.3'], ['foo' => 'digits_between:1,6']); + $this->assertFalse($v->passes()); } public function testValidateSize() From edaed7601ebbbb5b8caba0e01692015664dcc5f7 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Bertholdo Carucce Date: Fri, 5 Aug 2016 20:51:34 -0300 Subject: [PATCH 104/249] Fix invalid() and valid() methods. (issue #14646) invalid() and valid() methods where returning empty arrays Issue link: https://github.com/laravel/framework/issues/14646 --- src/Illuminate/Validation/Validator.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 274c7cf0f252..3107533b674d 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -527,6 +527,22 @@ protected function validateAttribute($attribute, $rule) } } + /** + * Generate a key map to determine the valid + * and invalid data + * @return array + */ + protected function getMessagesKeyMap() + { + $map = []; + + foreach($this->messages()->toArray() as $key => $message){ + $map []= explode('.', $key)[0]; + } + + return array_flip(array_unique($map)); + } + /** * Returns the data which was valid. * @@ -538,7 +554,7 @@ public function valid() $this->passes(); } - return array_diff_key($this->data, $this->messages()->toArray()); + return array_diff_key($this->data, $this->getMessagesKeyMap()); } /** @@ -552,7 +568,7 @@ public function invalid() $this->passes(); } - return array_intersect_key($this->data, $this->messages()->toArray()); + return array_intersect_key($this->data, $this->getMessagesKeyMap()); } /** From 02c778cc49023f7329ac25ddc8b47fed2da0549a Mon Sep 17 00:00:00 2001 From: Carlos Alberto Bertholdo Carucce Date: Fri, 5 Aug 2016 21:28:48 -0300 Subject: [PATCH 105/249] Update Validator.php --- src/Illuminate/Validation/Validator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 3107533b674d..d9c1660d2cd4 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -529,7 +529,7 @@ protected function validateAttribute($attribute, $rule) /** * Generate a key map to determine the valid - * and invalid data + * and invalid data. * @return array */ protected function getMessagesKeyMap() @@ -537,7 +537,7 @@ protected function getMessagesKeyMap() $map = []; foreach($this->messages()->toArray() as $key => $message){ - $map []= explode('.', $key)[0]; + $map [] = explode('.', $key)[0]; } return array_flip(array_unique($map)); From 46d5c7043ab600300cb69dce82da9c5842ec2609 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Bertholdo Carucce Date: Fri, 5 Aug 2016 21:33:08 -0300 Subject: [PATCH 106/249] Update Validator.php Fixing style --- src/Illuminate/Validation/Validator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index d9c1660d2cd4..75b90ba9cd59 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -536,7 +536,7 @@ protected function getMessagesKeyMap() { $map = []; - foreach($this->messages()->toArray() as $key => $message){ + foreach ($this->messages()->toArray() as $key => $message){ $map [] = explode('.', $key)[0]; } From 65dd3800d50e49561cc6a1d332bf352322aa97b1 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Bertholdo Carucce Date: Fri, 5 Aug 2016 21:35:34 -0300 Subject: [PATCH 107/249] Fixing style --- src/Illuminate/Validation/Validator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 75b90ba9cd59..40516933f65c 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -536,7 +536,7 @@ protected function getMessagesKeyMap() { $map = []; - foreach ($this->messages()->toArray() as $key => $message){ + foreach ($this->messages()->toArray() as $key => $message) { $map [] = explode('.', $key)[0]; } From 7a3efb11aab530eca0ff10d419cf281ed5191fc5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Aug 2016 20:44:43 -0500 Subject: [PATCH 108/249] use message object --- .../Console/stubs/notification.stub | 10 +- .../Notifications/ChannelManager.php | 2 - .../Channels/DatabaseChannel.php | 12 +- .../Notifications/Channels/MailChannel.php | 43 ++-- .../Channels/NexmoSmsChannel.php | 17 +- .../Channels/SlackWebhookChannel.php | 33 +-- src/Illuminate/Notifications/Message.php | 178 ++++++++++++++++ src/Illuminate/Notifications/Notification.php | 200 +++--------------- .../NotificationBroadcastChannelTest.php | 11 +- .../NotificationChannelManagerTest.php | 3 - .../NotificationDatabaseChannelTest.php | 11 +- .../NotificationMailChannelTest.php | 13 +- .../Notifications/NotificationMessageTest.php | 36 ++++ .../NotificationNexmoChannelTest.php | 12 +- .../NotificationNotificationTest.php | 46 ---- .../NotificationSlackChannelTest.php | 21 +- 16 files changed, 347 insertions(+), 301 deletions(-) create mode 100644 src/Illuminate/Notifications/Message.php create mode 100644 tests/Notifications/NotificationMessageTest.php delete mode 100644 tests/Notifications/NotificationNotificationTest.php diff --git a/src/Illuminate/Foundation/Console/stubs/notification.stub b/src/Illuminate/Foundation/Console/stubs/notification.stub index aa06c465d69e..fa573d4e3a2b 100644 --- a/src/Illuminate/Foundation/Console/stubs/notification.stub +++ b/src/Illuminate/Foundation/Console/stubs/notification.stub @@ -34,12 +34,12 @@ class DummyClass extends Notification /** * Get the notification message. * - * @return void + * @return \Illuminate\Notifications\Message */ - public function message() + public function message($notifiable) { - $this->line('The introduction to the notification.') - ->action('Notification Action', 'https://laravel.com') - ->line('Thank you for using our application!'); + return $this->line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); } } diff --git a/src/Illuminate/Notifications/ChannelManager.php b/src/Illuminate/Notifications/ChannelManager.php index b95ff2b646e6..ac059b0b3261 100644 --- a/src/Illuminate/Notifications/ChannelManager.php +++ b/src/Illuminate/Notifications/ChannelManager.php @@ -46,8 +46,6 @@ public function send($notifiables, $notification) */ public function sendNow($notifiables, $notification) { - $notification->message(); - if (! $notification->application) { $notification->application( $this->app['config']['app.name'], diff --git a/src/Illuminate/Notifications/Channels/DatabaseChannel.php b/src/Illuminate/Notifications/Channels/DatabaseChannel.php index 96d8cfb69a59..c40bd2d007c5 100644 --- a/src/Illuminate/Notifications/Channels/DatabaseChannel.php +++ b/src/Illuminate/Notifications/Channels/DatabaseChannel.php @@ -29,13 +29,15 @@ public function send($notifiables, Notification $notification) */ protected function createNotification($notifiable, Notification $notification) { + $message = $notification->message($notifiable); + return $notifiable->routeNotificationFor('database')->create([ 'type' => get_class($notification), - 'level' => $notification->level, - 'intro' => $notification->introLines, - 'outro' => $notification->outroLines, - 'action_text' => $notification->actionText, - 'action_url' => $notification->actionUrl, + 'level' => $message->level, + 'intro' => $message->introLines, + 'outro' => $message->outroLines, + 'action_text' => $message->actionText, + 'action_url' => $message->actionUrl, 'read' => false, ]); } diff --git a/src/Illuminate/Notifications/Channels/MailChannel.php b/src/Illuminate/Notifications/Channels/MailChannel.php index a4abc2a7a123..4f4cf63d378c 100644 --- a/src/Illuminate/Notifications/Channels/MailChannel.php +++ b/src/Illuminate/Notifications/Channels/MailChannel.php @@ -5,6 +5,7 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Contracts\Mail\Mailer; +use Illuminate\Notifications\Message; use Illuminate\Notifications\Notification; class MailChannel @@ -36,39 +37,25 @@ public function __construct(Mailer $mailer) */ public function send($notifiables, Notification $notification) { - $data = $this->prepareNotificationData($notification); - - $emails = $notifiables->map(function ($n) { - return $n->routeNotificationFor('mail'); - })->filter()->all(); - - if (empty($emails)) { - return; - } - $view = data_get($notification, 'options.view', 'notifications::email'); - $this->mailer->send($view, $data, function ($m) use ($notifiables, $notification, $emails) { - count($notifiables) === 1 - ? $m->to($emails) : $m->bcc($emails); + foreach ($notifiables as $notifiable) { + if (! $notifiable->routeNotificationFor('mail')) { + continue; + } - $m->subject($notification->subject ?: Str::title( - Str::snake(class_basename($notification), ' ') - )); - }); - } + $data = $notification->toArray($notifiable); - /** - * Prepare the data from the given notification. - * - * @param \Illuminate\Notifications\Notification $notification - * @return array - */ - protected function prepareNotificationData($notification) - { - $data = $notification->toArray(); + Arr::set($data, 'actionColor', $this->actionColorForLevel($data['level'])); + + $this->mailer->send($view, $data, function ($m) use ($notifiable, $notification) { + $m->to($notifiable->routeNotificationFor('mail')); - return Arr::set($data, 'actionColor', $this->actionColorForLevel($data['level'])); + $m->subject($notification->message($notifiable)->subject ?: Str::title( + Str::snake(class_basename($notification), ' ') + )); + }); + } } /** diff --git a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php index 4c4bd63ae768..0017c67e7833 100644 --- a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php +++ b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php @@ -52,7 +52,7 @@ public function send($notifiables, Notification $notification) $this->nexmo->message()->send([ 'from' => $this->from, 'to' => $to, - 'text' => $this->formatNotification($notification), + 'text' => $this->formatNotification($notifiable, $notification), ]); } } @@ -60,20 +60,21 @@ public function send($notifiables, Notification $notification) /** * Format the given notification to a single string. * + * @param mixed $notifiable * @param \Illuminate\Notifications\Notification $notification * @return string */ - protected function formatNotification(Notification $notification) + protected function formatNotification($notifiable, $notification) { - $data = $notification->toArray(); + $message = $notification->message($notifiable); - $actionText = $notification->actionText - ? $notification->actionText.': ' : ''; + $actionText = $message->actionText + ? $message->actionText.': ' : ''; return trim(implode(PHP_EOL.PHP_EOL, array_filter([ - implode(' ', Arr::get($data, 'introLines', [])), - $actionText.Arr::get($data, 'actionUrl'), - implode(' ', Arr::get($data, 'outroLines', [])), + implode(' ', $message->introLines), + $actionText.$message->actionUrl, + implode(' ', $message->outroLines), ]))); } diff --git a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php index e8e313938601..4e4958d6b4cd 100644 --- a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php +++ b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php @@ -3,6 +3,7 @@ namespace Illuminate\Notifications\Channels; use GuzzleHttp\Client as HttpClient; +use Illuminate\Notifications\Message; use Illuminate\Notifications\Notification; class SlackWebhookChannel @@ -39,14 +40,16 @@ public function send($notifiables, Notification $notification) continue; } + $message = $notification->message($notifiable); + $this->http->post($url, [ 'json' => [ 'attachments' => [ array_filter([ - 'color' => $this->color($notification), - 'title' => $notification->subject, - 'title_link' => $notification->actionUrl ?: null, - 'text' => $this->format($notification), + 'color' => $this->color($message->level), + 'title' => $message->subject, + 'title_link' => $message->actionUrl ?: null, + 'text' => $this->format($message), ]), ], ], @@ -55,33 +58,33 @@ public function send($notifiables, Notification $notification) } /** - * Format the given notification. + * Format the given notification message. * - * @param \Illuminate\Notifications\Notification $notification + * @param \Illuminate\Notifications\Message $message * @return string */ - protected function format(Notification $notification) + protected function format(Message $message) { - $message = trim(implode(PHP_EOL.PHP_EOL, $notification->introLines)); + $text = trim(implode(PHP_EOL.PHP_EOL, $message->introLines)); - if ($notification->actionText) { - $message .= PHP_EOL.PHP_EOL.'<'.$notification->actionUrl.'|'.$notification->actionText.'>'; + if ($message->actionText) { + $text .= PHP_EOL.PHP_EOL.'<'.$message->actionUrl.'|'.$message->actionText.'>'; } - $message .= PHP_EOL.PHP_EOL.trim(implode(PHP_EOL.PHP_EOL, $notification->outroLines)); + $text .= PHP_EOL.PHP_EOL.trim(implode(PHP_EOL.PHP_EOL, $message->outroLines)); - return trim($message); + return trim($text); } /** * Get the color that should be applied to the notification. * - * @param \Illuminate\Notifications\Notification $notification + * @param string $level * @return string|null */ - protected function color(Notification $notification) + protected function color($level) { - switch ($notification->level) { + switch ($level) { case 'success': return 'good'; case 'error': diff --git a/src/Illuminate/Notifications/Message.php b/src/Illuminate/Notifications/Message.php new file mode 100644 index 000000000000..dc8b6249c4c0 --- /dev/null +++ b/src/Illuminate/Notifications/Message.php @@ -0,0 +1,178 @@ +level = 'success'; + + return $this; + } + + /** + * Indicate that the notification gives information about an error. + * + * @return $this + */ + public function error() + { + $this->level = 'error'; + + return $this; + } + + /** + * Set the "level" of the notification (success, error, etc.). + * + * @param string $level + * @return $this + */ + public function level($level) + { + $this->level = $level; + + return $this; + } + + /** + * Set the subject of the notification. + * + * @param string $subject + * @return $this + */ + public function subject($subject) + { + $this->subject = $subject; + + return $this; + } + + /** + * Add a line of text to the notification. + * + * @param \Illuminate\Notifications\Action|string $line + * @return $this + */ + public function line($line) + { + return $this->with($line); + } + + /** + * Add a line of text to the notification. + * + * @param \Illuminate\Notifications\Action|string|array $line + * @return $this + */ + public function with($line) + { + if ($line instanceof Action) { + $this->action($line->text, $line->url); + } elseif (! $this->actionText) { + $this->introLines[] = $this->formatLine($line); + } else { + $this->outroLines[] = $this->formatLine($line); + } + + return $this; + } + + /** + * Format the given line of text. + * + * @param string|array $line + * @return string + */ + protected function formatLine($line) + { + if (is_array($line)) { + return implode(' ', array_map('trim', $line)); + } + + return trim(implode(' ', array_map('trim', explode(PHP_EOL, $line)))); + } + + /** + * Set the notification's options. + * + * @param array $options + * @return $this + */ + public function options(array $options) + { + $this->options = $options; + + return $this; + } + + /** + * Configure the "call to action" button. + * + * @param string $text + * @param string $url + * @return $this + */ + public function action($text, $url) + { + $this->actionText = $text; + $this->actionUrl = $url; + + return $this; + } +} diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index 2dd5b130c108..423b945702e7 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -2,6 +2,7 @@ namespace Illuminate\Notifications; +use BadMethodCallException; use Illuminate\Queue\SerializesModels; class Notification @@ -22,55 +23,6 @@ class Notification */ public $logoUrl; - /** - * The "level" of the notification (info, success, error). - * - * @var string - */ - public $level = 'info'; - - /** - * The subject of the notification. - * - * @var string - */ - public $subject; - - /** - * The "intro" lines of the notification. - * - * @var array - */ - public $introLines = []; - - /** - * The "outro" lines of the notification. - * - * @var array - */ - public $outroLines = []; - - /** - * The text / label for the action. - * - * @var string - */ - public $actionText; - - /** - * The action URL. - * - * @var string - */ - public $actionUrl; - - /** - * The notification's options. - * - * @var array - */ - public $options = []; - /** * Specify the name of the application sending the notification. * @@ -87,144 +39,40 @@ public function application($application, $logoUrl = null) } /** - * Indicate that the notification gives information about a successful operation. - * - * @return $this - */ - public function success() - { - $this->level = 'success'; - - return $this; - } - - /** - * Indicate that the notification gives information about an error. - * - * @return $this - */ - public function error() - { - $this->level = 'error'; - - return $this; - } - - /** - * Set the "level" of the notification (success, error, etc.). - * - * @param string $level - * @return $this - */ - public function level($level) - { - $this->level = $level; - - return $this; - } - - /** - * Set the subject of the notification. - * - * @param string $subject - * @return $this - */ - public function subject($subject) - { - $this->subject = $subject; - - return $this; - } - - /** - * Add a line of text to the notification. - * - * @param \Illuminate\Notifications\Action|string $line - * @return $this - */ - public function line($line) - { - return $this->with($line); - } - - /** - * Add a line of text to the notification. + * Get an array representation of the notification. * - * @param \Illuminate\Notifications\Action|string|array $line - * @return $this + * @param mixed $notifiable + * @return array */ - public function with($line) + public function toArray($notifiable) { - if ($line instanceof Action) { - $this->action($line->text, $line->url); - } elseif (! $this->actionText) { - $this->introLines[] = $this->formatLine($line); - } else { - $this->outroLines[] = $this->formatLine($line); - } + $message = $this->message($notifiable); - return $this; + return [ + 'application' => $this->application, + 'logoUrl' => $this->logoUrl, + 'level' => $message->level, + 'subject' => $message->subject, + 'introLines' => $message->introLines, + 'outroLines' => $message->outroLines, + 'actionText' => $message->actionText, + 'actionUrl' => $message->actionUrl, + ]; } /** - * Format the given line of text. + * Dynamically pass calls to the message class. * - * @param string|array $line - * @return string + * @param string $method + * @param array $parameters + * @return mixed */ - protected function formatLine($line) + public function __call($method, $parameters) { - if (is_array($line)) { - return implode(' ', array_map('trim', $line)); + if (method_exists(Message::class, $method)) { + return (new Message)->{$method}(...$parameters); } - return trim(implode(' ', array_map('trim', explode(PHP_EOL, $line)))); - } - - /** - * Set the notification's options. - * - * @param array $options - * @return $this - */ - public function options(array $options) - { - $this->options = $options; - - return $this; - } - - /** - * Configure the "call to action" button. - * - * @param string $text - * @param string $url - * @return $this - */ - public function action($text, $url) - { - $this->actionText = $text; - $this->actionUrl = $url; - - return $this; - } - - /** - * Get the instance as an array. - * - * @return array - */ - public function toArray() - { - return [ - 'application' => $this->application, - 'logoUrl' => $this->logoUrl, - 'level' => $this->level, - 'subject' => $this->subject, - 'introLines' => $this->introLines, - 'outroLines' => $this->outroLines, - 'actionText' => $this->actionText, - 'actionUrl' => $this->actionUrl, - ]; + throw new BadMethodCallException("Call to undefined method [{$method}]."); } } diff --git a/tests/Notifications/NotificationBroadcastChannelTest.php b/tests/Notifications/NotificationBroadcastChannelTest.php index 22d92ad94d95..a6f56692a209 100644 --- a/tests/Notifications/NotificationBroadcastChannelTest.php +++ b/tests/Notifications/NotificationBroadcastChannelTest.php @@ -1,5 +1,6 @@ shouldReceive('routeNotificationFor->create')->with([ @@ -32,3 +33,11 @@ public function testBroadcastChannelCreatesDatabaseRecordWithProperData() $channel->send($notifiables, $notification); } } + +class NotificationBroadcastChannelTestNotification extends Notification +{ + public function message($notifiable) + { + return new Message; + } +} diff --git a/tests/Notifications/NotificationChannelManagerTest.php b/tests/Notifications/NotificationChannelManagerTest.php index 79540f5bfd13..c67a2bfad21a 100644 --- a/tests/Notifications/NotificationChannelManagerTest.php +++ b/tests/Notifications/NotificationChannelManagerTest.php @@ -23,9 +23,6 @@ public function testNotificationCanBeDispatchedToDriver() $driver->shouldReceive('send')->andReturnUsing(function ($notifiables, $notification) { $this->assertEquals('Name', $notification->application); $this->assertEquals('Logo', $notification->logoUrl); - $this->assertEquals('test', $notification->introLines[0]); - $this->assertEquals('Text', $notification->actionText); - $this->assertEquals('url', $notification->actionUrl); }); $events->shouldReceive('fire')->with(Mockery::type(Illuminate\Notifications\Events\NotificationSent::class)); diff --git a/tests/Notifications/NotificationDatabaseChannelTest.php b/tests/Notifications/NotificationDatabaseChannelTest.php index 3104f4809c8f..f3fc4a2ba2ef 100644 --- a/tests/Notifications/NotificationDatabaseChannelTest.php +++ b/tests/Notifications/NotificationDatabaseChannelTest.php @@ -1,5 +1,6 @@ shouldReceive('routeNotificationFor->create')->with([ @@ -29,3 +30,11 @@ public function testDatabaseChannelCreatesDatabaseRecordWithProperData() $channel->send($notifiables, $notification); } } + +class NotificationDatabaseChannelTestNotification extends Notification +{ + public function message($notifiable) + { + return new Message; + } +} diff --git a/tests/Notifications/NotificationMailChannelTest.php b/tests/Notifications/NotificationMailChannelTest.php index ee80bbda0aba..a6a21c8d3563 100644 --- a/tests/Notifications/NotificationMailChannelTest.php +++ b/tests/Notifications/NotificationMailChannelTest.php @@ -1,5 +1,6 @@ toArray(); + $array = $notification->toArray($notifiable); $array['actionColor'] = 'blue'; $channel = new Illuminate\Notifications\Channels\MailChannel( @@ -35,3 +36,11 @@ class NotificationMailChannelTestNotifiable public $email = 'taylor@laravel.com'; } + +class NotificationMailChannelTestNotification extends Notification +{ + public function message($notifiable) + { + return new Message; + } +} diff --git a/tests/Notifications/NotificationMessageTest.php b/tests/Notifications/NotificationMessageTest.php new file mode 100644 index 000000000000..7f94104d53c8 --- /dev/null +++ b/tests/Notifications/NotificationMessageTest.php @@ -0,0 +1,36 @@ +assertEquals('info', $message->level); + + $message = new Message; + $message->level('error'); + $this->assertEquals('error', $message->level); + } + + public function testMessageFormatsMultiLineText() + { + $message = new Message; + $message->with(' + This is a + single line of text. + '); + + $this->assertEquals('This is a single line of text.', $message->introLines[0]); + + $message = new Message; + $message->with([ + 'This is a', + 'single line of text.', + ]); + + $this->assertEquals('This is a single line of text.', $message->introLines[0]); + } +} diff --git a/tests/Notifications/NotificationNexmoChannelTest.php b/tests/Notifications/NotificationNexmoChannelTest.php index 15e4d16bdce5..dd699cfad7ce 100644 --- a/tests/Notifications/NotificationNexmoChannelTest.php +++ b/tests/Notifications/NotificationNexmoChannelTest.php @@ -11,7 +11,7 @@ public function tearDown() public function testSmsIsSentViaNexmo() { - $notification = new Notification; + $notification = new NotificationNexmoChannelTestNotification; $notifiables = collect([ $notifiable = new NotificationNexmoChannelTestNotifiable, ]); @@ -44,3 +44,13 @@ class NotificationNexmoChannelTestNotifiable use Illuminate\Notifications\Notifiable; public $phone_number = '5555555555'; } + +class NotificationNexmoChannelTestNotification extends Notification +{ + public function message($notifiable) + { + return $this->line('line 1') + ->action('Text', 'url') + ->line('line 2'); + } +} diff --git a/tests/Notifications/NotificationNotificationTest.php b/tests/Notifications/NotificationNotificationTest.php deleted file mode 100644 index 18aaf88530d3..000000000000 --- a/tests/Notifications/NotificationNotificationTest.php +++ /dev/null @@ -1,46 +0,0 @@ -assertEquals('info', $notification->level); - - $notification = new NotificationTestNotification; - $notification->level('error'); - $this->assertEquals('error', $notification->level); - } - - public function testChannelNotificationFormatsMultiLineText() - { - $notification = new Notification([]); - $notification->with(' - This is a - single line of text. - '); - - $this->assertEquals('This is a single line of text.', $notification->introLines[0]); - - $notification = new Notification([]); - $notification->with([ - 'This is a', - 'single line of text.', - ]); - - $this->assertEquals('This is a single line of text.', $notification->introLines[0]); - } -} - - -class NotificationTestNotification extends Notification -{ - public $level = 'error'; -} - -class NotificationTestNotificationWithSubject extends Notification -{ - public $subject = 'Zonda'; -} diff --git a/tests/Notifications/NotificationSlackChannelTest.php b/tests/Notifications/NotificationSlackChannelTest.php index 4b961c27f9ab..a58f356384a5 100644 --- a/tests/Notifications/NotificationSlackChannelTest.php +++ b/tests/Notifications/NotificationSlackChannelTest.php @@ -11,18 +11,11 @@ public function tearDown() public function testCorrectPayloadIsSentToSlack() { - $notification = new Notification; + $notification = new NotificationSlackChannelTestNotification; $notifiables = collect([ $notifiable = new NotificationSlackChannelTestNotifiable, ]); - $notification->subject = 'Subject'; - $notification->level = 'success'; - $notification->introLines = ['line 1']; - $notification->actionText = 'Text'; - $notification->actionUrl = 'url'; - $notification->outroLines = ['line 2']; - $channel = new Illuminate\Notifications\Channels\SlackWebhookChannel( $http = Mockery::mock('GuzzleHttp\Client') ); @@ -59,3 +52,15 @@ public function routeNotificationForSlack() return 'url'; } } + +class NotificationSlackChannelTestNotification extends Notification +{ + public function message($notifiable) + { + return $this->subject('Subject') + ->success() + ->line('line 1') + ->action('Text', 'url') + ->line('line 2'); + } +} From 4bd06ce8b6e585ea96f5aa020f5e7ac022567a3f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 5 Aug 2016 21:45:10 -0400 Subject: [PATCH 109/249] Applied fixes from StyleCI [ci skip] [skip ci] --- src/Illuminate/Notifications/Channels/NexmoSmsChannel.php | 1 - tests/Notifications/NotificationMessageTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php index 0017c67e7833..1fd01e9ee462 100644 --- a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php +++ b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php @@ -2,7 +2,6 @@ namespace Illuminate\Notifications\Channels; -use Illuminate\Support\Arr; use Nexmo\Client as NexmoClient; use Illuminate\Notifications\Notification; diff --git a/tests/Notifications/NotificationMessageTest.php b/tests/Notifications/NotificationMessageTest.php index 7f94104d53c8..e10be66392db 100644 --- a/tests/Notifications/NotificationMessageTest.php +++ b/tests/Notifications/NotificationMessageTest.php @@ -1,7 +1,6 @@ Date: Fri, 5 Aug 2016 20:50:21 -0500 Subject: [PATCH 110/249] Fix type hint --- src/Illuminate/Auth/Notifications/ResetPassword.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Auth/Notifications/ResetPassword.php b/src/Illuminate/Auth/Notifications/ResetPassword.php index 664ef10f9aa9..7484eaef7049 100644 --- a/src/Illuminate/Auth/Notifications/ResetPassword.php +++ b/src/Illuminate/Auth/Notifications/ResetPassword.php @@ -38,7 +38,7 @@ public function via($notifiable) /** * Build the notification message. * - * @return $this + * @return \Illuminate\Notifications\Message */ public function message() { From f35ea22d90a8f7c188f3ecd710d9b4d08354b4d6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 6 Aug 2016 08:47:57 -0500 Subject: [PATCH 111/249] fix type hint --- src/Illuminate/Foundation/Console/stubs/notification.stub | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Foundation/Console/stubs/notification.stub b/src/Illuminate/Foundation/Console/stubs/notification.stub index fa573d4e3a2b..75c116fdbc40 100644 --- a/src/Illuminate/Foundation/Console/stubs/notification.stub +++ b/src/Illuminate/Foundation/Console/stubs/notification.stub @@ -34,6 +34,7 @@ class DummyClass extends Notification /** * Get the notification message. * + * @param mixed $notifiable * @return \Illuminate\Notifications\Message */ public function message($notifiable) From 6f4d59dadabcc7c38e8195c8bff4c22ce47f5d5f Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sat, 6 Aug 2016 16:06:46 +0200 Subject: [PATCH 112/249] [5.3] Fix notifications docblocks and remove useless imports (#14666) * Fix notifications docblocks and remove useless imports * Remove another useless import --- src/Illuminate/Notifications/ChannelManager.php | 4 ++-- src/Illuminate/Notifications/Channels/MailChannel.php | 1 - src/Illuminate/Notifications/Events/NotificationSent.php | 2 -- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Notifications/ChannelManager.php b/src/Illuminate/Notifications/ChannelManager.php index ac059b0b3261..4b8e44274e0c 100644 --- a/src/Illuminate/Notifications/ChannelManager.php +++ b/src/Illuminate/Notifications/ChannelManager.php @@ -73,8 +73,8 @@ public function sendNow($notifiables, $notification) /** * Queue the given notification instances. * - * @param mixed $notification - * @param array[\Illuminate\Notifcations\Channels\Notification] + * @param mixed $notifiables + * @param array[\Illuminate\Notifcations\Channels\Notification] $notification * @return void */ protected function queueNotification($notifiables, $notification) diff --git a/src/Illuminate/Notifications/Channels/MailChannel.php b/src/Illuminate/Notifications/Channels/MailChannel.php index 4f4cf63d378c..c6aff1766238 100644 --- a/src/Illuminate/Notifications/Channels/MailChannel.php +++ b/src/Illuminate/Notifications/Channels/MailChannel.php @@ -5,7 +5,6 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Contracts\Mail\Mailer; -use Illuminate\Notifications\Message; use Illuminate\Notifications\Notification; class MailChannel diff --git a/src/Illuminate/Notifications/Events/NotificationSent.php b/src/Illuminate/Notifications/Events/NotificationSent.php index d27388e39c2e..c1180ebcc685 100644 --- a/src/Illuminate/Notifications/Events/NotificationSent.php +++ b/src/Illuminate/Notifications/Events/NotificationSent.php @@ -2,8 +2,6 @@ namespace Illuminate\Notifications\Events; -use Illuminate\Notifications\Notification; - class NotificationSent { /** From cf8065ccd0bd3aec5d19483aec85f3ecd2936407 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Sat, 6 Aug 2016 16:08:02 +0200 Subject: [PATCH 113/249] support dot notation in Request::exists() to fix #14643 (#14660) --- src/Illuminate/Http/Request.php | 2 +- tests/Http/HttpRequestTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index fcf0bf4532b9..555dddb75a95 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -273,7 +273,7 @@ public function exists($key) $input = $this->all(); foreach ($keys as $value) { - if (! array_key_exists($value, $input)) { + if (! Arr::has($input, $value)) { return false; } } diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index cea56ec146c7..333c459c5ac3 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -204,6 +204,10 @@ public function testExistsMethod() $request = Request::create('/', 'GET', ['foo' => '', 'bar' => null]); $this->assertTrue($request->exists('foo')); $this->assertTrue($request->exists('bar')); + + $request = Request::create('/', 'GET', ['foo' => ['bar' => null, 'baz' => '']]); + $this->assertTrue($request->exists('foo.bar')); + $this->assertTrue($request->exists('foo.baz')); } public function testHasMethod() @@ -220,6 +224,9 @@ public function testHasMethod() //test arrays within query string $request = Request::create('/', 'GET', ['foo' => ['bar', 'baz']]); $this->assertTrue($request->has('foo')); + + $request = Request::create('/', 'GET', ['foo' => ['bar' => 'baz']]); + $this->assertTrue($request->has('foo.bar')); } public function testInputMethod() From dec6941c4eb96bd76dea3167b2d4584c9f561617 Mon Sep 17 00:00:00 2001 From: Darwin Luague Date: Sat, 6 Aug 2016 22:08:21 +0800 Subject: [PATCH 114/249] [5.3] Fix undefined variable: request (#14659) Injected Illuminate\Http\Request in sendResetFailedResponse() method. --- src/Illuminate/Foundation/Auth/ResetsPasswords.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Auth/ResetsPasswords.php b/src/Illuminate/Foundation/Auth/ResetsPasswords.php index 7f4105474547..cf79ace0bc45 100644 --- a/src/Illuminate/Foundation/Auth/ResetsPasswords.php +++ b/src/Illuminate/Foundation/Auth/ResetsPasswords.php @@ -54,7 +54,7 @@ public function reset(Request $request) // redirect them back to where they came from with their error message. return $response == Password::PASSWORD_RESET ? $this->sendResetResponse($response) - : $this->sendResetFailedResponse($response); + : $this->sendResetFailedResponse($request, $response); } /** @@ -102,10 +102,11 @@ protected function sendResetResponse($response) /** * Get the response for a failed password reset. * + * @param \Illuminate\Http\Request * @param string $response * @return \Illuminate\Http\Response */ - protected function sendResetFailedResponse($response) + protected function sendResetFailedResponse(Request $request, $response) { return redirect()->back() ->withInput($request->only('email')) From 7e9f3f49228c6fe4522eaf959f2966997156be74 Mon Sep 17 00:00:00 2001 From: Flugger Date: Sat, 6 Aug 2016 22:48:58 +0200 Subject: [PATCH 115/249] Arrange imports by length --- src/Illuminate/Database/Eloquent/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 8f482a950620..20207e328154 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -2,8 +2,8 @@ namespace Illuminate\Database\Eloquent; -use BadMethodCallException; use Closure; +use BadMethodCallException; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Pagination\Paginator; From c1660800c7ed95bb520e9ffce1022152a0fbc14c Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Sat, 6 Aug 2016 15:54:49 -0500 Subject: [PATCH 116/249] Refactor away from call_user_func[_array] - in Pipeline and Routing/Router --- src/Illuminate/Pipeline/Pipeline.php | 14 ++++++++++---- src/Illuminate/Routing/Pipeline.php | 6 +++--- src/Illuminate/Routing/Route.php | 11 ++++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Illuminate/Pipeline/Pipeline.php b/src/Illuminate/Pipeline/Pipeline.php index d15c78a761b7..3f880c5e0c9b 100644 --- a/src/Illuminate/Pipeline/Pipeline.php +++ b/src/Illuminate/Pipeline/Pipeline.php @@ -99,9 +99,8 @@ public function then(Closure $destination) $pipes = array_reverse($this->pipes); - return call_user_func( - array_reduce($pipes, $this->getSlice(), $firstSlice), $this->passable - ); + $callable = array_reduce($pipes, $this->getSlice(), $firstSlice); + return $callable($this->passable); } /** @@ -134,7 +133,14 @@ protected function getSlice() $parameters = [$passable, $stack]; } - return call_user_func_array([$pipe, $this->method], $parameters); + switch (count($parameters)) { + case 0: return $pipe->{$this->method}(); + case 1: return $pipe->{$this->method}($parameters[0]); + case 2: return $pipe->{$this->method}($parameters[0], $parameters[1]); + case 3: return $pipe->{$this->method}($parameters[0], $parameters[1], $parameters[2]); + case 4: return $pipe->{$this->method}($parameters[0], $parameters[1], $parameters[2], $parameters[3]); + default: return call_user_func_array([$pipe, $this->method], $parameters); + } }; }; } diff --git a/src/Illuminate/Routing/Pipeline.php b/src/Illuminate/Routing/Pipeline.php index 1d928c7b0b93..fa33dc4e3a6f 100644 --- a/src/Illuminate/Routing/Pipeline.php +++ b/src/Illuminate/Routing/Pipeline.php @@ -28,8 +28,8 @@ protected function getSlice() return function ($passable) use ($stack, $pipe) { try { $slice = parent::getSlice(); - - return call_user_func($slice($stack, $pipe), $passable); + $callable = $slice($stack, $pipe); + return $callable($passable); } catch (Exception $e) { return $this->handleException($passable, $e); } catch (Throwable $e) { @@ -49,7 +49,7 @@ protected function getInitialSlice(Closure $destination) { return function ($passable) use ($destination) { try { - return call_user_func($destination, $passable); + return $destination($passable); } catch (Exception $e) { return $this->handleException($passable, $e); } catch (Throwable $e) { diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index 2a25a891cba2..653d0739c8bb 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -171,7 +171,16 @@ protected function runCallable() $this->parametersWithoutNulls(), new ReflectionFunction($this->action['uses']) ); - return call_user_func_array($this->action['uses'], $parameters); + $callable = $this->action['uses']; + $parameters = array_values($parameters); + switch (count($parameters)) { + case 0: return $callable(); + case 1: return $callable($parameters[0]); + case 2: return $callable($parameters[0], $parameters[1]); + case 3: return $callable($parameters[0], $parameters[1], $parameters[2]); + case 4: return $callable($parameters[0], $parameters[1], $parameters[2], $parameters[3]); + default: return call_user_func_array($callable, $parameters); + } } /** From 713cd059c29fee2690dbfc52feaa3daf709dc338 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Sat, 6 Aug 2016 16:18:19 -0500 Subject: [PATCH 117/249] Style fixes --- src/Illuminate/Pipeline/Pipeline.php | 2 +- src/Illuminate/Routing/Pipeline.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Pipeline/Pipeline.php b/src/Illuminate/Pipeline/Pipeline.php index 3f880c5e0c9b..cbfb3d78b422 100644 --- a/src/Illuminate/Pipeline/Pipeline.php +++ b/src/Illuminate/Pipeline/Pipeline.php @@ -98,8 +98,8 @@ public function then(Closure $destination) $firstSlice = $this->getInitialSlice($destination); $pipes = array_reverse($this->pipes); - $callable = array_reduce($pipes, $this->getSlice(), $firstSlice); + return $callable($this->passable); } diff --git a/src/Illuminate/Routing/Pipeline.php b/src/Illuminate/Routing/Pipeline.php index fa33dc4e3a6f..665be660f63e 100644 --- a/src/Illuminate/Routing/Pipeline.php +++ b/src/Illuminate/Routing/Pipeline.php @@ -29,6 +29,7 @@ protected function getSlice() try { $slice = parent::getSlice(); $callable = $slice($stack, $pipe); + return $callable($passable); } catch (Exception $e) { return $this->handleException($passable, $e); From 57e308a4599f4cc9b71fb0bfd6fe6cfa70f9fe4a Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Sat, 6 Aug 2016 16:31:22 -0500 Subject: [PATCH 118/249] Changes From Review: - use php 5.6 argument unpacking (splat) in favor of switch statement - remove one other call_user_func call previously missed --- src/Illuminate/Pipeline/Pipeline.php | 13 +++---------- src/Illuminate/Routing/Route.php | 10 +--------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/Illuminate/Pipeline/Pipeline.php b/src/Illuminate/Pipeline/Pipeline.php index cbfb3d78b422..0d53c6e1a63b 100644 --- a/src/Illuminate/Pipeline/Pipeline.php +++ b/src/Illuminate/Pipeline/Pipeline.php @@ -116,7 +116,7 @@ protected function getSlice() // If the pipe is an instance of a Closure, we will just call it directly but // otherwise we'll resolve the pipes out of the container and call it with // the appropriate method and arguments, returning the results back out. - return call_user_func($pipe, $passable, $stack); + return $pipe($passable, $stack); } elseif (! is_object($pipe)) { list($name, $parameters) = $this->parsePipeString($pipe); @@ -133,14 +133,7 @@ protected function getSlice() $parameters = [$passable, $stack]; } - switch (count($parameters)) { - case 0: return $pipe->{$this->method}(); - case 1: return $pipe->{$this->method}($parameters[0]); - case 2: return $pipe->{$this->method}($parameters[0], $parameters[1]); - case 3: return $pipe->{$this->method}($parameters[0], $parameters[1], $parameters[2]); - case 4: return $pipe->{$this->method}($parameters[0], $parameters[1], $parameters[2], $parameters[3]); - default: return call_user_func_array([$pipe, $this->method], $parameters); - } + return $pipe->{$this->method}(...$parameters); }; }; } @@ -154,7 +147,7 @@ protected function getSlice() protected function getInitialSlice(Closure $destination) { return function ($passable) use ($destination) { - return call_user_func($destination, $passable); + return $destination($passable); }; } diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index 653d0739c8bb..3e736520fe60 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -172,15 +172,7 @@ protected function runCallable() ); $callable = $this->action['uses']; - $parameters = array_values($parameters); - switch (count($parameters)) { - case 0: return $callable(); - case 1: return $callable($parameters[0]); - case 2: return $callable($parameters[0], $parameters[1]); - case 3: return $callable($parameters[0], $parameters[1], $parameters[2]); - case 4: return $callable($parameters[0], $parameters[1], $parameters[2], $parameters[3]); - default: return call_user_func_array($callable, $parameters); - } + return $callable(...array_values($parameters)); } /** From 34ad23e3a2d5a8574dcb921bed6cb3352168460f Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Sat, 6 Aug 2016 16:32:44 -0500 Subject: [PATCH 119/249] Style fixes --- src/Illuminate/Routing/Route.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index 3e736520fe60..7d40afa48858 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -172,6 +172,7 @@ protected function runCallable() ); $callable = $this->action['uses']; + return $callable(...array_values($parameters)); } From 3214b22229fac941575d5c5e7985eb541c3953ff Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sun, 7 Aug 2016 19:21:08 +0200 Subject: [PATCH 120/249] Use proper assertions (#14672) --- tests/Database/DatabaseQueryBuilderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 59c8da84e99d..b7b731a4e001 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -1245,7 +1245,7 @@ public function testUpdateOrInsertMethod() $builder->shouldReceive('exists')->once()->andReturn(false); $builder->shouldReceive('insert')->once()->with(['email' => 'foo', 'name' => 'bar'])->andReturn(true); - $this->assertEquals(true, $builder->updateOrInsert(['email' => 'foo'], ['name' => 'bar'])); + $this->assertTrue($builder->updateOrInsert(['email' => 'foo'], ['name' => 'bar'])); $builder = m::mock('Illuminate\Database\Query\Builder[where,exists,update]', [ m::mock('Illuminate\Database\ConnectionInterface'), @@ -1258,7 +1258,7 @@ public function testUpdateOrInsertMethod() $builder->shouldReceive('take')->andReturnSelf(); $builder->shouldReceive('update')->once()->with(['name' => 'bar'])->andReturn(1); - $this->assertEquals(true, $builder->updateOrInsert(['email' => 'foo'], ['name' => 'bar'])); + $this->assertTrue($builder->updateOrInsert(['email' => 'foo'], ['name' => 'bar'])); } public function testDeleteMethod() From 7d9bdd63aedaac480baee4d77bbdada5ae834733 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Aug 2016 12:26:10 -0500 Subject: [PATCH 121/249] formatting --- src/Illuminate/Pipeline/Pipeline.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Pipeline/Pipeline.php b/src/Illuminate/Pipeline/Pipeline.php index 0d53c6e1a63b..ffc0f6d896bd 100644 --- a/src/Illuminate/Pipeline/Pipeline.php +++ b/src/Illuminate/Pipeline/Pipeline.php @@ -97,8 +97,9 @@ public function then(Closure $destination) { $firstSlice = $this->getInitialSlice($destination); - $pipes = array_reverse($this->pipes); - $callable = array_reduce($pipes, $this->getSlice(), $firstSlice); + $callable = array_reduce( + array_reverse($this->pipes), $this->getSlice(), $firstSlice + ); return $callable($this->passable); } From e7489a2d30f6039396ea3dcfaa27bb51f453a710 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Sun, 7 Aug 2016 19:26:46 +0200 Subject: [PATCH 122/249] Alias View as ViewContract (#14673) --- src/Illuminate/View/Factory.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/View/Factory.php b/src/Illuminate/View/Factory.php index 3d016f0ccd2d..7a4f6fdcb46d 100755 --- a/src/Illuminate/View/Factory.php +++ b/src/Illuminate/View/Factory.php @@ -11,6 +11,7 @@ use Illuminate\View\Engines\EngineResolver; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Container\Container; +use Illuminate\Contracts\View\View as ViewContract; use Illuminate\Contracts\View\Factory as FactoryContract; class Factory implements FactoryContract @@ -513,7 +514,7 @@ protected function parseClassEvent($class, $prefix) * @param \Illuminate\Contracts\View\View $view * @return void */ - public function callComposer(View $view) + public function callComposer(ViewContract $view) { $this->events->fire('composing: '.$view->getName(), [$view]); } @@ -524,7 +525,7 @@ public function callComposer(View $view) * @param \Illuminate\Contracts\View\View $view * @return void */ - public function callCreator(View $view) + public function callCreator(ViewContract $view) { $this->events->fire('creating: '.$view->getName(), [$view]); } From 0fafba901c49b0f449927bbca1a8ed16abc56fb7 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 7 Aug 2016 18:33:51 +0100 Subject: [PATCH 123/249] Added a way to get the size of the queue (#14662) --- src/Illuminate/Contracts/Queue/Queue.php | 8 ++++++++ src/Illuminate/Queue/BeanstalkdQueue.php | 13 +++++++++++++ src/Illuminate/Queue/DatabaseQueue.php | 13 +++++++++++++ src/Illuminate/Queue/NullQueue.php | 11 +++++++++++ src/Illuminate/Queue/RedisQueue.php | 11 +++++++++++ src/Illuminate/Queue/SqsQueue.php | 13 +++++++++++++ src/Illuminate/Queue/SyncQueue.php | 11 +++++++++++ 7 files changed, 80 insertions(+) diff --git a/src/Illuminate/Contracts/Queue/Queue.php b/src/Illuminate/Contracts/Queue/Queue.php index 3f9e38304720..6fdfd13a0ea1 100644 --- a/src/Illuminate/Contracts/Queue/Queue.php +++ b/src/Illuminate/Contracts/Queue/Queue.php @@ -63,4 +63,12 @@ public function laterOn($queue, $delay, $job, $data = ''); * @return \Illuminate\Contracts\Queue\Job|null */ public function pop($queue = null); + + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null); } diff --git a/src/Illuminate/Queue/BeanstalkdQueue.php b/src/Illuminate/Queue/BeanstalkdQueue.php index ad090acdda3d..3c6cd61ba723 100755 --- a/src/Illuminate/Queue/BeanstalkdQueue.php +++ b/src/Illuminate/Queue/BeanstalkdQueue.php @@ -108,6 +108,19 @@ public function pop($queue = null) } } + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + $queue = $this->getQueue($queue); + + return (int) $this->pheanstalk->statsTube($queue)->total_jobs; + } + /** * Delete a message from the Beanstalk queue. * diff --git a/src/Illuminate/Queue/DatabaseQueue.php b/src/Illuminate/Queue/DatabaseQueue.php index 46ef36deeb7c..555c913548d2 100644 --- a/src/Illuminate/Queue/DatabaseQueue.php +++ b/src/Illuminate/Queue/DatabaseQueue.php @@ -174,6 +174,19 @@ public function pop($queue = null) $this->database->commit(); } + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + return $this->database->table($this->table) + ->where('queue', $this->getQueue($queue)) + ->count(); + } + /** * Get the next available job for the queue. * diff --git a/src/Illuminate/Queue/NullQueue.php b/src/Illuminate/Queue/NullQueue.php index bdef6cc4c05c..ab6c3fecf1b3 100644 --- a/src/Illuminate/Queue/NullQueue.php +++ b/src/Illuminate/Queue/NullQueue.php @@ -56,4 +56,15 @@ public function pop($queue = null) { // } + + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + return 0; + } } diff --git a/src/Illuminate/Queue/RedisQueue.php b/src/Illuminate/Queue/RedisQueue.php index 54d567490cd2..14630970f92a 100644 --- a/src/Illuminate/Queue/RedisQueue.php +++ b/src/Illuminate/Queue/RedisQueue.php @@ -131,6 +131,17 @@ public function pop($queue = null) } } + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + return (int) $this->getConnection()->llen($this->getQueue($queue)); + } + /** * Delete a reserved job from the queue. * diff --git a/src/Illuminate/Queue/SqsQueue.php b/src/Illuminate/Queue/SqsQueue.php index 791b323be2a6..5dacbdc73eee 100755 --- a/src/Illuminate/Queue/SqsQueue.php +++ b/src/Illuminate/Queue/SqsQueue.php @@ -116,6 +116,19 @@ public function pop($queue = null) } } + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + return (int) $this->sqs->getQueueAttributes([ + 'QueueUrl' => $this->getQueue($queue), + ])->get('ApproximateNumberOfMessages'); + } + /** * Get the queue or return the default. * diff --git a/src/Illuminate/Queue/SyncQueue.php b/src/Illuminate/Queue/SyncQueue.php index fac46a002946..4feef1c09392 100755 --- a/src/Illuminate/Queue/SyncQueue.php +++ b/src/Illuminate/Queue/SyncQueue.php @@ -94,6 +94,17 @@ public function pop($queue = null) // } + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + return 0; + } + /** * Resolve a Sync job instance. * From 43da8262bb1056ecf9b89c8fe4e11254f4e580f5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Aug 2016 12:35:50 -0500 Subject: [PATCH 124/249] formatting --- src/Illuminate/Contracts/Queue/Queue.php | 16 +++++++-------- src/Illuminate/Queue/BeanstalkdQueue.php | 26 ++++++++++++------------ src/Illuminate/Queue/DatabaseQueue.php | 26 ++++++++++++------------ src/Illuminate/Queue/NullQueue.php | 22 ++++++++++---------- src/Illuminate/Queue/RedisQueue.php | 22 ++++++++++---------- src/Illuminate/Queue/SqsQueue.php | 26 ++++++++++++------------ src/Illuminate/Queue/SyncQueue.php | 22 ++++++++++---------- 7 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/Illuminate/Contracts/Queue/Queue.php b/src/Illuminate/Contracts/Queue/Queue.php index 6fdfd13a0ea1..b5b5c9427c14 100644 --- a/src/Illuminate/Contracts/Queue/Queue.php +++ b/src/Illuminate/Contracts/Queue/Queue.php @@ -4,6 +4,14 @@ interface Queue { + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null); + /** * Push a new job onto the queue. * @@ -63,12 +71,4 @@ public function laterOn($queue, $delay, $job, $data = ''); * @return \Illuminate\Contracts\Queue\Job|null */ public function pop($queue = null); - - /** - * Get the size of the queue. - * - * @param string $queue - * @return int - */ - public function size($queue = null); } diff --git a/src/Illuminate/Queue/BeanstalkdQueue.php b/src/Illuminate/Queue/BeanstalkdQueue.php index 3c6cd61ba723..a4d1a949e88c 100755 --- a/src/Illuminate/Queue/BeanstalkdQueue.php +++ b/src/Illuminate/Queue/BeanstalkdQueue.php @@ -45,6 +45,19 @@ public function __construct(Pheanstalk $pheanstalk, $default, $timeToRun) $this->pheanstalk = $pheanstalk; } + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + $queue = $this->getQueue($queue); + + return (int) $this->pheanstalk->statsTube($queue)->total_jobs; + } + /** * Push a new job onto the queue. * @@ -108,19 +121,6 @@ public function pop($queue = null) } } - /** - * Get the size of the queue. - * - * @param string $queue - * @return int - */ - public function size($queue = null) - { - $queue = $this->getQueue($queue); - - return (int) $this->pheanstalk->statsTube($queue)->total_jobs; - } - /** * Delete a message from the Beanstalk queue. * diff --git a/src/Illuminate/Queue/DatabaseQueue.php b/src/Illuminate/Queue/DatabaseQueue.php index 555c913548d2..d6298db5b482 100644 --- a/src/Illuminate/Queue/DatabaseQueue.php +++ b/src/Illuminate/Queue/DatabaseQueue.php @@ -55,6 +55,19 @@ public function __construct(Connection $database, $table, $default = 'default', $this->database = $database; } + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + return $this->database->table($this->table) + ->where('queue', $this->getQueue($queue)) + ->count(); + } + /** * Push a new job onto the queue. * @@ -174,19 +187,6 @@ public function pop($queue = null) $this->database->commit(); } - /** - * Get the size of the queue. - * - * @param string $queue - * @return int - */ - public function size($queue = null) - { - return $this->database->table($this->table) - ->where('queue', $this->getQueue($queue)) - ->count(); - } - /** * Get the next available job for the queue. * diff --git a/src/Illuminate/Queue/NullQueue.php b/src/Illuminate/Queue/NullQueue.php index ab6c3fecf1b3..a42b8ce9b05b 100644 --- a/src/Illuminate/Queue/NullQueue.php +++ b/src/Illuminate/Queue/NullQueue.php @@ -6,6 +6,17 @@ class NullQueue extends Queue implements QueueContract { + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + return 0; + } + /** * Push a new job onto the queue. * @@ -56,15 +67,4 @@ public function pop($queue = null) { // } - - /** - * Get the size of the queue. - * - * @param string $queue - * @return int - */ - public function size($queue = null) - { - return 0; - } } diff --git a/src/Illuminate/Queue/RedisQueue.php b/src/Illuminate/Queue/RedisQueue.php index 14630970f92a..f336703613af 100644 --- a/src/Illuminate/Queue/RedisQueue.php +++ b/src/Illuminate/Queue/RedisQueue.php @@ -56,6 +56,17 @@ public function __construct(Database $redis, $default = 'default', $this->connection = $connection; } + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + return (int) $this->getConnection()->llen($this->getQueue($queue)); + } + /** * Push a new job onto the queue. * @@ -131,17 +142,6 @@ public function pop($queue = null) } } - /** - * Get the size of the queue. - * - * @param string $queue - * @return int - */ - public function size($queue = null) - { - return (int) $this->getConnection()->llen($this->getQueue($queue)); - } - /** * Delete a reserved job from the queue. * diff --git a/src/Illuminate/Queue/SqsQueue.php b/src/Illuminate/Queue/SqsQueue.php index 5dacbdc73eee..f7add815ce2e 100755 --- a/src/Illuminate/Queue/SqsQueue.php +++ b/src/Illuminate/Queue/SqsQueue.php @@ -44,6 +44,19 @@ public function __construct(SqsClient $sqs, $default, $prefix = '') $this->default = $default; } + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + return (int) $this->sqs->getQueueAttributes([ + 'QueueUrl' => $this->getQueue($queue), + ])->get('ApproximateNumberOfMessages'); + } + /** * Push a new job onto the queue. * @@ -116,19 +129,6 @@ public function pop($queue = null) } } - /** - * Get the size of the queue. - * - * @param string $queue - * @return int - */ - public function size($queue = null) - { - return (int) $this->sqs->getQueueAttributes([ - 'QueueUrl' => $this->getQueue($queue), - ])->get('ApproximateNumberOfMessages'); - } - /** * Get the queue or return the default. * diff --git a/src/Illuminate/Queue/SyncQueue.php b/src/Illuminate/Queue/SyncQueue.php index 4feef1c09392..75b023abbbe2 100755 --- a/src/Illuminate/Queue/SyncQueue.php +++ b/src/Illuminate/Queue/SyncQueue.php @@ -11,6 +11,17 @@ class SyncQueue extends Queue implements QueueContract { + /** + * Get the size of the queue. + * + * @param string $queue + * @return int + */ + public function size($queue = null) + { + return 0; + } + /** * Push a new job onto the queue. * @@ -94,17 +105,6 @@ public function pop($queue = null) // } - /** - * Get the size of the queue. - * - * @param string $queue - * @return int - */ - public function size($queue = null) - { - return 0; - } - /** * Resolve a Sync job instance. * From 5a5eba633ba75cf22154ef232e3cb7339766035f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Nabia=C5=82ek?= Date: Sun, 7 Aug 2016 19:36:48 +0200 Subject: [PATCH 125/249] [5.3] Add uniqueStrict method (#14661) * [5.3] Add uniqueStrict method * Style fix --- src/Illuminate/Support/Collection.php | 25 +++++++++++++++++++++ tests/Support/SupportCollectionTest.php | 29 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 9e741f4e6509..a4714336aa14 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -1058,6 +1058,31 @@ public function unique($key = null) }); } + /** + * Return only unique items from the collection array using strict comparison. + * + * @param string|callable|null $key + * @return static + */ + public function uniqueStrict($key = null) + { + if (is_null($key)) { + return new static(array_unique($this->items, SORT_REGULAR)); + } + + $key = $this->valueRetriever($key); + + $exists = []; + + return $this->reject(function ($item) use ($key, &$exists) { + if (in_array($id = $key($item), $exists, true)) { + return true; + } + + $exists[] = $id; + }); + } + /** * Reset the keys on the underlying array. * diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index ea8c1adcb213..586686fa75cf 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -543,6 +543,35 @@ public function testUniqueWithCallback() })->all()); } + public function testUniqueStrict() + { + $c = new Collection([ + [ + 'id' => '0', + 'name' => 'zero', + ], + [ + 'id' => '00', + 'name' => 'double zero', + ], + [ + 'id' => '0', + 'name' => 'again zero', + ], + ]); + + $this->assertEquals([ + [ + 'id' => '0', + 'name' => 'zero', + ], + [ + 'id' => '00', + 'name' => 'double zero', + ], + ], $c->uniqueStrict('id')->all()); + } + public function testCollapse() { $data = new Collection([[$object1 = new StdClass], [$object2 = new StdClass]]); From 74d8e414023f7f808b7a485d3629bb5ef48897a4 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Aug 2016 13:36:55 -0400 Subject: [PATCH 126/249] Applied fixes from StyleCI [ci skip] [skip ci] --- tests/Support/SupportCollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 586686fa75cf..52069e8bb24c 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1063,7 +1063,7 @@ public function testKeyByClosure() }); $this->assertEquals([ '0-taylorotwell' => ['firstname' => 'Taylor', 'lastname' => 'Otwell', 'locale' => 'US'], - '1-lucasmichot' => ['firstname' => 'Lucas', 'lastname' => 'Michot', 'locale' => 'FR'], + '1-lucasmichot' => ['firstname' => 'Lucas', 'lastname' => 'Michot', 'locale' => 'FR'], ], $result->all()); } From 7a42ba6d82aa55740d7bcf5662692dd3421ffeec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Nabia=C5=82ek?= Date: Sun, 7 Aug 2016 19:37:16 +0200 Subject: [PATCH 127/249] [5.3] Add containsStrict method (#14657) * Add containsStrict method * Fix code style --- src/Illuminate/Support/Collection.php | 22 ++++++++++++++++++ tests/Support/SupportCollectionTest.php | 30 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index a4714336aa14..ea34c1746964 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -172,6 +172,28 @@ public function contains($key, $value = null) return in_array($key, $this->items); } + /** + * Determine if an item exists in the collection using strict comparison. + * + * @param mixed $key + * @param mixed $value + * @return bool + */ + public function containsStrict($key, $value = null) + { + if (func_num_args() == 2) { + return $this->contains(function ($item) use ($key, $value) { + return data_get($item, $key) === $value; + }); + } + + if ($this->useAsCallable($key)) { + return ! is_null($this->first($key)); + } + + return in_array($key, $this->items, true); + } + /** * Get the items in the collection that are not present in the given items. * diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 52069e8bb24c..60acb3a90832 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1092,6 +1092,36 @@ public function testContains() $this->assertFalse($c->contains('foo')); } + public function testContainsStrict() + { + $c = new Collection([1, 3, 5, '02']); + + $this->assertTrue($c->containsStrict(1)); + $this->assertFalse($c->containsStrict(2)); + $this->assertTrue($c->containsStrict('02')); + $this->assertTrue($c->containsStrict(function ($value) { + return $value < 5; + })); + $this->assertFalse($c->containsStrict(function ($value) { + return $value > 5; + })); + + $c = new Collection([['v' => 1], ['v' => 3], ['v' => '04'], ['v' => 5]]); + + $this->assertTrue($c->containsStrict('v', 1)); + $this->assertFalse($c->containsStrict('v', 2)); + $this->assertFalse($c->containsStrict('v', 4)); + $this->assertTrue($c->containsStrict('v', '04')); + + $c = new Collection(['date', 'class', (object) ['foo' => 50], '']); + + $this->assertTrue($c->containsStrict('date')); + $this->assertTrue($c->containsStrict('class')); + $this->assertFalse($c->containsStrict('foo')); + $this->assertFalse($c->containsStrict(null)); + $this->assertTrue($c->containsStrict('')); + } + public function testGettingSumFromCollection() { $c = new Collection([(object) ['foo' => 50], (object) ['foo' => 50]]); From 55a1a06eb0ff66413bd635f37e53b96894e7d061 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Aug 2016 13:08:03 -0500 Subject: [PATCH 128/249] fix bugs in code --- src/Illuminate/Database/Eloquent/Model.php | 12 ++++++---- tests/Database/DatabaseEloquentModelTest.php | 25 +++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 9c5e117d1785..cddc22555d8b 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -2111,9 +2111,7 @@ public function makeHidden($attributes) { $this->visible = array_diff($this->visible, (array) $attributes); - if (! empty($this->hidden)) { - $this->addHidden($attributes); - } + $this->hidden = array_unique(array_merge($this->hidden, $attributes)); return $this; } @@ -2577,10 +2575,14 @@ protected function getArrayableRelations() protected function getArrayableItems(array $values) { if (count($this->getVisible()) > 0) { - return array_intersect_key($values, array_flip($this->getVisible())); + $values = array_intersect_key($values, array_flip($this->getVisible())); + } + + if (count($this->getHidden()) > 0) { + $values = array_diff_key($values, array_flip($this->getHidden())); } - return array_diff_key($values, array_flip($this->getHidden())); + return $values; } /** diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 7dba5bd583da..78cc4a5885b6 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -713,17 +713,6 @@ public function testVisible() $this->assertArrayNotHasKey('age', $array); } - public function testHiddenAreIgnoringWhenVisibleExists() - { - $model = new EloquentModelStub(['name' => 'foo', 'age' => 'bar', 'id' => 'baz']); - $model->setVisible(['name', 'id']); - $model->setHidden(['name', 'age']); - $array = $model->toArray(); - $this->assertArrayHasKey('name', $array); - $this->assertArrayHasKey('id', $array); - $this->assertArrayNotHasKey('age', $array); - } - public function testDynamicHidden() { $model = new EloquentModelDynamicHiddenStub(['name' => 'foo', 'age' => 'bar', 'id' => 'baz']); @@ -743,6 +732,20 @@ public function testWithHidden() $this->assertArrayNotHasKey('id', $array); } + public function testMakeHidden() + { + $model = new EloquentModelStub(['name' => 'foo', 'age' => 'bar', 'id' => 'baz']); + $array = $model->toArray(); + $this->assertArrayHasKey('name', $array); + $this->assertArrayHasKey('age', $array); + $this->assertArrayHasKey('id', $array); + + $array = $model->makeHidden(['name', 'age'])->toArray(); + $this->assertArrayNotHasKey('name', $array); + $this->assertArrayNotHasKey('age', $array); + $this->assertArrayHasKey('id', $array); + } + public function testDynamicVisible() { $model = new EloquentModelDynamicVisibleStub(['name' => 'foo', 'age' => 'bar', 'id' => 'baz']); From 4cbf35d44c95d54faf827948f63c446c2b2b0d59 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Aug 2016 14:08:19 -0400 Subject: [PATCH 129/249] Applied fixes from StyleCI [ci skip] [skip ci] --- tests/Database/DatabaseEloquentModelTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 78cc4a5885b6..1167341f9cc7 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -267,8 +267,8 @@ public function testTimestampsAreReturnedAsObjects() $model = $this->getMockBuilder('EloquentDateModelStub')->setMethods(['getDateFormat'])->getMock(); $model->expects($this->any())->method('getDateFormat')->will($this->returnValue('Y-m-d')); $model->setRawAttributes([ - 'created_at' => '2012-12-04', - 'updated_at' => '2012-12-05', + 'created_at' => '2012-12-04', + 'updated_at' => '2012-12-05', ]); $this->assertInstanceOf('Carbon\Carbon', $model->created_at); @@ -280,8 +280,8 @@ public function testTimestampsAreReturnedAsObjectsFromPlainDatesAndTimestamps() $model = $this->getMockBuilder('EloquentDateModelStub')->setMethods(['getDateFormat'])->getMock(); $model->expects($this->any())->method('getDateFormat')->will($this->returnValue('Y-m-d H:i:s')); $model->setRawAttributes([ - 'created_at' => '2012-12-04', - 'updated_at' => time(), + 'created_at' => '2012-12-04', + 'updated_at' => time(), ]); $this->assertInstanceOf('Carbon\Carbon', $model->created_at); From 623a2a7244033a4f38cb3e98ae534460a8a87cfe Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Aug 2016 13:13:39 -0500 Subject: [PATCH 130/249] use collections --- src/Illuminate/Auth/Middleware/Authorize.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Auth/Middleware/Authorize.php b/src/Illuminate/Auth/Middleware/Authorize.php index 49cc8fe2e9b2..6752f9cb30a1 100644 --- a/src/Illuminate/Auth/Middleware/Authorize.php +++ b/src/Illuminate/Auth/Middleware/Authorize.php @@ -69,12 +69,9 @@ protected function getGateArguments($request, $models) return []; } - $gate_args = []; - foreach ($models as $model) { - $gate_args[] = $this->getModel($request, $model); - } - - return $gate_args; + return collect($models)->map(function ($model) use ($request) { + return $this->getModel($request, $model); + })->all(); } /** From ba400eab007cbee67070da40d06bcf238f089df0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Aug 2016 13:27:44 -0500 Subject: [PATCH 131/249] clean up exception handling --- src/Illuminate/Database/Eloquent/Builder.php | 3 +-- .../Eloquent/RelationNotFoundException.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 20207e328154..495d00a4eff1 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -681,8 +681,7 @@ public function getRelation($name) try { return $this->getModel()->$name(); } catch (BadMethodCallException $e) { - $className = get_class($this->getModel()); - throw new RelationNotFoundException("Call to undefined relationship {$name} on Model {$className}"); + throw RelationNotFoundException::make($this->getModel(), $name); } }); diff --git a/src/Illuminate/Database/Eloquent/RelationNotFoundException.php b/src/Illuminate/Database/Eloquent/RelationNotFoundException.php index 6541f1cec27b..b55a66adc913 100755 --- a/src/Illuminate/Database/Eloquent/RelationNotFoundException.php +++ b/src/Illuminate/Database/Eloquent/RelationNotFoundException.php @@ -6,5 +6,17 @@ class RelationNotFoundException extends RuntimeException { - // + /** + * Create a new exception instance. + * + * @param mixed $model + * @param string $relation + * @return static + */ + public static function make($model, $relation) + { + $class = get_class($model); + + throw new static("Call to undefined relationship [{$relation}] on model [{$class}]."); + } } From abc9dfe74eacb3a6ab13442fbd19829382653b10 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Bertholdo Carucce Date: Sun, 7 Aug 2016 16:15:54 -0300 Subject: [PATCH 132/249] Added testes for PR #14651 https://github.com/laravel/framework/pull/14651 --- tests/Validation/ValidationValidatorTest.php | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 6bf4c01f18e8..e0810dca77bf 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -3047,6 +3047,76 @@ public function testUsingSettersWithImplicitRules() $this->assertFalse($v->passes()); } + public function testInvalidMethod() + { + $trans = $this->getRealTranslator(); + + $v = new Validator($trans, + [ + ['name' => 'John'], + ['name' => null], + ['name' => ''] + ], + [ + '*.name' => 'required', + ]); + + $this->assertEquals($v->invalid(), [ + 1 => ['name' => null], + 2 => ['name' => ''] + ]); + + $v = new Validator($trans, + [ + 'name' => '' + ], + [ + 'name' => 'required', + ]); + + $this->assertEquals($v->invalid(), [ + 'name' => '' + ]); + } + + public function testValidMethod() + { + $trans = $this->getRealTranslator(); + + $v = new Validator($trans, + [ + ['name' => 'John'], + ['name' => null], + ['name' => ''], + ['name' => 'Doe'] + ], + [ + '*.name' => 'required', + ]); + + $this->assertEquals($v->valid(), [ + 0 => ['name' => 'John'], + 3 => ['name' => 'Doe'] + ]); + + $v = new Validator($trans, + [ + 'name' => 'Carlos', + 'age' => 'unknown', + 'gender' => 'male' + ], + [ + 'name' => 'required', + 'gernder' => 'in:male,female', + 'age' => 'required|int' + ]); + + $this->assertEquals($v->valid(), [ + 'name' => 'Carlos', + 'gender' => 'male' + ]); + } + protected function getTranslator() { return m::mock('Symfony\Component\Translation\TranslatorInterface'); From 3199870df109c259bf3eac7f12134e92adfa7922 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Bertholdo Carucce Date: Sun, 7 Aug 2016 16:19:54 -0300 Subject: [PATCH 133/249] Apply patch from StyleCI --- tests/Validation/ValidationValidatorTest.php | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index e0810dca77bf..12725a77b1d6 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -323,7 +323,7 @@ public function testDisplayableValuesAreReplaced() $trans->addResource('array', ['validation.in' => ':attribute must be included in :values.'], 'en', 'messages'); $customValues = [ 'type' => [ - '5' => 'Short', + '5' => 'Short', '300' => 'Long', ], ]; @@ -338,7 +338,7 @@ public function testDisplayableValuesAreReplaced() $trans->addResource('array', ['validation.in' => ':attribute must be included in :values.'], 'en', 'messages'); $customValues = [ 'type' => [ - '5' => 'Short', + '5' => 'Short', '300' => 'Long', ], ]; @@ -3055,7 +3055,7 @@ public function testInvalidMethod() [ ['name' => 'John'], ['name' => null], - ['name' => ''] + ['name' => ''], ], [ '*.name' => 'required', @@ -3063,19 +3063,19 @@ public function testInvalidMethod() $this->assertEquals($v->invalid(), [ 1 => ['name' => null], - 2 => ['name' => ''] + 2 => ['name' => ''], ]); $v = new Validator($trans, [ - 'name' => '' + 'name' => '', ], [ 'name' => 'required', ]); $this->assertEquals($v->invalid(), [ - 'name' => '' + 'name' => '', ]); } @@ -3088,7 +3088,7 @@ public function testValidMethod() ['name' => 'John'], ['name' => null], ['name' => ''], - ['name' => 'Doe'] + ['name' => 'Doe'], ], [ '*.name' => 'required', @@ -3096,24 +3096,24 @@ public function testValidMethod() $this->assertEquals($v->valid(), [ 0 => ['name' => 'John'], - 3 => ['name' => 'Doe'] + 3 => ['name' => 'Doe'], ]); $v = new Validator($trans, [ 'name' => 'Carlos', 'age' => 'unknown', - 'gender' => 'male' + 'gender' => 'male', ], [ 'name' => 'required', 'gernder' => 'in:male,female', - 'age' => 'required|int' + 'age' => 'required|int', ]); $this->assertEquals($v->valid(), [ 'name' => 'Carlos', - 'gender' => 'male' + 'gender' => 'male', ]); } From a1aeae9f64a1b58fcf35c5b437aeefa1b1a61480 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 7 Aug 2016 20:45:19 +0100 Subject: [PATCH 134/249] [5.3] Include delayed and reserved in redis queue count (#14681) * Include delayed and reserved in redis queue count * Applied fixes from StyleCI [ci skip] [skip ci] --- src/Illuminate/Console/Command.php | 8 +- src/Illuminate/Database/Query/Builder.php | 8 +- src/Illuminate/Foundation/Application.php | 66 +++--- .../Foundation/Console/RouteListCommand.php | 6 +- src/Illuminate/Queue/RedisQueue.php | 6 +- src/Illuminate/Support/Str.php | 222 +++++++++--------- tests/Auth/AuthPasswordBrokerTest.php | 4 +- tests/Cache/CacheApcStoreTest.php | 12 +- tests/Cache/CacheArrayStoreTest.php | 12 +- tests/Cache/CacheMemcachedStoreTest.php | 6 +- .../DatabaseEloquentIntegrationTest.php | 8 +- .../DatabaseMigratorIntegrationTest.php | 4 +- .../FoundationExpectsModelEventsTest.php | 4 +- .../QueueDatabaseQueueIntegrationTest.php | 4 +- 14 files changed, 187 insertions(+), 183 deletions(-) diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index df45e97785b6..26993edf59a6 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -70,10 +70,10 @@ class Command extends SymfonyCommand * @var array */ protected $verbosityMap = [ - 'v' => OutputInterface::VERBOSITY_VERBOSE, - 'vv' => OutputInterface::VERBOSITY_VERY_VERBOSE, - 'vvv' => OutputInterface::VERBOSITY_DEBUG, - 'quiet' => OutputInterface::VERBOSITY_QUIET, + 'v' => OutputInterface::VERBOSITY_VERBOSE, + 'vv' => OutputInterface::VERBOSITY_VERY_VERBOSE, + 'vvv' => OutputInterface::VERBOSITY_DEBUG, + 'quiet' => OutputInterface::VERBOSITY_QUIET, 'normal' => OutputInterface::VERBOSITY_NORMAL, ]; diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 6b14ad182aaf..99e6e5981c4b 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -51,11 +51,11 @@ class Builder */ protected $bindings = [ 'select' => [], - 'join' => [], - 'where' => [], + 'join' => [], + 'where' => [], 'having' => [], - 'order' => [], - 'union' => [], + 'order' => [], + 'union' => [], ]; /** diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index 27d5f61c465f..eb6a69bc891a 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -1062,40 +1062,40 @@ public function isLocale($locale) public function registerCoreContainerAliases() { $aliases = [ - 'app' => ['Illuminate\Foundation\Application', 'Illuminate\Contracts\Container\Container', 'Illuminate\Contracts\Foundation\Application'], - 'auth' => ['Illuminate\Auth\AuthManager', 'Illuminate\Contracts\Auth\Factory'], - 'auth.driver' => ['Illuminate\Contracts\Auth\Guard'], - 'blade.compiler' => ['Illuminate\View\Compilers\BladeCompiler'], - 'cache' => ['Illuminate\Cache\CacheManager', 'Illuminate\Contracts\Cache\Factory'], - 'cache.store' => ['Illuminate\Cache\Repository', 'Illuminate\Contracts\Cache\Repository'], - 'config' => ['Illuminate\Config\Repository', 'Illuminate\Contracts\Config\Repository'], - 'cookie' => ['Illuminate\Cookie\CookieJar', 'Illuminate\Contracts\Cookie\Factory', 'Illuminate\Contracts\Cookie\QueueingFactory'], - 'encrypter' => ['Illuminate\Encryption\Encrypter', 'Illuminate\Contracts\Encryption\Encrypter'], - 'db' => ['Illuminate\Database\DatabaseManager'], - 'db.connection' => ['Illuminate\Database\Connection', 'Illuminate\Database\ConnectionInterface'], - 'events' => ['Illuminate\Events\Dispatcher', 'Illuminate\Contracts\Events\Dispatcher'], - 'files' => ['Illuminate\Filesystem\Filesystem'], - 'filesystem' => ['Illuminate\Filesystem\FilesystemManager', 'Illuminate\Contracts\Filesystem\Factory'], - 'filesystem.disk' => ['Illuminate\Contracts\Filesystem\Filesystem'], - 'filesystem.cloud' => ['Illuminate\Contracts\Filesystem\Cloud'], - 'hash' => ['Illuminate\Contracts\Hashing\Hasher'], - 'translator' => ['Illuminate\Translation\Translator', 'Symfony\Component\Translation\TranslatorInterface'], - 'log' => ['Illuminate\Log\Writer', 'Illuminate\Contracts\Logging\Log', 'Psr\Log\LoggerInterface'], - 'mailer' => ['Illuminate\Mail\Mailer', 'Illuminate\Contracts\Mail\Mailer', 'Illuminate\Contracts\Mail\MailQueue'], - 'auth.password' => ['Illuminate\Auth\Passwords\PasswordBrokerManager', 'Illuminate\Contracts\Auth\PasswordBrokerFactory'], + 'app' => ['Illuminate\Foundation\Application', 'Illuminate\Contracts\Container\Container', 'Illuminate\Contracts\Foundation\Application'], + 'auth' => ['Illuminate\Auth\AuthManager', 'Illuminate\Contracts\Auth\Factory'], + 'auth.driver' => ['Illuminate\Contracts\Auth\Guard'], + 'blade.compiler' => ['Illuminate\View\Compilers\BladeCompiler'], + 'cache' => ['Illuminate\Cache\CacheManager', 'Illuminate\Contracts\Cache\Factory'], + 'cache.store' => ['Illuminate\Cache\Repository', 'Illuminate\Contracts\Cache\Repository'], + 'config' => ['Illuminate\Config\Repository', 'Illuminate\Contracts\Config\Repository'], + 'cookie' => ['Illuminate\Cookie\CookieJar', 'Illuminate\Contracts\Cookie\Factory', 'Illuminate\Contracts\Cookie\QueueingFactory'], + 'encrypter' => ['Illuminate\Encryption\Encrypter', 'Illuminate\Contracts\Encryption\Encrypter'], + 'db' => ['Illuminate\Database\DatabaseManager'], + 'db.connection' => ['Illuminate\Database\Connection', 'Illuminate\Database\ConnectionInterface'], + 'events' => ['Illuminate\Events\Dispatcher', 'Illuminate\Contracts\Events\Dispatcher'], + 'files' => ['Illuminate\Filesystem\Filesystem'], + 'filesystem' => ['Illuminate\Filesystem\FilesystemManager', 'Illuminate\Contracts\Filesystem\Factory'], + 'filesystem.disk' => ['Illuminate\Contracts\Filesystem\Filesystem'], + 'filesystem.cloud' => ['Illuminate\Contracts\Filesystem\Cloud'], + 'hash' => ['Illuminate\Contracts\Hashing\Hasher'], + 'translator' => ['Illuminate\Translation\Translator', 'Symfony\Component\Translation\TranslatorInterface'], + 'log' => ['Illuminate\Log\Writer', 'Illuminate\Contracts\Logging\Log', 'Psr\Log\LoggerInterface'], + 'mailer' => ['Illuminate\Mail\Mailer', 'Illuminate\Contracts\Mail\Mailer', 'Illuminate\Contracts\Mail\MailQueue'], + 'auth.password' => ['Illuminate\Auth\Passwords\PasswordBrokerManager', 'Illuminate\Contracts\Auth\PasswordBrokerFactory'], 'auth.password.broker' => ['Illuminate\Auth\Passwords\PasswordBroker', 'Illuminate\Contracts\Auth\PasswordBroker'], - 'queue' => ['Illuminate\Queue\QueueManager', 'Illuminate\Contracts\Queue\Factory', 'Illuminate\Contracts\Queue\Monitor'], - 'queue.connection' => ['Illuminate\Contracts\Queue\Queue'], - 'queue.failer' => ['Illuminate\Queue\Failed\FailedJobProviderInterface'], - 'redirect' => ['Illuminate\Routing\Redirector'], - 'redis' => ['Illuminate\Redis\Database', 'Illuminate\Contracts\Redis\Database'], - 'request' => ['Illuminate\Http\Request', 'Symfony\Component\HttpFoundation\Request'], - 'router' => ['Illuminate\Routing\Router', 'Illuminate\Contracts\Routing\Registrar'], - 'session' => ['Illuminate\Session\SessionManager'], - 'session.store' => ['Illuminate\Session\Store', 'Symfony\Component\HttpFoundation\Session\SessionInterface'], - 'url' => ['Illuminate\Routing\UrlGenerator', 'Illuminate\Contracts\Routing\UrlGenerator'], - 'validator' => ['Illuminate\Validation\Factory', 'Illuminate\Contracts\Validation\Factory'], - 'view' => ['Illuminate\View\Factory', 'Illuminate\Contracts\View\Factory'], + 'queue' => ['Illuminate\Queue\QueueManager', 'Illuminate\Contracts\Queue\Factory', 'Illuminate\Contracts\Queue\Monitor'], + 'queue.connection' => ['Illuminate\Contracts\Queue\Queue'], + 'queue.failer' => ['Illuminate\Queue\Failed\FailedJobProviderInterface'], + 'redirect' => ['Illuminate\Routing\Redirector'], + 'redis' => ['Illuminate\Redis\Database', 'Illuminate\Contracts\Redis\Database'], + 'request' => ['Illuminate\Http\Request', 'Symfony\Component\HttpFoundation\Request'], + 'router' => ['Illuminate\Routing\Router', 'Illuminate\Contracts\Routing\Registrar'], + 'session' => ['Illuminate\Session\SessionManager'], + 'session.store' => ['Illuminate\Session\Store', 'Symfony\Component\HttpFoundation\Session\SessionInterface'], + 'url' => ['Illuminate\Routing\UrlGenerator', 'Illuminate\Contracts\Routing\UrlGenerator'], + 'validator' => ['Illuminate\Validation\Factory', 'Illuminate\Contracts\Validation\Factory'], + 'view' => ['Illuminate\View\Factory', 'Illuminate\Contracts\View\Factory'], ]; foreach ($aliases as $key => $aliases) { diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index 1abd6cae669e..a22bbd5e4292 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -109,10 +109,10 @@ protected function getRoutes() protected function getRouteInformation(Route $route) { return $this->filterRoute([ - 'host' => $route->domain(), + 'host' => $route->domain(), 'method' => implode('|', $route->methods()), - 'uri' => $route->uri(), - 'name' => $route->getName(), + 'uri' => $route->uri(), + 'name' => $route->getName(), 'action' => $route->getActionName(), 'middleware' => $this->getMiddleware($route), ]); diff --git a/src/Illuminate/Queue/RedisQueue.php b/src/Illuminate/Queue/RedisQueue.php index f336703613af..6ef2b5909ab5 100644 --- a/src/Illuminate/Queue/RedisQueue.php +++ b/src/Illuminate/Queue/RedisQueue.php @@ -64,7 +64,11 @@ public function __construct(Database $redis, $default = 'default', */ public function size($queue = null) { - return (int) $this->getConnection()->llen($this->getQueue($queue)); + $queue = $this->getQueue($queue); + + return $this->getConnection()->llen($queue) + + $this->getConnection()->llen($queue.':delayed') + + $this->getConnection()->llen($queue.':reserved'); } /** diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index e59809a09173..c007c977bddd 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -466,119 +466,119 @@ protected static function charsArray() } return $charsArray = [ - '0' => ['°', '₀', '۰'], - '1' => ['¹', '₁', '۱'], - '2' => ['²', '₂', '۲'], - '3' => ['³', '₃', '۳'], - '4' => ['⁴', '₄', '۴', '٤'], - '5' => ['⁵', '₅', '۵', '٥'], - '6' => ['⁶', '₆', '۶', '٦'], - '7' => ['⁷', '₇', '۷'], - '8' => ['⁸', '₈', '۸'], - '9' => ['⁹', '₉', '۹'], - 'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'], - 'b' => ['б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'], - 'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ'], - 'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'], - 'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ'], - 'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ'], - 'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'], - 'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'], - 'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ'], - 'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج'], - 'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'], - 'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'], - 'm' => ['м', 'μ', 'م', 'မ', 'მ'], - 'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ'], - 'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ'], - 'p' => ['п', 'π', 'ပ', 'პ', 'پ'], - 'q' => ['ყ'], - 'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'], - 's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს'], - 't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ'], - 'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'], - 'v' => ['в', 'ვ', 'ϐ'], - 'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ'], - 'x' => ['χ', 'ξ'], - 'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'], - 'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'], - 'aa' => ['ع', 'आ', 'آ'], - 'ae' => ['ä', 'æ', 'ǽ'], - 'ai' => ['ऐ'], - 'at' => ['@'], - 'ch' => ['ч', 'ჩ', 'ჭ', 'چ'], - 'dj' => ['ђ', 'đ'], - 'dz' => ['џ', 'ძ'], - 'ei' => ['ऍ'], - 'gh' => ['غ', 'ღ'], - 'ii' => ['ई'], - 'ij' => ['ij'], - 'kh' => ['х', 'خ', 'ხ'], - 'lj' => ['љ'], - 'nj' => ['њ'], - 'oe' => ['ö', 'œ', 'ؤ'], - 'oi' => ['ऑ'], - 'oii' => ['ऒ'], - 'ps' => ['ψ'], - 'sh' => ['ш', 'შ', 'ش'], + '0' => ['°', '₀', '۰'], + '1' => ['¹', '₁', '۱'], + '2' => ['²', '₂', '۲'], + '3' => ['³', '₃', '۳'], + '4' => ['⁴', '₄', '۴', '٤'], + '5' => ['⁵', '₅', '۵', '٥'], + '6' => ['⁶', '₆', '۶', '٦'], + '7' => ['⁷', '₇', '۷'], + '8' => ['⁸', '₈', '۸'], + '9' => ['⁹', '₉', '۹'], + 'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'], + 'b' => ['б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'], + 'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ'], + 'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'], + 'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ'], + 'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ'], + 'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'], + 'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'], + 'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ'], + 'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج'], + 'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'], + 'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'], + 'm' => ['м', 'μ', 'م', 'မ', 'მ'], + 'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ'], + 'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ'], + 'p' => ['п', 'π', 'ပ', 'პ', 'پ'], + 'q' => ['ყ'], + 'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'], + 's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს'], + 't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ'], + 'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'], + 'v' => ['в', 'ვ', 'ϐ'], + 'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ'], + 'x' => ['χ', 'ξ'], + 'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'], + 'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'], + 'aa' => ['ع', 'आ', 'آ'], + 'ae' => ['ä', 'æ', 'ǽ'], + 'ai' => ['ऐ'], + 'at' => ['@'], + 'ch' => ['ч', 'ჩ', 'ჭ', 'چ'], + 'dj' => ['ђ', 'đ'], + 'dz' => ['џ', 'ძ'], + 'ei' => ['ऍ'], + 'gh' => ['غ', 'ღ'], + 'ii' => ['ई'], + 'ij' => ['ij'], + 'kh' => ['х', 'خ', 'ხ'], + 'lj' => ['љ'], + 'nj' => ['њ'], + 'oe' => ['ö', 'œ', 'ؤ'], + 'oi' => ['ऑ'], + 'oii' => ['ऒ'], + 'ps' => ['ψ'], + 'sh' => ['ш', 'შ', 'ش'], 'shch' => ['щ'], - 'ss' => ['ß'], - 'sx' => ['ŝ'], - 'th' => ['þ', 'ϑ', 'ث', 'ذ', 'ظ'], - 'ts' => ['ц', 'ც', 'წ'], - 'ue' => ['ü'], - 'uu' => ['ऊ'], - 'ya' => ['я'], - 'yu' => ['ю'], - 'zh' => ['ж', 'ჟ', 'ژ'], - '(c)' => ['©'], - 'A' => ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 'Ā', 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ'], - 'B' => ['Б', 'Β', 'ब'], - 'C' => ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ'], - 'D' => ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'], - 'E' => ['É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ', 'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ', 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є', 'Ə'], - 'F' => ['Ф', 'Φ'], - 'G' => ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'], - 'H' => ['Η', 'Ή', 'Ħ'], - 'I' => ['Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ'], - 'K' => ['К', 'Κ'], - 'L' => ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल'], - 'M' => ['М', 'Μ'], - 'N' => ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'], - 'O' => ['Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ', 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ'], - 'P' => ['П', 'Π'], - 'R' => ['Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ'], - 'S' => ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'], - 'T' => ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'], - 'U' => ['Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ', 'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ'], - 'V' => ['В'], - 'W' => ['Ω', 'Ώ', 'Ŵ'], - 'X' => ['Χ', 'Ξ'], - 'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'], - 'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ'], - 'AE' => ['Ä', 'Æ', 'Ǽ'], - 'CH' => ['Ч'], - 'DJ' => ['Ђ'], - 'DZ' => ['Џ'], - 'GX' => ['Ĝ'], - 'HX' => ['Ĥ'], - 'IJ' => ['IJ'], - 'JX' => ['Ĵ'], - 'KH' => ['Х'], - 'LJ' => ['Љ'], - 'NJ' => ['Њ'], - 'OE' => ['Ö', 'Œ'], - 'PS' => ['Ψ'], - 'SH' => ['Ш'], + 'ss' => ['ß'], + 'sx' => ['ŝ'], + 'th' => ['þ', 'ϑ', 'ث', 'ذ', 'ظ'], + 'ts' => ['ц', 'ც', 'წ'], + 'ue' => ['ü'], + 'uu' => ['ऊ'], + 'ya' => ['я'], + 'yu' => ['ю'], + 'zh' => ['ж', 'ჟ', 'ژ'], + '(c)' => ['©'], + 'A' => ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 'Ā', 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ'], + 'B' => ['Б', 'Β', 'ब'], + 'C' => ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ'], + 'D' => ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'], + 'E' => ['É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ', 'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ', 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є', 'Ə'], + 'F' => ['Ф', 'Φ'], + 'G' => ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'], + 'H' => ['Η', 'Ή', 'Ħ'], + 'I' => ['Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ'], + 'K' => ['К', 'Κ'], + 'L' => ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल'], + 'M' => ['М', 'Μ'], + 'N' => ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'], + 'O' => ['Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ', 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ'], + 'P' => ['П', 'Π'], + 'R' => ['Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ'], + 'S' => ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'], + 'T' => ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'], + 'U' => ['Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ', 'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ'], + 'V' => ['В'], + 'W' => ['Ω', 'Ώ', 'Ŵ'], + 'X' => ['Χ', 'Ξ'], + 'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'], + 'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ'], + 'AE' => ['Ä', 'Æ', 'Ǽ'], + 'CH' => ['Ч'], + 'DJ' => ['Ђ'], + 'DZ' => ['Џ'], + 'GX' => ['Ĝ'], + 'HX' => ['Ĥ'], + 'IJ' => ['IJ'], + 'JX' => ['Ĵ'], + 'KH' => ['Х'], + 'LJ' => ['Љ'], + 'NJ' => ['Њ'], + 'OE' => ['Ö', 'Œ'], + 'PS' => ['Ψ'], + 'SH' => ['Ш'], 'SHCH' => ['Щ'], - 'SS' => ['ẞ'], - 'TH' => ['Þ'], - 'TS' => ['Ц'], - 'UE' => ['Ü'], - 'YA' => ['Я'], - 'YU' => ['Ю'], - 'ZH' => ['Ж'], - ' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"], + 'SS' => ['ẞ'], + 'TH' => ['Þ'], + 'TS' => ['Ц'], + 'UE' => ['Ü'], + 'YA' => ['Я'], + 'YU' => ['Ю'], + 'ZH' => ['Ж'], + ' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"], ]; } } diff --git a/tests/Auth/AuthPasswordBrokerTest.php b/tests/Auth/AuthPasswordBrokerTest.php index e5282e0dd888..51c589cbf1cd 100755 --- a/tests/Auth/AuthPasswordBrokerTest.php +++ b/tests/Auth/AuthPasswordBrokerTest.php @@ -140,9 +140,9 @@ protected function getMocks() { $mocks = [ 'tokens' => m::mock('Illuminate\Auth\Passwords\TokenRepositoryInterface'), - 'users' => m::mock('Illuminate\Contracts\Auth\UserProvider'), + 'users' => m::mock('Illuminate\Contracts\Auth\UserProvider'), 'mailer' => m::mock('Illuminate\Contracts\Mail\Mailer'), - 'view' => 'resetLinkView', + 'view' => 'resetLinkView', ]; return $mocks; diff --git a/tests/Cache/CacheApcStoreTest.php b/tests/Cache/CacheApcStoreTest.php index 51f8337574ef..24f41733da7d 100755 --- a/tests/Cache/CacheApcStoreTest.php +++ b/tests/Cache/CacheApcStoreTest.php @@ -28,9 +28,9 @@ public function testGetMultipleReturnsNullWhenNotFoundAndValueWhenFound() ]); $store = new Illuminate\Cache\ApcStore($apc); $this->assertEquals([ - 'foo' => 'qux', - 'bar' => null, - 'baz' => 'norf', + 'foo' => 'qux', + 'bar' => null, + 'baz' => 'norf', ], $store->many(['foo', 'bar', 'baz'])); } @@ -54,9 +54,9 @@ public function testSetMultipleMethodProperlyCallsAPC() ]); $store = new Illuminate\Cache\ApcStore($apc); $store->putMany([ - 'foo' => 'bar', - 'baz' => 'qux', - 'bar' => 'norf', + 'foo' => 'bar', + 'baz' => 'qux', + 'bar' => 'norf', ], 1); } diff --git a/tests/Cache/CacheArrayStoreTest.php b/tests/Cache/CacheArrayStoreTest.php index c48a90ff9352..5d287e356b26 100755 --- a/tests/Cache/CacheArrayStoreTest.php +++ b/tests/Cache/CacheArrayStoreTest.php @@ -16,14 +16,14 @@ public function testMultipleItemsCanBeSetAndRetrieved() $store = new ArrayStore; $store->put('foo', 'bar', 10); $store->putMany([ - 'fizz' => 'buz', - 'quz' => 'baz', + 'fizz' => 'buz', + 'quz' => 'baz', ], 10); $this->assertEquals([ - 'foo' => 'bar', - 'fizz' => 'buz', - 'quz' => 'baz', - 'norf' => null, + 'foo' => 'bar', + 'fizz' => 'buz', + 'quz' => 'baz', + 'norf' => null, ], $store->many(['foo', 'fizz', 'quz', 'norf'])); } diff --git a/tests/Cache/CacheMemcachedStoreTest.php b/tests/Cache/CacheMemcachedStoreTest.php index 81b79c85b59c..3ff54d811c2f 100755 --- a/tests/Cache/CacheMemcachedStoreTest.php +++ b/tests/Cache/CacheMemcachedStoreTest.php @@ -35,9 +35,9 @@ public function testMemcacheGetMultiValuesAreReturnedWithCorrectKeys() $memcache->expects($this->once())->method('getResultCode')->will($this->returnValue(0)); $store = new Illuminate\Cache\MemcachedStore($memcache, 'foo'); $this->assertEquals([ - 'foo' => 'fizz', - 'bar' => 'buzz', - 'baz' => 'norf', + 'foo' => 'fizz', + 'bar' => 'buzz', + 'baz' => 'norf', ], $store->many([ 'foo', 'bar', 'baz', ])); diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index fab102f9136c..2d2fccb057cb 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -18,13 +18,13 @@ public function setUp() $db = new DB; $db->addConnection([ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'sqlite', + 'database' => ':memory:', ]); $db->addConnection([ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'sqlite', + 'database' => ':memory:', ], 'second_connection'); $db->bootEloquent(); diff --git a/tests/Database/DatabaseMigratorIntegrationTest.php b/tests/Database/DatabaseMigratorIntegrationTest.php index 0d24b2e25273..5a32b5b00361 100644 --- a/tests/Database/DatabaseMigratorIntegrationTest.php +++ b/tests/Database/DatabaseMigratorIntegrationTest.php @@ -19,8 +19,8 @@ public function setUp() $this->db = $db = new DB; $db->addConnection([ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'sqlite', + 'database' => ':memory:', ]); $db->setAsGlobal(); diff --git a/tests/Foundation/FoundationExpectsModelEventsTest.php b/tests/Foundation/FoundationExpectsModelEventsTest.php index 3411c1c0f355..159f0bd4b89e 100644 --- a/tests/Foundation/FoundationExpectsModelEventsTest.php +++ b/tests/Foundation/FoundationExpectsModelEventsTest.php @@ -19,8 +19,8 @@ public function createApplication() $db = new DB; $db->addConnection([ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'sqlite', + 'database' => ':memory:', ]); $db->bootEloquent(); diff --git a/tests/Queue/QueueDatabaseQueueIntegrationTest.php b/tests/Queue/QueueDatabaseQueueIntegrationTest.php index c57e288fa1f3..4a058e0f54bd 100644 --- a/tests/Queue/QueueDatabaseQueueIntegrationTest.php +++ b/tests/Queue/QueueDatabaseQueueIntegrationTest.php @@ -29,8 +29,8 @@ public function setUp() $db = new DB; $db->addConnection([ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'sqlite', + 'database' => ':memory:', ]); $db->bootEloquent(); From 6777f95f3f4dcb11acae9aa5155112ec54975dc5 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 7 Aug 2016 20:56:57 +0100 Subject: [PATCH 135/249] Revert "[5.3] Include delayed and reserved in redis queue count" --- src/Illuminate/Console/Command.php | 8 +- src/Illuminate/Database/Query/Builder.php | 8 +- src/Illuminate/Foundation/Application.php | 66 +++--- .../Foundation/Console/RouteListCommand.php | 6 +- src/Illuminate/Queue/RedisQueue.php | 6 +- src/Illuminate/Support/Str.php | 222 +++++++++--------- tests/Auth/AuthPasswordBrokerTest.php | 4 +- tests/Cache/CacheApcStoreTest.php | 12 +- tests/Cache/CacheArrayStoreTest.php | 12 +- tests/Cache/CacheMemcachedStoreTest.php | 6 +- .../DatabaseEloquentIntegrationTest.php | 8 +- .../DatabaseMigratorIntegrationTest.php | 4 +- .../FoundationExpectsModelEventsTest.php | 4 +- .../QueueDatabaseQueueIntegrationTest.php | 4 +- tests/Validation/ValidationValidatorTest.php | 4 +- 15 files changed, 185 insertions(+), 189 deletions(-) diff --git a/src/Illuminate/Console/Command.php b/src/Illuminate/Console/Command.php index 26993edf59a6..df45e97785b6 100755 --- a/src/Illuminate/Console/Command.php +++ b/src/Illuminate/Console/Command.php @@ -70,10 +70,10 @@ class Command extends SymfonyCommand * @var array */ protected $verbosityMap = [ - 'v' => OutputInterface::VERBOSITY_VERBOSE, - 'vv' => OutputInterface::VERBOSITY_VERY_VERBOSE, - 'vvv' => OutputInterface::VERBOSITY_DEBUG, - 'quiet' => OutputInterface::VERBOSITY_QUIET, + 'v' => OutputInterface::VERBOSITY_VERBOSE, + 'vv' => OutputInterface::VERBOSITY_VERY_VERBOSE, + 'vvv' => OutputInterface::VERBOSITY_DEBUG, + 'quiet' => OutputInterface::VERBOSITY_QUIET, 'normal' => OutputInterface::VERBOSITY_NORMAL, ]; diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 99e6e5981c4b..6b14ad182aaf 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -51,11 +51,11 @@ class Builder */ protected $bindings = [ 'select' => [], - 'join' => [], - 'where' => [], + 'join' => [], + 'where' => [], 'having' => [], - 'order' => [], - 'union' => [], + 'order' => [], + 'union' => [], ]; /** diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index eb6a69bc891a..27d5f61c465f 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -1062,40 +1062,40 @@ public function isLocale($locale) public function registerCoreContainerAliases() { $aliases = [ - 'app' => ['Illuminate\Foundation\Application', 'Illuminate\Contracts\Container\Container', 'Illuminate\Contracts\Foundation\Application'], - 'auth' => ['Illuminate\Auth\AuthManager', 'Illuminate\Contracts\Auth\Factory'], - 'auth.driver' => ['Illuminate\Contracts\Auth\Guard'], - 'blade.compiler' => ['Illuminate\View\Compilers\BladeCompiler'], - 'cache' => ['Illuminate\Cache\CacheManager', 'Illuminate\Contracts\Cache\Factory'], - 'cache.store' => ['Illuminate\Cache\Repository', 'Illuminate\Contracts\Cache\Repository'], - 'config' => ['Illuminate\Config\Repository', 'Illuminate\Contracts\Config\Repository'], - 'cookie' => ['Illuminate\Cookie\CookieJar', 'Illuminate\Contracts\Cookie\Factory', 'Illuminate\Contracts\Cookie\QueueingFactory'], - 'encrypter' => ['Illuminate\Encryption\Encrypter', 'Illuminate\Contracts\Encryption\Encrypter'], - 'db' => ['Illuminate\Database\DatabaseManager'], - 'db.connection' => ['Illuminate\Database\Connection', 'Illuminate\Database\ConnectionInterface'], - 'events' => ['Illuminate\Events\Dispatcher', 'Illuminate\Contracts\Events\Dispatcher'], - 'files' => ['Illuminate\Filesystem\Filesystem'], - 'filesystem' => ['Illuminate\Filesystem\FilesystemManager', 'Illuminate\Contracts\Filesystem\Factory'], - 'filesystem.disk' => ['Illuminate\Contracts\Filesystem\Filesystem'], - 'filesystem.cloud' => ['Illuminate\Contracts\Filesystem\Cloud'], - 'hash' => ['Illuminate\Contracts\Hashing\Hasher'], - 'translator' => ['Illuminate\Translation\Translator', 'Symfony\Component\Translation\TranslatorInterface'], - 'log' => ['Illuminate\Log\Writer', 'Illuminate\Contracts\Logging\Log', 'Psr\Log\LoggerInterface'], - 'mailer' => ['Illuminate\Mail\Mailer', 'Illuminate\Contracts\Mail\Mailer', 'Illuminate\Contracts\Mail\MailQueue'], - 'auth.password' => ['Illuminate\Auth\Passwords\PasswordBrokerManager', 'Illuminate\Contracts\Auth\PasswordBrokerFactory'], + 'app' => ['Illuminate\Foundation\Application', 'Illuminate\Contracts\Container\Container', 'Illuminate\Contracts\Foundation\Application'], + 'auth' => ['Illuminate\Auth\AuthManager', 'Illuminate\Contracts\Auth\Factory'], + 'auth.driver' => ['Illuminate\Contracts\Auth\Guard'], + 'blade.compiler' => ['Illuminate\View\Compilers\BladeCompiler'], + 'cache' => ['Illuminate\Cache\CacheManager', 'Illuminate\Contracts\Cache\Factory'], + 'cache.store' => ['Illuminate\Cache\Repository', 'Illuminate\Contracts\Cache\Repository'], + 'config' => ['Illuminate\Config\Repository', 'Illuminate\Contracts\Config\Repository'], + 'cookie' => ['Illuminate\Cookie\CookieJar', 'Illuminate\Contracts\Cookie\Factory', 'Illuminate\Contracts\Cookie\QueueingFactory'], + 'encrypter' => ['Illuminate\Encryption\Encrypter', 'Illuminate\Contracts\Encryption\Encrypter'], + 'db' => ['Illuminate\Database\DatabaseManager'], + 'db.connection' => ['Illuminate\Database\Connection', 'Illuminate\Database\ConnectionInterface'], + 'events' => ['Illuminate\Events\Dispatcher', 'Illuminate\Contracts\Events\Dispatcher'], + 'files' => ['Illuminate\Filesystem\Filesystem'], + 'filesystem' => ['Illuminate\Filesystem\FilesystemManager', 'Illuminate\Contracts\Filesystem\Factory'], + 'filesystem.disk' => ['Illuminate\Contracts\Filesystem\Filesystem'], + 'filesystem.cloud' => ['Illuminate\Contracts\Filesystem\Cloud'], + 'hash' => ['Illuminate\Contracts\Hashing\Hasher'], + 'translator' => ['Illuminate\Translation\Translator', 'Symfony\Component\Translation\TranslatorInterface'], + 'log' => ['Illuminate\Log\Writer', 'Illuminate\Contracts\Logging\Log', 'Psr\Log\LoggerInterface'], + 'mailer' => ['Illuminate\Mail\Mailer', 'Illuminate\Contracts\Mail\Mailer', 'Illuminate\Contracts\Mail\MailQueue'], + 'auth.password' => ['Illuminate\Auth\Passwords\PasswordBrokerManager', 'Illuminate\Contracts\Auth\PasswordBrokerFactory'], 'auth.password.broker' => ['Illuminate\Auth\Passwords\PasswordBroker', 'Illuminate\Contracts\Auth\PasswordBroker'], - 'queue' => ['Illuminate\Queue\QueueManager', 'Illuminate\Contracts\Queue\Factory', 'Illuminate\Contracts\Queue\Monitor'], - 'queue.connection' => ['Illuminate\Contracts\Queue\Queue'], - 'queue.failer' => ['Illuminate\Queue\Failed\FailedJobProviderInterface'], - 'redirect' => ['Illuminate\Routing\Redirector'], - 'redis' => ['Illuminate\Redis\Database', 'Illuminate\Contracts\Redis\Database'], - 'request' => ['Illuminate\Http\Request', 'Symfony\Component\HttpFoundation\Request'], - 'router' => ['Illuminate\Routing\Router', 'Illuminate\Contracts\Routing\Registrar'], - 'session' => ['Illuminate\Session\SessionManager'], - 'session.store' => ['Illuminate\Session\Store', 'Symfony\Component\HttpFoundation\Session\SessionInterface'], - 'url' => ['Illuminate\Routing\UrlGenerator', 'Illuminate\Contracts\Routing\UrlGenerator'], - 'validator' => ['Illuminate\Validation\Factory', 'Illuminate\Contracts\Validation\Factory'], - 'view' => ['Illuminate\View\Factory', 'Illuminate\Contracts\View\Factory'], + 'queue' => ['Illuminate\Queue\QueueManager', 'Illuminate\Contracts\Queue\Factory', 'Illuminate\Contracts\Queue\Monitor'], + 'queue.connection' => ['Illuminate\Contracts\Queue\Queue'], + 'queue.failer' => ['Illuminate\Queue\Failed\FailedJobProviderInterface'], + 'redirect' => ['Illuminate\Routing\Redirector'], + 'redis' => ['Illuminate\Redis\Database', 'Illuminate\Contracts\Redis\Database'], + 'request' => ['Illuminate\Http\Request', 'Symfony\Component\HttpFoundation\Request'], + 'router' => ['Illuminate\Routing\Router', 'Illuminate\Contracts\Routing\Registrar'], + 'session' => ['Illuminate\Session\SessionManager'], + 'session.store' => ['Illuminate\Session\Store', 'Symfony\Component\HttpFoundation\Session\SessionInterface'], + 'url' => ['Illuminate\Routing\UrlGenerator', 'Illuminate\Contracts\Routing\UrlGenerator'], + 'validator' => ['Illuminate\Validation\Factory', 'Illuminate\Contracts\Validation\Factory'], + 'view' => ['Illuminate\View\Factory', 'Illuminate\Contracts\View\Factory'], ]; foreach ($aliases as $key => $aliases) { diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index a22bbd5e4292..1abd6cae669e 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -109,10 +109,10 @@ protected function getRoutes() protected function getRouteInformation(Route $route) { return $this->filterRoute([ - 'host' => $route->domain(), + 'host' => $route->domain(), 'method' => implode('|', $route->methods()), - 'uri' => $route->uri(), - 'name' => $route->getName(), + 'uri' => $route->uri(), + 'name' => $route->getName(), 'action' => $route->getActionName(), 'middleware' => $this->getMiddleware($route), ]); diff --git a/src/Illuminate/Queue/RedisQueue.php b/src/Illuminate/Queue/RedisQueue.php index 6ef2b5909ab5..f336703613af 100644 --- a/src/Illuminate/Queue/RedisQueue.php +++ b/src/Illuminate/Queue/RedisQueue.php @@ -64,11 +64,7 @@ public function __construct(Database $redis, $default = 'default', */ public function size($queue = null) { - $queue = $this->getQueue($queue); - - return $this->getConnection()->llen($queue) - + $this->getConnection()->llen($queue.':delayed') - + $this->getConnection()->llen($queue.':reserved'); + return (int) $this->getConnection()->llen($this->getQueue($queue)); } /** diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index c007c977bddd..e59809a09173 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -466,119 +466,119 @@ protected static function charsArray() } return $charsArray = [ - '0' => ['°', '₀', '۰'], - '1' => ['¹', '₁', '۱'], - '2' => ['²', '₂', '۲'], - '3' => ['³', '₃', '۳'], - '4' => ['⁴', '₄', '۴', '٤'], - '5' => ['⁵', '₅', '۵', '٥'], - '6' => ['⁶', '₆', '۶', '٦'], - '7' => ['⁷', '₇', '۷'], - '8' => ['⁸', '₈', '۸'], - '9' => ['⁹', '₉', '۹'], - 'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'], - 'b' => ['б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'], - 'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ'], - 'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'], - 'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ'], - 'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ'], - 'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'], - 'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'], - 'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ'], - 'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج'], - 'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'], - 'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'], - 'm' => ['м', 'μ', 'م', 'မ', 'მ'], - 'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ'], - 'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ'], - 'p' => ['п', 'π', 'ပ', 'პ', 'پ'], - 'q' => ['ყ'], - 'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'], - 's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს'], - 't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ'], - 'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'], - 'v' => ['в', 'ვ', 'ϐ'], - 'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ'], - 'x' => ['χ', 'ξ'], - 'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'], - 'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'], - 'aa' => ['ع', 'आ', 'آ'], - 'ae' => ['ä', 'æ', 'ǽ'], - 'ai' => ['ऐ'], - 'at' => ['@'], - 'ch' => ['ч', 'ჩ', 'ჭ', 'چ'], - 'dj' => ['ђ', 'đ'], - 'dz' => ['џ', 'ძ'], - 'ei' => ['ऍ'], - 'gh' => ['غ', 'ღ'], - 'ii' => ['ई'], - 'ij' => ['ij'], - 'kh' => ['х', 'خ', 'ხ'], - 'lj' => ['љ'], - 'nj' => ['њ'], - 'oe' => ['ö', 'œ', 'ؤ'], - 'oi' => ['ऑ'], - 'oii' => ['ऒ'], - 'ps' => ['ψ'], - 'sh' => ['ш', 'შ', 'ش'], + '0' => ['°', '₀', '۰'], + '1' => ['¹', '₁', '۱'], + '2' => ['²', '₂', '۲'], + '3' => ['³', '₃', '۳'], + '4' => ['⁴', '₄', '۴', '٤'], + '5' => ['⁵', '₅', '۵', '٥'], + '6' => ['⁶', '₆', '۶', '٦'], + '7' => ['⁷', '₇', '۷'], + '8' => ['⁸', '₈', '۸'], + '9' => ['⁹', '₉', '۹'], + 'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'], + 'b' => ['б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'], + 'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ'], + 'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'], + 'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ'], + 'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ'], + 'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'], + 'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'], + 'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ'], + 'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج'], + 'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'], + 'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'], + 'm' => ['м', 'μ', 'م', 'မ', 'მ'], + 'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ'], + 'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ'], + 'p' => ['п', 'π', 'ပ', 'პ', 'پ'], + 'q' => ['ყ'], + 'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'], + 's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს'], + 't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ'], + 'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'], + 'v' => ['в', 'ვ', 'ϐ'], + 'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ'], + 'x' => ['χ', 'ξ'], + 'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'], + 'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'], + 'aa' => ['ع', 'आ', 'آ'], + 'ae' => ['ä', 'æ', 'ǽ'], + 'ai' => ['ऐ'], + 'at' => ['@'], + 'ch' => ['ч', 'ჩ', 'ჭ', 'چ'], + 'dj' => ['ђ', 'đ'], + 'dz' => ['џ', 'ძ'], + 'ei' => ['ऍ'], + 'gh' => ['غ', 'ღ'], + 'ii' => ['ई'], + 'ij' => ['ij'], + 'kh' => ['х', 'خ', 'ხ'], + 'lj' => ['љ'], + 'nj' => ['њ'], + 'oe' => ['ö', 'œ', 'ؤ'], + 'oi' => ['ऑ'], + 'oii' => ['ऒ'], + 'ps' => ['ψ'], + 'sh' => ['ш', 'შ', 'ش'], 'shch' => ['щ'], - 'ss' => ['ß'], - 'sx' => ['ŝ'], - 'th' => ['þ', 'ϑ', 'ث', 'ذ', 'ظ'], - 'ts' => ['ц', 'ც', 'წ'], - 'ue' => ['ü'], - 'uu' => ['ऊ'], - 'ya' => ['я'], - 'yu' => ['ю'], - 'zh' => ['ж', 'ჟ', 'ژ'], - '(c)' => ['©'], - 'A' => ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 'Ā', 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ'], - 'B' => ['Б', 'Β', 'ब'], - 'C' => ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ'], - 'D' => ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'], - 'E' => ['É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ', 'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ', 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є', 'Ə'], - 'F' => ['Ф', 'Φ'], - 'G' => ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'], - 'H' => ['Η', 'Ή', 'Ħ'], - 'I' => ['Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ'], - 'K' => ['К', 'Κ'], - 'L' => ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल'], - 'M' => ['М', 'Μ'], - 'N' => ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'], - 'O' => ['Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ', 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ'], - 'P' => ['П', 'Π'], - 'R' => ['Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ'], - 'S' => ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'], - 'T' => ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'], - 'U' => ['Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ', 'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ'], - 'V' => ['В'], - 'W' => ['Ω', 'Ώ', 'Ŵ'], - 'X' => ['Χ', 'Ξ'], - 'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'], - 'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ'], - 'AE' => ['Ä', 'Æ', 'Ǽ'], - 'CH' => ['Ч'], - 'DJ' => ['Ђ'], - 'DZ' => ['Џ'], - 'GX' => ['Ĝ'], - 'HX' => ['Ĥ'], - 'IJ' => ['IJ'], - 'JX' => ['Ĵ'], - 'KH' => ['Х'], - 'LJ' => ['Љ'], - 'NJ' => ['Њ'], - 'OE' => ['Ö', 'Œ'], - 'PS' => ['Ψ'], - 'SH' => ['Ш'], + 'ss' => ['ß'], + 'sx' => ['ŝ'], + 'th' => ['þ', 'ϑ', 'ث', 'ذ', 'ظ'], + 'ts' => ['ц', 'ც', 'წ'], + 'ue' => ['ü'], + 'uu' => ['ऊ'], + 'ya' => ['я'], + 'yu' => ['ю'], + 'zh' => ['ж', 'ჟ', 'ژ'], + '(c)' => ['©'], + 'A' => ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 'Ā', 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ'], + 'B' => ['Б', 'Β', 'ब'], + 'C' => ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ'], + 'D' => ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ'], + 'E' => ['É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ', 'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ', 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є', 'Ə'], + 'F' => ['Ф', 'Φ'], + 'G' => ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ'], + 'H' => ['Η', 'Ή', 'Ħ'], + 'I' => ['Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ'], + 'K' => ['К', 'Κ'], + 'L' => ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल'], + 'M' => ['М', 'Μ'], + 'N' => ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν'], + 'O' => ['Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ', 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ'], + 'P' => ['П', 'Π'], + 'R' => ['Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ'], + 'S' => ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ'], + 'T' => ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ'], + 'U' => ['Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ', 'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ'], + 'V' => ['В'], + 'W' => ['Ω', 'Ώ', 'Ŵ'], + 'X' => ['Χ', 'Ξ'], + 'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ'], + 'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ'], + 'AE' => ['Ä', 'Æ', 'Ǽ'], + 'CH' => ['Ч'], + 'DJ' => ['Ђ'], + 'DZ' => ['Џ'], + 'GX' => ['Ĝ'], + 'HX' => ['Ĥ'], + 'IJ' => ['IJ'], + 'JX' => ['Ĵ'], + 'KH' => ['Х'], + 'LJ' => ['Љ'], + 'NJ' => ['Њ'], + 'OE' => ['Ö', 'Œ'], + 'PS' => ['Ψ'], + 'SH' => ['Ш'], 'SHCH' => ['Щ'], - 'SS' => ['ẞ'], - 'TH' => ['Þ'], - 'TS' => ['Ц'], - 'UE' => ['Ü'], - 'YA' => ['Я'], - 'YU' => ['Ю'], - 'ZH' => ['Ж'], - ' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"], + 'SS' => ['ẞ'], + 'TH' => ['Þ'], + 'TS' => ['Ц'], + 'UE' => ['Ü'], + 'YA' => ['Я'], + 'YU' => ['Ю'], + 'ZH' => ['Ж'], + ' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"], ]; } } diff --git a/tests/Auth/AuthPasswordBrokerTest.php b/tests/Auth/AuthPasswordBrokerTest.php index 51c589cbf1cd..e5282e0dd888 100755 --- a/tests/Auth/AuthPasswordBrokerTest.php +++ b/tests/Auth/AuthPasswordBrokerTest.php @@ -140,9 +140,9 @@ protected function getMocks() { $mocks = [ 'tokens' => m::mock('Illuminate\Auth\Passwords\TokenRepositoryInterface'), - 'users' => m::mock('Illuminate\Contracts\Auth\UserProvider'), + 'users' => m::mock('Illuminate\Contracts\Auth\UserProvider'), 'mailer' => m::mock('Illuminate\Contracts\Mail\Mailer'), - 'view' => 'resetLinkView', + 'view' => 'resetLinkView', ]; return $mocks; diff --git a/tests/Cache/CacheApcStoreTest.php b/tests/Cache/CacheApcStoreTest.php index 24f41733da7d..51f8337574ef 100755 --- a/tests/Cache/CacheApcStoreTest.php +++ b/tests/Cache/CacheApcStoreTest.php @@ -28,9 +28,9 @@ public function testGetMultipleReturnsNullWhenNotFoundAndValueWhenFound() ]); $store = new Illuminate\Cache\ApcStore($apc); $this->assertEquals([ - 'foo' => 'qux', - 'bar' => null, - 'baz' => 'norf', + 'foo' => 'qux', + 'bar' => null, + 'baz' => 'norf', ], $store->many(['foo', 'bar', 'baz'])); } @@ -54,9 +54,9 @@ public function testSetMultipleMethodProperlyCallsAPC() ]); $store = new Illuminate\Cache\ApcStore($apc); $store->putMany([ - 'foo' => 'bar', - 'baz' => 'qux', - 'bar' => 'norf', + 'foo' => 'bar', + 'baz' => 'qux', + 'bar' => 'norf', ], 1); } diff --git a/tests/Cache/CacheArrayStoreTest.php b/tests/Cache/CacheArrayStoreTest.php index 5d287e356b26..c48a90ff9352 100755 --- a/tests/Cache/CacheArrayStoreTest.php +++ b/tests/Cache/CacheArrayStoreTest.php @@ -16,14 +16,14 @@ public function testMultipleItemsCanBeSetAndRetrieved() $store = new ArrayStore; $store->put('foo', 'bar', 10); $store->putMany([ - 'fizz' => 'buz', - 'quz' => 'baz', + 'fizz' => 'buz', + 'quz' => 'baz', ], 10); $this->assertEquals([ - 'foo' => 'bar', - 'fizz' => 'buz', - 'quz' => 'baz', - 'norf' => null, + 'foo' => 'bar', + 'fizz' => 'buz', + 'quz' => 'baz', + 'norf' => null, ], $store->many(['foo', 'fizz', 'quz', 'norf'])); } diff --git a/tests/Cache/CacheMemcachedStoreTest.php b/tests/Cache/CacheMemcachedStoreTest.php index 3ff54d811c2f..81b79c85b59c 100755 --- a/tests/Cache/CacheMemcachedStoreTest.php +++ b/tests/Cache/CacheMemcachedStoreTest.php @@ -35,9 +35,9 @@ public function testMemcacheGetMultiValuesAreReturnedWithCorrectKeys() $memcache->expects($this->once())->method('getResultCode')->will($this->returnValue(0)); $store = new Illuminate\Cache\MemcachedStore($memcache, 'foo'); $this->assertEquals([ - 'foo' => 'fizz', - 'bar' => 'buzz', - 'baz' => 'norf', + 'foo' => 'fizz', + 'bar' => 'buzz', + 'baz' => 'norf', ], $store->many([ 'foo', 'bar', 'baz', ])); diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index 2d2fccb057cb..fab102f9136c 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -18,13 +18,13 @@ public function setUp() $db = new DB; $db->addConnection([ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'sqlite', + 'database' => ':memory:', ]); $db->addConnection([ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'sqlite', + 'database' => ':memory:', ], 'second_connection'); $db->bootEloquent(); diff --git a/tests/Database/DatabaseMigratorIntegrationTest.php b/tests/Database/DatabaseMigratorIntegrationTest.php index 5a32b5b00361..0d24b2e25273 100644 --- a/tests/Database/DatabaseMigratorIntegrationTest.php +++ b/tests/Database/DatabaseMigratorIntegrationTest.php @@ -19,8 +19,8 @@ public function setUp() $this->db = $db = new DB; $db->addConnection([ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'sqlite', + 'database' => ':memory:', ]); $db->setAsGlobal(); diff --git a/tests/Foundation/FoundationExpectsModelEventsTest.php b/tests/Foundation/FoundationExpectsModelEventsTest.php index 159f0bd4b89e..3411c1c0f355 100644 --- a/tests/Foundation/FoundationExpectsModelEventsTest.php +++ b/tests/Foundation/FoundationExpectsModelEventsTest.php @@ -19,8 +19,8 @@ public function createApplication() $db = new DB; $db->addConnection([ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'sqlite', + 'database' => ':memory:', ]); $db->bootEloquent(); diff --git a/tests/Queue/QueueDatabaseQueueIntegrationTest.php b/tests/Queue/QueueDatabaseQueueIntegrationTest.php index 4a058e0f54bd..c57e288fa1f3 100644 --- a/tests/Queue/QueueDatabaseQueueIntegrationTest.php +++ b/tests/Queue/QueueDatabaseQueueIntegrationTest.php @@ -29,8 +29,8 @@ public function setUp() $db = new DB; $db->addConnection([ - 'driver' => 'sqlite', - 'database' => ':memory:', + 'driver' => 'sqlite', + 'database' => ':memory:', ]); $db->bootEloquent(); diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 12725a77b1d6..dd1396bb584a 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -323,7 +323,7 @@ public function testDisplayableValuesAreReplaced() $trans->addResource('array', ['validation.in' => ':attribute must be included in :values.'], 'en', 'messages'); $customValues = [ 'type' => [ - '5' => 'Short', + '5' => 'Short', '300' => 'Long', ], ]; @@ -338,7 +338,7 @@ public function testDisplayableValuesAreReplaced() $trans->addResource('array', ['validation.in' => ':attribute must be included in :values.'], 'en', 'messages'); $customValues = [ 'type' => [ - '5' => 'Short', + '5' => 'Short', '300' => 'Long', ], ]; From a85271aec7a1b833cac60595cd3a8efca1d2934f Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 7 Aug 2016 21:41:30 +0100 Subject: [PATCH 136/249] Include delayed and reserved in redis queue count --- src/Illuminate/Queue/RedisQueue.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Queue/RedisQueue.php b/src/Illuminate/Queue/RedisQueue.php index f336703613af..6ef2b5909ab5 100644 --- a/src/Illuminate/Queue/RedisQueue.php +++ b/src/Illuminate/Queue/RedisQueue.php @@ -64,7 +64,11 @@ public function __construct(Database $redis, $default = 'default', */ public function size($queue = null) { - return (int) $this->getConnection()->llen($this->getQueue($queue)); + $queue = $this->getQueue($queue); + + return $this->getConnection()->llen($queue) + + $this->getConnection()->llen($queue.':delayed') + + $this->getConnection()->llen($queue.':reserved'); } /** From 882311e319c0573210f6d2196bdd5968a131de89 Mon Sep 17 00:00:00 2001 From: Joseph Silber Date: Sun, 7 Aug 2016 20:58:28 -0400 Subject: [PATCH 137/249] Return new exception --- src/Illuminate/Database/Eloquent/RelationNotFoundException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/RelationNotFoundException.php b/src/Illuminate/Database/Eloquent/RelationNotFoundException.php index b55a66adc913..5026ac9c8910 100755 --- a/src/Illuminate/Database/Eloquent/RelationNotFoundException.php +++ b/src/Illuminate/Database/Eloquent/RelationNotFoundException.php @@ -17,6 +17,6 @@ public static function make($model, $relation) { $class = get_class($model); - throw new static("Call to undefined relationship [{$relation}] on model [{$class}]."); + return new static("Call to undefined relationship [{$relation}] on model [{$class}]."); } } From d410063c8031cd4648f5878181077fca4e1d5f7e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 7 Aug 2016 21:09:52 -0500 Subject: [PATCH 138/249] refactoring notifications --- .../Notifications/ChannelManager.php | 7 -- .../Notifications/Channels/MailChannel.php | 29 +------- .../Notifications/Messages/MailMessage.php | 26 +++++++ .../SimpleMessage.php} | 41 ++++++------ src/Illuminate/Notifications/Notification.php | 67 ------------------- .../resources/views/email.blade.php | 23 +++++-- .../NotificationChannelManagerTest.php | 5 +- .../NotificationMailChannelTest.php | 12 ++-- 8 files changed, 71 insertions(+), 139 deletions(-) create mode 100644 src/Illuminate/Notifications/Messages/MailMessage.php rename src/Illuminate/Notifications/{Message.php => Messages/SimpleMessage.php} (86%) diff --git a/src/Illuminate/Notifications/ChannelManager.php b/src/Illuminate/Notifications/ChannelManager.php index 4b8e44274e0c..2612ce74d369 100644 --- a/src/Illuminate/Notifications/ChannelManager.php +++ b/src/Illuminate/Notifications/ChannelManager.php @@ -46,13 +46,6 @@ public function send($notifiables, $notification) */ public function sendNow($notifiables, $notification) { - if (! $notification->application) { - $notification->application( - $this->app['config']['app.name'], - $this->app['config']['app.logo'] - ); - } - foreach ($notifiables as $notifiable) { $channels = $notification->via($notifiable); diff --git a/src/Illuminate/Notifications/Channels/MailChannel.php b/src/Illuminate/Notifications/Channels/MailChannel.php index c6aff1766238..bbd3c9171a49 100644 --- a/src/Illuminate/Notifications/Channels/MailChannel.php +++ b/src/Illuminate/Notifications/Channels/MailChannel.php @@ -2,7 +2,6 @@ namespace Illuminate\Notifications\Channels; -use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Contracts\Mail\Mailer; use Illuminate\Notifications\Notification; @@ -36,42 +35,20 @@ public function __construct(Mailer $mailer) */ public function send($notifiables, Notification $notification) { - $view = data_get($notification, 'options.view', 'notifications::email'); - foreach ($notifiables as $notifiable) { if (! $notifiable->routeNotificationFor('mail')) { continue; } - $data = $notification->toArray($notifiable); - - Arr::set($data, 'actionColor', $this->actionColorForLevel($data['level'])); + $message = $notification->asMail($notifiable); - $this->mailer->send($view, $data, function ($m) use ($notifiable, $notification) { + $this->mailer->send($message->view, $message->toArray(), function ($m) use ($notifiable, $notification, $message) { $m->to($notifiable->routeNotificationFor('mail')); - $m->subject($notification->message($notifiable)->subject ?: Str::title( + $m->subject($message->subject ?: Str::title( Str::snake(class_basename($notification), ' ') )); }); } } - - /** - * Get the action color for the given notification "level". - * - * @param string $level - * @return string - */ - protected function actionColorForLevel($level) - { - switch ($level) { - case 'success': - return 'green'; - case 'error': - return 'red'; - default: - return 'blue'; - } - } } diff --git a/src/Illuminate/Notifications/Messages/MailMessage.php b/src/Illuminate/Notifications/Messages/MailMessage.php new file mode 100644 index 000000000000..ee6a8b2b870a --- /dev/null +++ b/src/Illuminate/Notifications/Messages/MailMessage.php @@ -0,0 +1,26 @@ +view = $view; + + return $this; + } +} diff --git a/src/Illuminate/Notifications/Message.php b/src/Illuminate/Notifications/Messages/SimpleMessage.php similarity index 86% rename from src/Illuminate/Notifications/Message.php rename to src/Illuminate/Notifications/Messages/SimpleMessage.php index dc8b6249c4c0..7d5c5c430a31 100644 --- a/src/Illuminate/Notifications/Message.php +++ b/src/Illuminate/Notifications/Messages/SimpleMessage.php @@ -1,8 +1,8 @@ options = $options; - - return $this; - } - /** * Configure the "call to action" button. * @@ -175,4 +155,21 @@ public function action($text, $url) return $this; } + + /** + * Get an array representation of the message. + * + * @return array + */ + public function toArray() + { + return [ + 'level' => $this->level, + 'subject' => $this->subject, + 'introLines' => $this->introLines, + 'outroLines' => $this->outroLines, + 'actionText' => $this->actionText, + 'actionUrl' => $this->actionUrl, + ]; + } } diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index 423b945702e7..41bc2f877938 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -8,71 +8,4 @@ class Notification { use SerializesModels; - - /** - * The name of the application sending the notification. - * - * @var string - */ - public $application; - - /** - * The URL to the application's logo. - * - * @var string - */ - public $logoUrl; - - /** - * Specify the name of the application sending the notification. - * - * @param string $application - * @param string $logoUrl - * @return $this - */ - public function application($application, $logoUrl = null) - { - $this->application = $application; - $this->logoUrl = $logoUrl; - - return $this; - } - - /** - * Get an array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - $message = $this->message($notifiable); - - return [ - 'application' => $this->application, - 'logoUrl' => $this->logoUrl, - 'level' => $message->level, - 'subject' => $message->subject, - 'introLines' => $message->introLines, - 'outroLines' => $message->outroLines, - 'actionText' => $message->actionText, - 'actionUrl' => $message->actionUrl, - ]; - } - - /** - * Dynamically pass calls to the message class. - * - * @param string $method - * @param array $parameters - * @return mixed - */ - public function __call($method, $parameters) - { - if (method_exists(Message::class, $method)) { - return (new Message)->{$method}(...$parameters); - } - - throw new BadMethodCallException("Call to undefined method [{$method}]."); - } } diff --git a/src/Illuminate/Notifications/resources/views/email.blade.php b/src/Illuminate/Notifications/resources/views/email.blade.php index 5467e73fc557..285dbbcb5a47 100644 --- a/src/Illuminate/Notifications/resources/views/email.blade.php +++ b/src/Illuminate/Notifications/resources/views/email.blade.php @@ -218,11 +218,7 @@ @@ -255,6 +251,19 @@
+ + {{ $actionText }} @@ -273,7 +282,7 @@

- Regards,
{{ $application }} + Regards,
{{ config('app.name') }}

@@ -309,7 +318,7 @@

© {{ date('Y') }} - {{ $application }}. + {{ config('app.name') }}. All rights reserved.

diff --git a/tests/Notifications/NotificationChannelManagerTest.php b/tests/Notifications/NotificationChannelManagerTest.php index c67a2bfad21a..1e022a91c321 100644 --- a/tests/Notifications/NotificationChannelManagerTest.php +++ b/tests/Notifications/NotificationChannelManagerTest.php @@ -20,10 +20,7 @@ public function testNotificationCanBeDispatchedToDriver() Container::setInstance($container); $manager = Mockery::mock(ChannelManager::class.'[driver]', [$container]); $manager->shouldReceive('driver')->andReturn($driver = Mockery::mock()); - $driver->shouldReceive('send')->andReturnUsing(function ($notifiables, $notification) { - $this->assertEquals('Name', $notification->application); - $this->assertEquals('Logo', $notification->logoUrl); - }); + $driver->shouldReceive('send')->once(); $events->shouldReceive('fire')->with(Mockery::type(Illuminate\Notifications\Events\NotificationSent::class)); $manager->send([new NotificationChannelManagerTestNotifiable], new NotificationChannelManagerTestNotification); diff --git a/tests/Notifications/NotificationMailChannelTest.php b/tests/Notifications/NotificationMailChannelTest.php index a6a21c8d3563..05b606613309 100644 --- a/tests/Notifications/NotificationMailChannelTest.php +++ b/tests/Notifications/NotificationMailChannelTest.php @@ -1,6 +1,6 @@ toArray($notifiable); - $array['actionColor'] = 'blue'; + $message = $notification->asMail($notifiable); + $data = $message->toArray(); $channel = new Illuminate\Notifications\Channels\MailChannel( $mailer = Mockery::mock(Illuminate\Contracts\Mail\Mailer::class) ); - $mailer->shouldReceive('send')->with('notifications::email', $array, Mockery::type('Closure')); + $mailer->shouldReceive('send')->with('notifications::email', $data, Mockery::type('Closure')); $channel->send($notifiables, $notification); } @@ -39,8 +39,8 @@ class NotificationMailChannelTestNotifiable class NotificationMailChannelTestNotification extends Notification { - public function message($notifiable) + public function asMail($notifiable) { - return new Message; + return new MailMessage; } } From c685b501b34d224b3a3fe376b56fb84ff28615a0 Mon Sep 17 00:00:00 2001 From: halaei Date: Mon, 8 Aug 2016 10:34:17 +0430 Subject: [PATCH 139/249] test and fix RedisQueue::size() by using zcard and eval --- src/Illuminate/Queue/LuaScripts.php | 12 ++++++++++++ src/Illuminate/Queue/RedisQueue.php | 4 +--- tests/Queue/RedisQueueIntegrationTest.php | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Queue/LuaScripts.php b/src/Illuminate/Queue/LuaScripts.php index 8aa942e005ed..464c11270928 100644 --- a/src/Illuminate/Queue/LuaScripts.php +++ b/src/Illuminate/Queue/LuaScripts.php @@ -54,6 +54,18 @@ public static function migrateExpiredJobs() end end return true +LUA; + } + + /** + * Get the Lua script for computing the size of queue. + * + * @return string + */ + public static function size() + { + return <<<'LUA' +return redis.call('llen', KEYS[1]) + redis.call('zcard', KEYS[1]..':delayed') + redis.call('zcard', KEYS[1]..':reserved') LUA; } } diff --git a/src/Illuminate/Queue/RedisQueue.php b/src/Illuminate/Queue/RedisQueue.php index 6ef2b5909ab5..8fcfe89c3055 100644 --- a/src/Illuminate/Queue/RedisQueue.php +++ b/src/Illuminate/Queue/RedisQueue.php @@ -66,9 +66,7 @@ public function size($queue = null) { $queue = $this->getQueue($queue); - return $this->getConnection()->llen($queue) - + $this->getConnection()->llen($queue.':delayed') - + $this->getConnection()->llen($queue.':reserved'); + return $this->getConnection()->eval(LuaScripts::size(), 1, $queue); } /** diff --git a/tests/Queue/RedisQueueIntegrationTest.php b/tests/Queue/RedisQueueIntegrationTest.php index 43a1126cbea9..bfb84e6e7066 100644 --- a/tests/Queue/RedisQueueIntegrationTest.php +++ b/tests/Queue/RedisQueueIntegrationTest.php @@ -263,6 +263,21 @@ public function testDelete() $this->assertNull($this->queue->pop()); } + + public function testSize() + { + $this->assertEquals(0, $this->queue->size()); + $this->queue->push(new RedisQueueIntegrationTestJob(1)); + $this->assertEquals(1, $this->queue->size()); + $this->queue->later(60, new RedisQueueIntegrationTestJob(2)); + $this->assertEquals(2, $this->queue->size()); + $this->queue->push(new RedisQueueIntegrationTestJob(3)); + $this->assertEquals(3, $this->queue->size()); + $job = $this->queue->pop(); + $this->assertEquals(3, $this->queue->size()); + $job->delete(); + $this->assertEquals(2, $this->queue->size()); + } } class RedisQueueIntegrationTestJob From a22ef56f98890c6a9919d56c30bdbf951be11cc3 Mon Sep 17 00:00:00 2001 From: Carlos A B Carucce Date: Mon, 8 Aug 2016 11:34:54 -0300 Subject: [PATCH 140/249] Misspelling fixed 'gender' --- tests/Validation/ValidationValidatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index dd1396bb584a..d7ed1a7b2cfe 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -3107,7 +3107,7 @@ public function testValidMethod() ], [ 'name' => 'required', - 'gernder' => 'in:male,female', + 'gender' => 'in:male,female', 'age' => 'required|int', ]); From d2f5c3795749fbefa606ad72e7bef181845d8c19 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 10:47:36 -0500 Subject: [PATCH 141/249] work on channel speific messages --- composer.json | 1 + .../Auth/Notifications/ResetPassword.php | 10 ++-- .../Console/stubs/notification.stub | 25 ++++++++-- .../Channels/BroadcastChannel.php | 46 ------------------- .../Channels/DatabaseChannel.php | 38 ++++++++++++--- .../Notifications/Channels/MailChannel.php | 2 +- .../Channels/NexmoSmsChannel.php | 2 +- .../Channels/SlackWebhookChannel.php | 8 ++-- .../Notifications/DatabaseNotification.php | 10 +++- .../Events/DatabaseNotificationCreated.php | 6 ++- .../Messages/DatabaseMessage.php | 36 +++++++++++++++ .../Notifications/Messages/NexmoMessage.php | 8 ++++ .../Notifications/Messages/SlackMessage.php | 8 ++++ src/Illuminate/Notifications/Notification.php | 10 ++++ .../NotificationBroadcastChannelTest.php | 43 ----------------- .../NotificationDatabaseChannelTest.php | 44 ++++++++++++++---- .../NotificationMailChannelTest.php | 4 +- .../Notifications/NotificationMessageTest.php | 2 +- .../NotificationNexmoChannelTest.php | 6 ++- .../NotificationSlackChannelTest.php | 6 ++- 20 files changed, 186 insertions(+), 129 deletions(-) delete mode 100644 src/Illuminate/Notifications/Channels/BroadcastChannel.php create mode 100644 src/Illuminate/Notifications/Messages/DatabaseMessage.php create mode 100644 src/Illuminate/Notifications/Messages/NexmoMessage.php create mode 100644 src/Illuminate/Notifications/Messages/SlackMessage.php delete mode 100644 tests/Notifications/NotificationBroadcastChannelTest.php diff --git a/composer.json b/composer.json index 4d14f4174f79..2d6849fea0f9 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "nesbot/carbon": "~1.20", "paragonie/random_compat": "~1.4|~2.0", "psy/psysh": "0.7.*", + "ramsey/uuid": "~3.0", "swiftmailer/swiftmailer": "~5.1", "symfony/console": "3.1.*", "symfony/debug": "3.1.*", diff --git a/src/Illuminate/Auth/Notifications/ResetPassword.php b/src/Illuminate/Auth/Notifications/ResetPassword.php index 7484eaef7049..c5fa1d819ec2 100644 --- a/src/Illuminate/Auth/Notifications/ResetPassword.php +++ b/src/Illuminate/Auth/Notifications/ResetPassword.php @@ -3,6 +3,7 @@ namespace Illuminate\Auth\Notifications; use Illuminate\Notifications\Notification; +use Illuminate\Notifications\Messages\MailMessage; class ResetPassword extends Notification { @@ -36,13 +37,14 @@ public function via($notifiable) } /** - * Build the notification message. + * Build the mail representation of the notification. * - * @return \Illuminate\Notifications\Message + * @return \Illuminate\Notifications\Messages\MailMessage */ - public function message() + public function toMail() { - return $this->line([ + return (new MailMessage) + ->line([ 'You are receiving this email because we received a password reset request for your account.', 'Click the button below to reset your password:', ]) diff --git a/src/Illuminate/Foundation/Console/stubs/notification.stub b/src/Illuminate/Foundation/Console/stubs/notification.stub index 75c116fdbc40..82481ae3f138 100644 --- a/src/Illuminate/Foundation/Console/stubs/notification.stub +++ b/src/Illuminate/Foundation/Console/stubs/notification.stub @@ -5,6 +5,9 @@ namespace DummyNamespace; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Notifications\Messages\MailMessage; +use Illuminate\Notifications\Messages\DatabaseMessage; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; class DummyClass extends Notification { @@ -32,15 +35,29 @@ class DummyClass extends Notification } /** - * Get the notification message. + * Get the mail representation of the notification. * * @param mixed $notifiable - * @return \Illuminate\Notifications\Message + * @return \Illuminate\Notifications\Messages\MailMessage */ - public function message($notifiable) + public function toMail($notifiable) { - return $this->line('The introduction to the notification.') + return (new MailMessage) + ->line('The introduction to the notification.') ->action('Notification Action', 'https://laravel.com') ->line('Thank you for using our application!'); } + + /** + * Get the database representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\DatabaseMessage + */ + public function toDatabase($notifiable) + { + return new DatabaseMessage([ + // + ]); + } } diff --git a/src/Illuminate/Notifications/Channels/BroadcastChannel.php b/src/Illuminate/Notifications/Channels/BroadcastChannel.php deleted file mode 100644 index 7a02549f451a..000000000000 --- a/src/Illuminate/Notifications/Channels/BroadcastChannel.php +++ /dev/null @@ -1,46 +0,0 @@ -events = $events; - } - - /** - * Send the given notification. - * - * @param \Illuminate\Support\Collection $notifiables - * @param \Illuminate\Notifications\Notification $notification - * @return void - */ - public function send($notifiables, Notification $notification) - { - foreach ($notifiables as $notifiable) { - $databaseNotification = $this->createNotification($notifiable, $notification); - - $this->events->fire(new DatabaseNotificationCreated( - $notifiable, $notification, $databaseNotification - )); - } - } -} diff --git a/src/Illuminate/Notifications/Channels/DatabaseChannel.php b/src/Illuminate/Notifications/Channels/DatabaseChannel.php index c40bd2d007c5..c03137711645 100644 --- a/src/Illuminate/Notifications/Channels/DatabaseChannel.php +++ b/src/Illuminate/Notifications/Channels/DatabaseChannel.php @@ -3,9 +3,30 @@ namespace Illuminate\Notifications\Channels; use Illuminate\Notifications\Notification; +use Illuminate\Contracts\Events\Dispatcher; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Notifications\Events\DatabaseNotificationCreated; class DatabaseChannel { + /** + * The event dispatcher. + * + * @var \Illuminate\Contracts\Events\Dispatcher + */ + protected $events; + + /** + * Create a new database channel. + * + * @param \Illuminate\Contracts\Events\Dispatcher $events + * @return void + */ + public function __construct(Dispatcher $events) + { + $this->events = $events; + } + /** * Send the given notification. * @@ -16,7 +37,13 @@ class DatabaseChannel public function send($notifiables, Notification $notification) { foreach ($notifiables as $notifiable) { - $this->createNotification($notifiable, $notification); + $databaseNotification = $this->createNotification($notifiable, $notification); + + if ($notification instanceof ShouldBroadcast) { + $this->events->fire(new DatabaseNotificationCreated( + $notifiable, $notification, $databaseNotification + )); + } } } @@ -29,15 +56,12 @@ public function send($notifiables, Notification $notification) */ protected function createNotification($notifiable, Notification $notification) { - $message = $notification->message($notifiable); + $message = $notification->toDatabase($notifiable); return $notifiable->routeNotificationFor('database')->create([ + 'id' => $message->id, 'type' => get_class($notification), - 'level' => $message->level, - 'intro' => $message->introLines, - 'outro' => $message->outroLines, - 'action_text' => $message->actionText, - 'action_url' => $message->actionUrl, + 'data' => $message->data, 'read' => false, ]); } diff --git a/src/Illuminate/Notifications/Channels/MailChannel.php b/src/Illuminate/Notifications/Channels/MailChannel.php index bbd3c9171a49..ff41001547d0 100644 --- a/src/Illuminate/Notifications/Channels/MailChannel.php +++ b/src/Illuminate/Notifications/Channels/MailChannel.php @@ -40,7 +40,7 @@ public function send($notifiables, Notification $notification) continue; } - $message = $notification->asMail($notifiable); + $message = $notification->toMail($notifiable); $this->mailer->send($message->view, $message->toArray(), function ($m) use ($notifiable, $notification, $message) { $m->to($notifiable->routeNotificationFor('mail')); diff --git a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php index 1fd01e9ee462..5da0469da914 100644 --- a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php +++ b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php @@ -65,7 +65,7 @@ public function send($notifiables, Notification $notification) */ protected function formatNotification($notifiable, $notification) { - $message = $notification->message($notifiable); + $message = $notification->toNexmo($notifiable); $actionText = $message->actionText ? $message->actionText.': ' : ''; diff --git a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php index 4e4958d6b4cd..c9db90bf62ac 100644 --- a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php +++ b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php @@ -3,8 +3,8 @@ namespace Illuminate\Notifications\Channels; use GuzzleHttp\Client as HttpClient; -use Illuminate\Notifications\Message; use Illuminate\Notifications\Notification; +use Illuminate\Notifications\Messages\SlackMessage; class SlackWebhookChannel { @@ -40,7 +40,7 @@ public function send($notifiables, Notification $notification) continue; } - $message = $notification->message($notifiable); + $message = $notification->toSlack($notifiable); $this->http->post($url, [ 'json' => [ @@ -60,10 +60,10 @@ public function send($notifiables, Notification $notification) /** * Format the given notification message. * - * @param \Illuminate\Notifications\Message $message + * @param \Illuminate\Notifications\Messages\SlackMessage $message * @return string */ - protected function format(Message $message) + protected function format(SlackMessage $message) { $text = trim(implode(PHP_EOL.PHP_EOL, $message->introLines)); diff --git a/src/Illuminate/Notifications/DatabaseNotification.php b/src/Illuminate/Notifications/DatabaseNotification.php index 69497c1cfe9c..409ecceb4175 100644 --- a/src/Illuminate/Notifications/DatabaseNotification.php +++ b/src/Illuminate/Notifications/DatabaseNotification.php @@ -6,6 +6,13 @@ class DatabaseNotification extends Model { + /** + * Indicates if the IDs are auto-incrementing. + * + * @var bool + */ + public $incrementing = false; + /** * The table associated with the model. * @@ -26,8 +33,7 @@ class DatabaseNotification extends Model * @var array */ protected $casts = [ - 'intro' => 'array', - 'outro' => 'array', + 'data' => 'array', 'read' => 'boolean', ]; diff --git a/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php b/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php index 09400d6971e0..076c90b593ef 100644 --- a/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php +++ b/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php @@ -55,7 +55,11 @@ public function __construct($notifiable, $notification, $databaseNotification) */ public function broadcastOn() { - return [new PrivateChannel($this->channelName())]; + if (! empty($channels = $this->notification->broadcastOn())) { + return $channels; + } else { + return [new PrivateChannel($this->channelName())]; + } } /** diff --git a/src/Illuminate/Notifications/Messages/DatabaseMessage.php b/src/Illuminate/Notifications/Messages/DatabaseMessage.php new file mode 100644 index 000000000000..d9207bb99bae --- /dev/null +++ b/src/Illuminate/Notifications/Messages/DatabaseMessage.php @@ -0,0 +1,36 @@ +id = Arr::pull($data, 'id') ?: Uuid::uuid4(); + + $this->data = $data; + } +} diff --git a/src/Illuminate/Notifications/Messages/NexmoMessage.php b/src/Illuminate/Notifications/Messages/NexmoMessage.php new file mode 100644 index 000000000000..1d83e8393c5f --- /dev/null +++ b/src/Illuminate/Notifications/Messages/NexmoMessage.php @@ -0,0 +1,8 @@ +shouldReceive('routeNotificationFor->create')->with([ - 'type' => get_class($notification), - 'level' => 'info', - 'intro' => [], - 'outro' => [], - 'action_text' => null, - 'action_url' => null, - 'read' => false, - ]); - - $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); - $events->shouldReceive('fire')->once()->with('Illuminate\Notifications\Events\DatabaseNotificationCreated'); - - $channel = new BroadcastChannel($events); - $channel->send($notifiables, $notification); - } -} - -class NotificationBroadcastChannelTestNotification extends Notification -{ - public function message($notifiable) - { - return new Message; - } -} diff --git a/tests/Notifications/NotificationDatabaseChannelTest.php b/tests/Notifications/NotificationDatabaseChannelTest.php index f3fc4a2ba2ef..1f220dd15810 100644 --- a/tests/Notifications/NotificationDatabaseChannelTest.php +++ b/tests/Notifications/NotificationDatabaseChannelTest.php @@ -1,8 +1,9 @@ shouldReceive('routeNotificationFor->create')->with([ + 'id' => 1, 'type' => get_class($notification), - 'level' => 'info', - 'intro' => [], - 'outro' => [], - 'action_text' => null, - 'action_url' => null, + 'data' => ['invoice_id' => 1], 'read' => false, ]); - $channel = new DatabaseChannel; + $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); + $channel = new DatabaseChannel($events); + $channel->send($notifiables, $notification); + } + + public function testDatabaseNotificationCreationCanBeBroadcasted() + { + $notification = new NotificationDatabaseChannelTestBroadcastNotification; + $notifiables = collect([$notifiable = Mockery::mock()]); + + $notifiable->shouldReceive('routeNotificationFor->create')->with([ + 'id' => 1, + 'type' => get_class($notification), + 'data' => ['invoice_id' => 1], + 'read' => false, + ]); + + $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); + $events->shouldReceive('fire')->once()->with('Illuminate\Notifications\Events\DatabaseNotificationCreated'); + + $channel = new DatabaseChannel($events); $channel->send($notifiables, $notification); } } class NotificationDatabaseChannelTestNotification extends Notification { - public function message($notifiable) + public function toDatabase($notifiable) + { + return new DatabaseMessage(['id' => 1, 'invoice_id' => 1]); + } +} + +class NotificationDatabaseChannelTestBroadcastNotification extends Notification implements ShouldBroadcast +{ + public function toDatabase($notifiable) { - return new Message; + return new DatabaseMessage(['id' => 1, 'invoice_id' => 1]); } } diff --git a/tests/Notifications/NotificationMailChannelTest.php b/tests/Notifications/NotificationMailChannelTest.php index 05b606613309..f73c64e3c693 100644 --- a/tests/Notifications/NotificationMailChannelTest.php +++ b/tests/Notifications/NotificationMailChannelTest.php @@ -17,7 +17,7 @@ public function testMailIsSentByChannel() $notifiable = new NotificationMailChannelTestNotifiable, ]); - $message = $notification->asMail($notifiable); + $message = $notification->toMail($notifiable); $data = $message->toArray(); $channel = new Illuminate\Notifications\Channels\MailChannel( @@ -39,7 +39,7 @@ class NotificationMailChannelTestNotifiable class NotificationMailChannelTestNotification extends Notification { - public function asMail($notifiable) + public function toMail($notifiable) { return new MailMessage; } diff --git a/tests/Notifications/NotificationMessageTest.php b/tests/Notifications/NotificationMessageTest.php index e10be66392db..128a436d4d57 100644 --- a/tests/Notifications/NotificationMessageTest.php +++ b/tests/Notifications/NotificationMessageTest.php @@ -1,6 +1,6 @@ line('line 1') + return (new NexmoMessage) + ->line('line 1') ->action('Text', 'url') ->line('line 2'); } diff --git a/tests/Notifications/NotificationSlackChannelTest.php b/tests/Notifications/NotificationSlackChannelTest.php index a58f356384a5..7a0a6a387a2b 100644 --- a/tests/Notifications/NotificationSlackChannelTest.php +++ b/tests/Notifications/NotificationSlackChannelTest.php @@ -1,6 +1,7 @@ subject('Subject') + return (new SlackMessage) + ->subject('Subject') ->success() ->line('line 1') ->action('Text', 'url') From 13473f8da919aab38e1dba3e5102bd522aee9fb7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 10:47:56 -0500 Subject: [PATCH 142/249] Applied fixes from StyleCI (#14693) --- src/Illuminate/Notifications/Notification.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index cd12569dcdd3..7ad921ab7c2b 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -2,7 +2,6 @@ namespace Illuminate\Notifications; -use BadMethodCallException; use Illuminate\Queue\SerializesModels; class Notification From 8955c08e0bf75463f5388adc3281f73796a741f7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 12:00:06 -0500 Subject: [PATCH 143/249] tweak how broadcast is handled --- .../Console/stubs/notification.stub | 12 ++- .../Notifications/ChannelManager.php | 7 +- .../Channels/DatabaseChannel.php | 64 +++++--------- .../Notifications/Channels/MailChannel.php | 26 +++--- .../Channels/NexmoSmsChannel.php | 22 +++-- .../Channels/SlackWebhookChannel.php | 36 ++++---- .../Events/DatabaseNotificationCreated.php | 86 ------------------- .../Messages/DatabaseMessage.php | 10 --- src/Illuminate/Notifications/Notification.php | 7 ++ .../NotificationDatabaseChannelTest.php | 38 ++------ .../NotificationMailChannelTest.php | 6 +- .../NotificationNexmoChannelTest.php | 6 +- .../NotificationSlackChannelTest.php | 6 +- 13 files changed, 90 insertions(+), 236 deletions(-) delete mode 100644 src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php diff --git a/src/Illuminate/Foundation/Console/stubs/notification.stub b/src/Illuminate/Foundation/Console/stubs/notification.stub index 82481ae3f138..a192a7ccb712 100644 --- a/src/Illuminate/Foundation/Console/stubs/notification.stub +++ b/src/Illuminate/Foundation/Console/stubs/notification.stub @@ -6,8 +6,6 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; -use Illuminate\Notifications\Messages\DatabaseMessage; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; class DummyClass extends Notification { @@ -49,15 +47,15 @@ class DummyClass extends Notification } /** - * Get the database representation of the notification. + * Get the array representation of the notification. * * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\DatabaseMessage + * @return array */ - public function toDatabase($notifiable) + public function toArray($notifiable) { - return new DatabaseMessage([ + return [ // - ]); + ]; } } diff --git a/src/Illuminate/Notifications/ChannelManager.php b/src/Illuminate/Notifications/ChannelManager.php index 2612ce74d369..eb890f975512 100644 --- a/src/Illuminate/Notifications/ChannelManager.php +++ b/src/Illuminate/Notifications/ChannelManager.php @@ -2,6 +2,7 @@ namespace Illuminate\Notifications; +use Ramsey\Uuid\Uuid; use InvalidArgumentException; use Illuminate\Support\Manager; use Nexmo\Client as NexmoClient; @@ -47,6 +48,10 @@ public function send($notifiables, $notification) public function sendNow($notifiables, $notification) { foreach ($notifiables as $notifiable) { + $notification = clone $notification; + + $notification->id = Uuid::uuid4(); + $channels = $notification->via($notifiable); if (empty($channels)) { @@ -58,7 +63,7 @@ public function sendNow($notifiables, $notification) ); foreach ($channels as $channel) { - $this->driver($channel)->send(collect([$notifiable]), $notification); + $this->driver($channel)->send($notifiable, $notification); } } } diff --git a/src/Illuminate/Notifications/Channels/DatabaseChannel.php b/src/Illuminate/Notifications/Channels/DatabaseChannel.php index c03137711645..3a43ad181225 100644 --- a/src/Illuminate/Notifications/Channels/DatabaseChannel.php +++ b/src/Illuminate/Notifications/Channels/DatabaseChannel.php @@ -2,67 +2,47 @@ namespace Illuminate\Notifications\Channels; +use RuntimeException; use Illuminate\Notifications\Notification; -use Illuminate\Contracts\Events\Dispatcher; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; -use Illuminate\Notifications\Events\DatabaseNotificationCreated; class DatabaseChannel { - /** - * The event dispatcher. - * - * @var \Illuminate\Contracts\Events\Dispatcher - */ - protected $events; - - /** - * Create a new database channel. - * - * @param \Illuminate\Contracts\Events\Dispatcher $events - * @return void - */ - public function __construct(Dispatcher $events) - { - $this->events = $events; - } - /** * Send the given notification. * - * @param \Illuminate\Support\Collection $notifiables + * @param mixed $notifiable * @param \Illuminate\Notifications\Notification $notification * @return void */ - public function send($notifiables, Notification $notification) + public function send($notifiable, Notification $notification) { - foreach ($notifiables as $notifiable) { - $databaseNotification = $this->createNotification($notifiable, $notification); - - if ($notification instanceof ShouldBroadcast) { - $this->events->fire(new DatabaseNotificationCreated( - $notifiable, $notification, $databaseNotification - )); - } - } + $notifiable->routeNotificationFor('database')->create([ + 'id' => $notification->id, + 'type' => get_class($notification), + 'data' => $this->getData($notifiable, $notification), + 'read' => false, + ]); } /** - * Create a database notification record for the notifiable. + * Get the data for the notification. * * @param mixed $notifiable * @param \Illuminate\Notifications\Notification $notification - * @return \Illuminate\Notifications\DatabaseNotification + * @return array + * + * @throws \RuntimeException */ - protected function createNotification($notifiable, Notification $notification) + protected function getData($notifiable, Notification $notification) { - $message = $notification->toDatabase($notifiable); + if (method_exists($notification, 'toDatabase')) { + return $notification->toDatabase($notifiable)->data; + } elseif (method_exists($notification, 'toArray')) { + return $notification->toArray($notifiable); + } - return $notifiable->routeNotificationFor('database')->create([ - 'id' => $message->id, - 'type' => get_class($notification), - 'data' => $message->data, - 'read' => false, - ]); + throw new RuntimeException( + "Notification is missing toDatabase / toArray method." + ); } } diff --git a/src/Illuminate/Notifications/Channels/MailChannel.php b/src/Illuminate/Notifications/Channels/MailChannel.php index ff41001547d0..5a91079f0b05 100644 --- a/src/Illuminate/Notifications/Channels/MailChannel.php +++ b/src/Illuminate/Notifications/Channels/MailChannel.php @@ -29,26 +29,24 @@ public function __construct(Mailer $mailer) /** * Send the given notification. * - * @param \Illuminate\Support\Collection $notifiables + * @param mixed $notifiable * @param \Illuminate\Notifications\Notification $notification * @return void */ - public function send($notifiables, Notification $notification) + public function send($notifiable, Notification $notification) { - foreach ($notifiables as $notifiable) { - if (! $notifiable->routeNotificationFor('mail')) { - continue; - } + if (! $notifiable->routeNotificationFor('mail')) { + return; + } - $message = $notification->toMail($notifiable); + $message = $notification->toMail($notifiable); - $this->mailer->send($message->view, $message->toArray(), function ($m) use ($notifiable, $notification, $message) { - $m->to($notifiable->routeNotificationFor('mail')); + $this->mailer->send($message->view, $message->toArray(), function ($m) use ($notifiable, $notification, $message) { + $m->to($notifiable->routeNotificationFor('mail')); - $m->subject($message->subject ?: Str::title( - Str::snake(class_basename($notification), ' ') - )); - }); - } + $m->subject($message->subject ?: Str::title( + Str::snake(class_basename($notification), ' ') + )); + }); } } diff --git a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php index 5da0469da914..e80549f8f8ba 100644 --- a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php +++ b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php @@ -37,23 +37,21 @@ public function __construct(NexmoClient $nexmo, $from) /** * Send the given notification. * - * @param \Illuminate\Support\Collection $notifiables + * @param mixed $notifiable * @param \Illuminate\Notifications\Notification $notification * @return void */ - public function send($notifiables, Notification $notification) + public function send($notifiable, Notification $notification) { - foreach ($notifiables as $notifiable) { - if (! $to = $notifiable->routeNotificationFor('nexmo')) { - continue; - } - - $this->nexmo->message()->send([ - 'from' => $this->from, - 'to' => $to, - 'text' => $this->formatNotification($notifiable, $notification), - ]); + if (! $to = $notifiable->routeNotificationFor('nexmo')) { + return; } + + $this->nexmo->message()->send([ + 'from' => $this->from, + 'to' => $to, + 'text' => $this->formatNotification($notifiable, $notification), + ]); } /** diff --git a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php index c9db90bf62ac..ba8439f82cba 100644 --- a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php +++ b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php @@ -29,32 +29,30 @@ public function __construct(HttpClient $http) /** * Send the given notification. * - * @param \Illuminate\Support\Collection $notifiables + * @param mixed $notifiable * @param \Illuminate\Notifications\Notification $notification * @return void */ - public function send($notifiables, Notification $notification) + public function send($notifiable, Notification $notification) { - foreach ($notifiables as $notifiable) { - if (! $url = $notifiable->routeNotificationFor('slack')) { - continue; - } + if (! $url = $notifiable->routeNotificationFor('slack')) { + return; + } - $message = $notification->toSlack($notifiable); + $message = $notification->toSlack($notifiable); - $this->http->post($url, [ - 'json' => [ - 'attachments' => [ - array_filter([ - 'color' => $this->color($message->level), - 'title' => $message->subject, - 'title_link' => $message->actionUrl ?: null, - 'text' => $this->format($message), - ]), - ], + $this->http->post($url, [ + 'json' => [ + 'attachments' => [ + array_filter([ + 'color' => $this->color($message->level), + 'title' => $message->subject, + 'title_link' => $message->actionUrl ?: null, + 'text' => $this->format($message), + ]), ], - ]); - } + ], + ]); } /** diff --git a/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php b/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php deleted file mode 100644 index 076c90b593ef..000000000000 --- a/src/Illuminate/Notifications/Events/DatabaseNotificationCreated.php +++ /dev/null @@ -1,86 +0,0 @@ -notifiable = $notifiable; - $this->notification = $notification; - $this->databaseNotification = $databaseNotification; - } - - /** - * Get the channels the event should broadcast on. - * - * @return array - */ - public function broadcastOn() - { - if (! empty($channels = $this->notification->broadcastOn())) { - return $channels; - } else { - return [new PrivateChannel($this->channelName())]; - } - } - - /** - * Get the data that should be sent with the broadcasted event. - * - * @return array - */ - public function broadcastWith() - { - return ['notification' => $this->databaseNotification]; - } - - /** - * Get the broadcast channel name for the event. - * - * @return string - */ - protected function channelName() - { - $class = str_replace('\\', '.', get_class($this->notifiable)); - - return $class.'.'.$this->notifiable->getKey(); - } -} diff --git a/src/Illuminate/Notifications/Messages/DatabaseMessage.php b/src/Illuminate/Notifications/Messages/DatabaseMessage.php index d9207bb99bae..54b00d0884ad 100644 --- a/src/Illuminate/Notifications/Messages/DatabaseMessage.php +++ b/src/Illuminate/Notifications/Messages/DatabaseMessage.php @@ -2,18 +2,10 @@ namespace Illuminate\Notifications\Messages; -use Ramsey\Uuid\Uuid; use Illuminate\Support\Arr; class DatabaseMessage { - /** - * The message's unique identifier. - * - * @var string - */ - public $id; - /** * The data that should be stored with the notification. * @@ -29,8 +21,6 @@ class DatabaseMessage */ public function __construct(array $data = []) { - $this->id = Arr::pull($data, 'id') ?: Uuid::uuid4(); - $this->data = $data; } } diff --git a/src/Illuminate/Notifications/Notification.php b/src/Illuminate/Notifications/Notification.php index 7ad921ab7c2b..9b258b7dc1f6 100644 --- a/src/Illuminate/Notifications/Notification.php +++ b/src/Illuminate/Notifications/Notification.php @@ -8,6 +8,13 @@ class Notification { use SerializesModels; + /** + * The unique identifier for the notification. + * + * @var string + */ + public $id; + /** * Get the channels the event should broadcast on. * diff --git a/tests/Notifications/NotificationDatabaseChannelTest.php b/tests/Notifications/NotificationDatabaseChannelTest.php index 1f220dd15810..69ef0dbb7ea4 100644 --- a/tests/Notifications/NotificationDatabaseChannelTest.php +++ b/tests/Notifications/NotificationDatabaseChannelTest.php @@ -3,7 +3,6 @@ use Illuminate\Notifications\Notification; use Illuminate\Notifications\Channels\DatabaseChannel; use Illuminate\Notifications\Messages\DatabaseMessage; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; class NotificationDatabaseChannelTest extends PHPUnit_Framework_TestCase { @@ -15,7 +14,8 @@ public function tearDown() public function testDatabaseChannelCreatesDatabaseRecordWithProperData() { $notification = new NotificationDatabaseChannelTestNotification; - $notifiables = collect([$notifiable = Mockery::mock()]); + $notification->id = 1; + $notifiable = Mockery::mock(); $notifiable->shouldReceive('routeNotificationFor->create')->with([ 'id' => 1, @@ -24,28 +24,8 @@ public function testDatabaseChannelCreatesDatabaseRecordWithProperData() 'read' => false, ]); - $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); - $channel = new DatabaseChannel($events); - $channel->send($notifiables, $notification); - } - - public function testDatabaseNotificationCreationCanBeBroadcasted() - { - $notification = new NotificationDatabaseChannelTestBroadcastNotification; - $notifiables = collect([$notifiable = Mockery::mock()]); - - $notifiable->shouldReceive('routeNotificationFor->create')->with([ - 'id' => 1, - 'type' => get_class($notification), - 'data' => ['invoice_id' => 1], - 'read' => false, - ]); - - $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); - $events->shouldReceive('fire')->once()->with('Illuminate\Notifications\Events\DatabaseNotificationCreated'); - - $channel = new DatabaseChannel($events); - $channel->send($notifiables, $notification); + $channel = new DatabaseChannel; + $channel->send($notifiable, $notification); } } @@ -53,14 +33,6 @@ class NotificationDatabaseChannelTestNotification extends Notification { public function toDatabase($notifiable) { - return new DatabaseMessage(['id' => 1, 'invoice_id' => 1]); - } -} - -class NotificationDatabaseChannelTestBroadcastNotification extends Notification implements ShouldBroadcast -{ - public function toDatabase($notifiable) - { - return new DatabaseMessage(['id' => 1, 'invoice_id' => 1]); + return new DatabaseMessage(['invoice_id' => 1]); } } diff --git a/tests/Notifications/NotificationMailChannelTest.php b/tests/Notifications/NotificationMailChannelTest.php index f73c64e3c693..d36ea8923585 100644 --- a/tests/Notifications/NotificationMailChannelTest.php +++ b/tests/Notifications/NotificationMailChannelTest.php @@ -13,9 +13,7 @@ public function tearDown() public function testMailIsSentByChannel() { $notification = new NotificationMailChannelTestNotification; - $notifiables = collect([ - $notifiable = new NotificationMailChannelTestNotifiable, - ]); + $notifiable = new NotificationMailChannelTestNotifiable; $message = $notification->toMail($notifiable); $data = $message->toArray(); @@ -26,7 +24,7 @@ public function testMailIsSentByChannel() $mailer->shouldReceive('send')->with('notifications::email', $data, Mockery::type('Closure')); - $channel->send($notifiables, $notification); + $channel->send($notifiable, $notification); } } diff --git a/tests/Notifications/NotificationNexmoChannelTest.php b/tests/Notifications/NotificationNexmoChannelTest.php index ced9747cb198..781c561a3405 100644 --- a/tests/Notifications/NotificationNexmoChannelTest.php +++ b/tests/Notifications/NotificationNexmoChannelTest.php @@ -13,9 +13,7 @@ public function tearDown() public function testSmsIsSentViaNexmo() { $notification = new NotificationNexmoChannelTestNotification; - $notifiables = collect([ - $notifiable = new NotificationNexmoChannelTestNotifiable, - ]); + $notifiable = new NotificationNexmoChannelTestNotifiable; $notification->introLines = ['line 1']; $notification->actionText = 'Text'; @@ -36,7 +34,7 @@ public function testSmsIsSentViaNexmo() line 2', ]); - $channel->send($notifiables, $notification); + $channel->send($notifiable, $notification); } } diff --git a/tests/Notifications/NotificationSlackChannelTest.php b/tests/Notifications/NotificationSlackChannelTest.php index 7a0a6a387a2b..07a87fd998a7 100644 --- a/tests/Notifications/NotificationSlackChannelTest.php +++ b/tests/Notifications/NotificationSlackChannelTest.php @@ -13,9 +13,7 @@ public function tearDown() public function testCorrectPayloadIsSentToSlack() { $notification = new NotificationSlackChannelTestNotification; - $notifiables = collect([ - $notifiable = new NotificationSlackChannelTestNotifiable, - ]); + $notifiable = new NotificationSlackChannelTestNotifiable; $channel = new Illuminate\Notifications\Channels\SlackWebhookChannel( $http = Mockery::mock('GuzzleHttp\Client') @@ -38,7 +36,7 @@ public function testCorrectPayloadIsSentToSlack() ], ]); - $channel->send($notifiables, $notification); + $channel->send($notifiable, $notification); } } From cf92b46713e4703376c1275104b04d1e35d740d1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 12:00:14 -0500 Subject: [PATCH 144/249] add files --- .../Channels/BroadcastChannel.php | 63 +++++++++++++++ .../Events/BroadcastNotificationCreated.php | 81 +++++++++++++++++++ .../NotificationBroadcastChannelTest.php | 32 ++++++++ 3 files changed, 176 insertions(+) create mode 100644 src/Illuminate/Notifications/Channels/BroadcastChannel.php create mode 100644 src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php create mode 100644 tests/Notifications/NotificationBroadcastChannelTest.php diff --git a/src/Illuminate/Notifications/Channels/BroadcastChannel.php b/src/Illuminate/Notifications/Channels/BroadcastChannel.php new file mode 100644 index 000000000000..9bea64ee35bc --- /dev/null +++ b/src/Illuminate/Notifications/Channels/BroadcastChannel.php @@ -0,0 +1,63 @@ +events = $events; + } + + /** + * Send the given notification. + * + * @param mixed $notifiable + * @param \Illuminate\Notifications\Notification $notification + * @return void + */ + public function send($notifiable, Notification $notification) + { + $this->events->fire(new BroadcastNotificationCreated( + $notifiable, $notification, $this->getData($notifiable, $notification) + )); + } + + /** + * Get the data for the notification. + * + * @param mixed $notifiable + * @param \Illuminate\Notifications\Notification $notification + * @return array + * + * @throws \RuntimeException + */ + protected function getData($notifiable, Notification $notification) + { + if (method_exists($notification, 'toArray')) { + return $notification->toArray($notifiable); + } + + throw new RuntimeException( + "Notification is missing toArray method." + ); + } +} diff --git a/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php b/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php new file mode 100644 index 000000000000..851eb990afda --- /dev/null +++ b/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php @@ -0,0 +1,81 @@ +data = $data; + $this->notifiable = $notifiable; + $this->notification = $notification; + } + + /** + * Get the channels the event should broadcast on. + * + * @return array + */ + public function broadcastOn() + { + return [new PrivateChannel($this->channelName())]; + } + + /** + * Get the data that should be sent with the broadcasted event. + * + * @return array + */ + public function broadcastWith() + { + return array_merge($this->data, ['id' => $this->notification->id]); + } + + /** + * Get the broadcast channel name for the event. + * + * @return string + */ + protected function channelName() + { + $class = str_replace('\\', '.', get_class($this->notifiable)); + + return $class.'.'.$this->notifiable->getKey(); + } +} diff --git a/tests/Notifications/NotificationBroadcastChannelTest.php b/tests/Notifications/NotificationBroadcastChannelTest.php new file mode 100644 index 000000000000..db7954fcb17e --- /dev/null +++ b/tests/Notifications/NotificationBroadcastChannelTest.php @@ -0,0 +1,32 @@ +id = 1; + $notifiable = Mockery::mock(); + + $events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher'); + $events->shouldReceive('fire')->once()->with(Mockery::type('Illuminate\Notifications\Events\BroadcastNotificationCreated')); + $channel = new BroadcastChannel($events); + $channel->send($notifiable, $notification); + } +} + +class NotificationBroadcastChannelTestNotification extends Notification +{ + public function toArray($notifiable) + { + return ['invoice_id' => 1]; + } +} From af0391e26f1fd5e8aa7b17bb1bae77557cc1e3df Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 12:01:11 -0500 Subject: [PATCH 145/249] Applied fixes from StyleCI (#14698) --- src/Illuminate/Notifications/Channels/BroadcastChannel.php | 2 +- src/Illuminate/Notifications/Channels/DatabaseChannel.php | 2 +- src/Illuminate/Notifications/Messages/DatabaseMessage.php | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Notifications/Channels/BroadcastChannel.php b/src/Illuminate/Notifications/Channels/BroadcastChannel.php index 9bea64ee35bc..20a46c70f0ac 100644 --- a/src/Illuminate/Notifications/Channels/BroadcastChannel.php +++ b/src/Illuminate/Notifications/Channels/BroadcastChannel.php @@ -57,7 +57,7 @@ protected function getData($notifiable, Notification $notification) } throw new RuntimeException( - "Notification is missing toArray method." + 'Notification is missing toArray method.' ); } } diff --git a/src/Illuminate/Notifications/Channels/DatabaseChannel.php b/src/Illuminate/Notifications/Channels/DatabaseChannel.php index 3a43ad181225..1cb881bf416b 100644 --- a/src/Illuminate/Notifications/Channels/DatabaseChannel.php +++ b/src/Illuminate/Notifications/Channels/DatabaseChannel.php @@ -42,7 +42,7 @@ protected function getData($notifiable, Notification $notification) } throw new RuntimeException( - "Notification is missing toDatabase / toArray method." + 'Notification is missing toDatabase / toArray method.' ); } } diff --git a/src/Illuminate/Notifications/Messages/DatabaseMessage.php b/src/Illuminate/Notifications/Messages/DatabaseMessage.php index 54b00d0884ad..55707a7c065f 100644 --- a/src/Illuminate/Notifications/Messages/DatabaseMessage.php +++ b/src/Illuminate/Notifications/Messages/DatabaseMessage.php @@ -2,8 +2,6 @@ namespace Illuminate\Notifications\Messages; -use Illuminate\Support\Arr; - class DatabaseMessage { /** From 8ef4730ebb621d10a20ffe625050ceb9b535d63b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 12:08:27 -0500 Subject: [PATCH 146/249] cast to string --- src/Illuminate/Notifications/ChannelManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Notifications/ChannelManager.php b/src/Illuminate/Notifications/ChannelManager.php index eb890f975512..915cc5884d3d 100644 --- a/src/Illuminate/Notifications/ChannelManager.php +++ b/src/Illuminate/Notifications/ChannelManager.php @@ -50,7 +50,7 @@ public function sendNow($notifiables, $notification) foreach ($notifiables as $notifiable) { $notification = clone $notification; - $notification->id = Uuid::uuid4(); + $notification->id = (string) Uuid::uuid4(); $channels = $notification->via($notifiable); From 1b11ddc439d39b8937a89503075903a4953fe84d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 12:12:25 -0500 Subject: [PATCH 147/249] send notification type --- .../Notifications/Events/BroadcastNotificationCreated.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php b/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php index 851eb990afda..a24cc8b362cd 100644 --- a/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php +++ b/src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php @@ -64,7 +64,10 @@ public function broadcastOn() */ public function broadcastWith() { - return array_merge($this->data, ['id' => $this->notification->id]); + return array_merge($this->data, [ + 'id' => $this->notification->id, + 'type' => get_class($this->notification), + ]); } /** From f6fbc00e4fa522fcc573182a64172a82ae40f49e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 15:40:50 -0500 Subject: [PATCH 148/249] working on nexmo notifications --- .../Channels/NexmoSmsChannel.php | 40 ++------------ .../Notifications/Messages/NexmoMessage.php | 53 ++++++++++++++++++- .../NotificationNexmoChannelTest.php | 38 ++++++++----- 3 files changed, 81 insertions(+), 50 deletions(-) diff --git a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php index e80549f8f8ba..3dd9ac95c553 100644 --- a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php +++ b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php @@ -47,44 +47,12 @@ public function send($notifiable, Notification $notification) return; } + $message = $notification->toNexmo($notifiable); + $this->nexmo->message()->send([ - 'from' => $this->from, + 'from' => $message->from ?: $this->from, 'to' => $to, - 'text' => $this->formatNotification($notifiable, $notification), + 'text' => trim($message->content), ]); } - - /** - * Format the given notification to a single string. - * - * @param mixed $notifiable - * @param \Illuminate\Notifications\Notification $notification - * @return string - */ - protected function formatNotification($notifiable, $notification) - { - $message = $notification->toNexmo($notifiable); - - $actionText = $message->actionText - ? $message->actionText.': ' : ''; - - return trim(implode(PHP_EOL.PHP_EOL, array_filter([ - implode(' ', $message->introLines), - $actionText.$message->actionUrl, - implode(' ', $message->outroLines), - ]))); - } - - /** - * Set the phone number that should be used to send notification. - * - * @param string $from - * @return $this - */ - public function sendNotificationsFrom($from) - { - $this->from = $from; - - return $this; - } } diff --git a/src/Illuminate/Notifications/Messages/NexmoMessage.php b/src/Illuminate/Notifications/Messages/NexmoMessage.php index 1d83e8393c5f..e74063e742ca 100644 --- a/src/Illuminate/Notifications/Messages/NexmoMessage.php +++ b/src/Illuminate/Notifications/Messages/NexmoMessage.php @@ -2,7 +2,56 @@ namespace Illuminate\Notifications\Messages; -class NexmoMessage extends SimpleMessage +class NexmoMessage { - // + /** + * The message content. + * + * @var string + */ + public $content; + + /** + * The phone number the message should be sent from. + * + * @var string + */ + public $from; + + /** + * Create a new message instance. + * + * @param string $message + * @return void + */ + public function __construct($content = '') + { + $this->content = $content; + } + + /** + * Set the message contnet. + * + * @param string $content + * @return $this + */ + public function content($content) + { + $this->content = $content; + + return $this; + } + + /** + * Set the phone number the message should be sent from. + * + * @param string $number + * @return $this + */ + public function from($from) + { + $this->from = $from; + + return $this; + } } diff --git a/tests/Notifications/NotificationNexmoChannelTest.php b/tests/Notifications/NotificationNexmoChannelTest.php index 781c561a3405..abbe80692979 100644 --- a/tests/Notifications/NotificationNexmoChannelTest.php +++ b/tests/Notifications/NotificationNexmoChannelTest.php @@ -15,11 +15,6 @@ public function testSmsIsSentViaNexmo() $notification = new NotificationNexmoChannelTestNotification; $notifiable = new NotificationNexmoChannelTestNotifiable; - $notification->introLines = ['line 1']; - $notification->actionText = 'Text'; - $notification->actionUrl = 'url'; - $notification->outroLines = ['line 2']; - $channel = new Illuminate\Notifications\Channels\NexmoSmsChannel( $nexmo = Mockery::mock(Nexmo\Client::class), '4444444444' ); @@ -27,11 +22,25 @@ public function testSmsIsSentViaNexmo() $nexmo->shouldReceive('message->send')->with([ 'from' => '4444444444', 'to' => '5555555555', - 'text' => 'line 1 + 'text' => 'this is my message', + ]); + + $channel->send($notifiable, $notification); + } -Text: url + public function testSmsIsSentViaNexmoWithCustomFrom() + { + $notification = new NotificationNexmoChannelTestCustomFromNotification; + $notifiable = new NotificationNexmoChannelTestNotifiable; -line 2', + $channel = new Illuminate\Notifications\Channels\NexmoSmsChannel( + $nexmo = Mockery::mock(Nexmo\Client::class), '4444444444' + ); + + $nexmo->shouldReceive('message->send')->with([ + 'from' => '5554443333', + 'to' => '5555555555', + 'text' => 'this is my message', ]); $channel->send($notifiable, $notification); @@ -48,9 +57,14 @@ class NotificationNexmoChannelTestNotification extends Notification { public function toNexmo($notifiable) { - return (new NexmoMessage) - ->line('line 1') - ->action('Text', 'url') - ->line('line 2'); + return new NexmoMessage('this is my message'); + } +} + +class NotificationNexmoChannelTestCustomFromNotification extends Notification +{ + public function toNexmo($notifiable) + { + return (new NexmoMessage('this is my message'))->from('5554443333'); } } From 2b67c422c6f7024d09e91426760b5add016ad374 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 15:42:57 -0500 Subject: [PATCH 149/249] convert to message on plain string --- src/Illuminate/Notifications/Channels/NexmoSmsChannel.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php index 3dd9ac95c553..bc0cb21908cc 100644 --- a/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php +++ b/src/Illuminate/Notifications/Channels/NexmoSmsChannel.php @@ -4,6 +4,7 @@ use Nexmo\Client as NexmoClient; use Illuminate\Notifications\Notification; +use Illuminate\Notifications\Messages\NexmoMessage; class NexmoSmsChannel { @@ -49,6 +50,10 @@ public function send($notifiable, Notification $notification) $message = $notification->toNexmo($notifiable); + if (is_string($message)) { + $message = new NexmoMessage($message); + } + $this->nexmo->message()->send([ 'from' => $message->from ?: $this->from, 'to' => $to, From 25e6e0cd8400e3ec005baa05003c586c5c578c33 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 16:13:59 -0500 Subject: [PATCH 150/249] change comment --- src/Illuminate/Foundation/Console/stubs/notification.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/stubs/notification.stub b/src/Illuminate/Foundation/Console/stubs/notification.stub index a192a7ccb712..826660d3645a 100644 --- a/src/Illuminate/Foundation/Console/stubs/notification.stub +++ b/src/Illuminate/Foundation/Console/stubs/notification.stub @@ -22,7 +22,7 @@ class DummyClass extends Notification } /** - * Get the notification channels. + * Get the notification's delivery channels. * * @param mixed $notifiable * @return array|string From f708e42934fae5e4522fd54f1791e9440aa4fcb5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 16:14:41 -0500 Subject: [PATCH 151/249] clean up type hint --- src/Illuminate/Foundation/Console/stubs/notification.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/stubs/notification.stub b/src/Illuminate/Foundation/Console/stubs/notification.stub index 826660d3645a..cc537f517aff 100644 --- a/src/Illuminate/Foundation/Console/stubs/notification.stub +++ b/src/Illuminate/Foundation/Console/stubs/notification.stub @@ -25,7 +25,7 @@ class DummyClass extends Notification * Get the notification's delivery channels. * * @param mixed $notifiable - * @return array|string + * @return array */ public function via($notifiable) { From 5b2f861bd40b59851f70995c4972a79b42e5cb47 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2016 20:33:48 -0500 Subject: [PATCH 152/249] custom slack object --- .../Channels/SlackWebhookChannel.php | 52 +++++------ .../Messages/SlackAttachment.php | 75 +++++++++++++++ .../Notifications/Messages/SlackMessage.php | 92 ++++++++++++++++++- .../NotificationSlackChannelTest.php | 34 ++++--- 4 files changed, 206 insertions(+), 47 deletions(-) create mode 100644 src/Illuminate/Notifications/Messages/SlackAttachment.php diff --git a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php index ba8439f82cba..b75821bb63a9 100644 --- a/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php +++ b/src/Illuminate/Notifications/Channels/SlackWebhookChannel.php @@ -5,6 +5,7 @@ use GuzzleHttp\Client as HttpClient; use Illuminate\Notifications\Notification; use Illuminate\Notifications\Messages\SlackMessage; +use Illuminate\Notifications\Messages\SlackAttachment; class SlackWebhookChannel { @@ -43,50 +44,41 @@ public function send($notifiable, Notification $notification) $this->http->post($url, [ 'json' => [ - 'attachments' => [ - array_filter([ - 'color' => $this->color($message->level), - 'title' => $message->subject, - 'title_link' => $message->actionUrl ?: null, - 'text' => $this->format($message), - ]), - ], + 'text' => $message->content, + 'attachments' => $this->attachments($message), ], ]); } /** - * Format the given notification message. + * Format the message's attachments. * * @param \Illuminate\Notifications\Messages\SlackMessage $message - * @return string + * @return array */ - protected function format(SlackMessage $message) + protected function attachments(SlackMessage $message) { - $text = trim(implode(PHP_EOL.PHP_EOL, $message->introLines)); - - if ($message->actionText) { - $text .= PHP_EOL.PHP_EOL.'<'.$message->actionUrl.'|'.$message->actionText.'>'; - } - - $text .= PHP_EOL.PHP_EOL.trim(implode(PHP_EOL.PHP_EOL, $message->outroLines)); - - return trim($text); + return collect($message->attachments)->map(function ($attachment) use ($message) { + return array_filter([ + 'color' => $message->color(), + 'title' => $attachment->title, + 'text' => $attachment->content, + 'title_link' => $attachment->url, + 'fields' => $this->fields($attachment), + ]); + })->all(); } /** - * Get the color that should be applied to the notification. + * Format the attachment's fields. * - * @param string $level - * @return string|null + * @param \Illuminate\Notifications\Messages\SlackAttachment $attachment + * @return array */ - protected function color($level) + protected function fields(SlackAttachment $attachment) { - switch ($level) { - case 'success': - return 'good'; - case 'error': - return 'danger'; - } + return collect($attachment->fields)->map(function ($value, $key) { + return ['title' => $key, 'value' => $value, 'short' => true]; + })->values()->all(); } } diff --git a/src/Illuminate/Notifications/Messages/SlackAttachment.php b/src/Illuminate/Notifications/Messages/SlackAttachment.php new file mode 100644 index 000000000000..11b8a7ac0ef9 --- /dev/null +++ b/src/Illuminate/Notifications/Messages/SlackAttachment.php @@ -0,0 +1,75 @@ +title = $title; + $this->url = $url; + + return $this; + } + + /** + * Set the content (text) of the attachment. + * + * @param string $content + * @return $this + */ + public function content($content) + { + $this->content = $content; + + return $this; + } + + /** + * Set the fields of the attachment. + * + * @param array $fields + * @return $this + */ + public function fields(array $fields) + { + $this->fields = $fields; + + return $this; + } +} diff --git a/src/Illuminate/Notifications/Messages/SlackMessage.php b/src/Illuminate/Notifications/Messages/SlackMessage.php index ed4509f5048d..c20508f8fcf1 100644 --- a/src/Illuminate/Notifications/Messages/SlackMessage.php +++ b/src/Illuminate/Notifications/Messages/SlackMessage.php @@ -2,7 +2,95 @@ namespace Illuminate\Notifications\Messages; -class SlackMessage extends SimpleMessage +use Closure; + +class SlackMessage { - // + /** + * The "level" of the notification (info, success, error). + * + * @var string + */ + public $level = 'info'; + + /** + * The text content of the message. + * + * @var string + */ + public $content; + + /** + * The message's attachments. + * + * @var array + */ + public $attachments = []; + + /** + * Indicate that the notification gives information about a successful operation. + * + * @return $this + */ + public function success() + { + $this->level = 'success'; + + return $this; + } + + /** + * Indicate that the notification gives information about an error. + * + * @return $this + */ + public function error() + { + $this->level = 'error'; + + return $this; + } + + /** + * Set the content of the Slack message. + * + * @param string $content + * @return $this + */ + public function content($content) + { + $this->content = $content; + + return $this; + } + + /** + * Define an attachment for the message. + * + * @param \Closure $callback + * @return $this + */ + public function attachment(Closure $callback) + { + $this->attachments[] = $attachment = new SlackAttachment; + + $callback($attachment); + + return $this; + } + + /** + * Get the color for the message. + * + * @return string + */ + public function color() + { + switch ($this->level) { + case 'success': + return '#7CD197'; + case 'error': + return '#F35A00'; + } + } } diff --git a/tests/Notifications/NotificationSlackChannelTest.php b/tests/Notifications/NotificationSlackChannelTest.php index 07a87fd998a7..d91f75365d7b 100644 --- a/tests/Notifications/NotificationSlackChannelTest.php +++ b/tests/Notifications/NotificationSlackChannelTest.php @@ -21,16 +21,19 @@ public function testCorrectPayloadIsSentToSlack() $http->shouldReceive('post')->with('url', [ 'json' => [ + 'text' => 'Content', 'attachments' => [ [ - 'color' => 'good', - 'title' => 'Subject', - 'title_link' => 'url', - 'text' => 'line 1 - - - -line 2', + 'title' => 'Laravel', + 'title_link' => 'https://laravel.com', + 'text' => 'Attachment Content', + 'fields' => [ + [ + 'title' => 'Project', + 'value' => 'Laravel', + 'short' => true, + ], + ], ], ], ], @@ -44,8 +47,6 @@ class NotificationSlackChannelTestNotifiable { use Illuminate\Notifications\Notifiable; - public $phone_number = '5555555555'; - public function routeNotificationForSlack() { return 'url'; @@ -57,10 +58,13 @@ class NotificationSlackChannelTestNotification extends Notification public function toSlack($notifiable) { return (new SlackMessage) - ->subject('Subject') - ->success() - ->line('line 1') - ->action('Text', 'url') - ->line('line 2'); + ->content('Content') + ->attachment(function ($attachment) { + $attachment->title('Laravel', 'https://laravel.com') + ->content('Attachment Content') + ->fields([ + 'Project' => 'Laravel', + ]); + }); } } From e90635118a78508200b8f0144334d0a98fade6a2 Mon Sep 17 00:00:00 2001 From: Mark Beech Date: Tue, 9 Aug 2016 02:36:43 +0100 Subject: [PATCH 153/249] [5.3] Change $loop->index to $loop->iteration (#14706) * Change $loop->index to $loop->iteration and add correct $loop->index (start at 0) * Style fix --- src/Illuminate/View/Factory.php | 8 +++++--- tests/View/ViewFactoryTest.php | 9 +++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/View/Factory.php b/src/Illuminate/View/Factory.php index 7a4f6fdcb46d..2661b59528f8 100755 --- a/src/Illuminate/View/Factory.php +++ b/src/Illuminate/View/Factory.php @@ -802,6 +802,7 @@ public function addLoop($data) $parent = Arr::last($this->loopsStack); $this->loopsStack[] = [ + 'iteration' => 0, 'index' => 0, 'remaining' => isset($length) ? $length : null, 'count' => $length, @@ -821,14 +822,15 @@ public function incrementLoopIndices() { $loop = &$this->loopsStack[count($this->loopsStack) - 1]; - $loop['index']++; + $loop['iteration']++; + $loop['index'] = $loop['iteration'] - 1; - $loop['first'] = $loop['index'] == 1; + $loop['first'] = $loop['iteration'] == 1; if (isset($loop['count'])) { $loop['remaining']--; - $loop['last'] = $loop['index'] == $loop['count']; + $loop['last'] = $loop['iteration'] == $loop['count']; } } diff --git a/tests/View/ViewFactoryTest.php b/tests/View/ViewFactoryTest.php index 3115be8cec72..640f497dd3fe 100755 --- a/tests/View/ViewFactoryTest.php +++ b/tests/View/ViewFactoryTest.php @@ -455,6 +455,7 @@ public function testAddingLoops() $factory->addLoop([1, 2, 3]); $expectedLoop = [ + 'iteration' => 0, 'index' => 0, 'remaining' => 3, 'count' => 3, @@ -469,6 +470,7 @@ public function testAddingLoops() $factory->addLoop([1, 2, 3, 4]); $secondExpectedLoop = [ + 'iteration' => 0, 'index' => 0, 'remaining' => 4, 'count' => 4, @@ -491,6 +493,7 @@ public function testAddingUncountableLoop() $factory->addLoop(''); $expectedLoop = [ + 'iteration' => 0, 'index' => 0, 'remaining' => null, 'count' => null, @@ -513,7 +516,8 @@ public function testIncrementingLoopIndices() $factory->incrementLoopIndices(); - $this->assertEquals(2, $factory->getLoopStack()[0]['index']); + $this->assertEquals(2, $factory->getLoopStack()[0]['iteration']); + $this->assertEquals(1, $factory->getLoopStack()[0]['index']); $this->assertEquals(2, $factory->getLoopStack()[0]['remaining']); } @@ -540,7 +544,8 @@ public function testIncrementingLoopIndicesOfUncountable() $factory->incrementLoopIndices(); - $this->assertEquals(2, $factory->getLoopStack()[0]['index']); + $this->assertEquals(2, $factory->getLoopStack()[0]['iteration']); + $this->assertEquals(1, $factory->getLoopStack()[0]['index']); $this->assertFalse($factory->getLoopStack()[0]['first']); $this->assertNull($factory->getLoopStack()[0]['remaining']); $this->assertNull($factory->getLoopStack()[0]['last']); From e5bf0f45156f8d9565bfb5266254b0a0c250d6c7 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 9 Aug 2016 02:38:33 +0100 Subject: [PATCH 154/249] Increase the default reds timeout (#14695) --- src/Illuminate/Redis/Database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Redis/Database.php b/src/Illuminate/Redis/Database.php index 437427b17d23..fbffe1703779 100755 --- a/src/Illuminate/Redis/Database.php +++ b/src/Illuminate/Redis/Database.php @@ -26,7 +26,7 @@ public function __construct(array $servers = []) { $cluster = Arr::pull($servers, 'cluster'); - $options = (array) Arr::pull($servers, 'options'); + $options = array_merge(['timeout' => 10.0], (array) Arr::pull($servers, 'options')); if ($cluster) { $this->clients = $this->createAggregateClient($servers, $options); From d6b740816f30e9d7d398df19be3b3b1be34d3e3f Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 9 Aug 2016 02:38:47 +0100 Subject: [PATCH 155/249] Added missing notification dependency (#14694) --- src/Illuminate/Notifications/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Notifications/composer.json b/src/Illuminate/Notifications/composer.json index 285dec42a163..7df681042ac7 100644 --- a/src/Illuminate/Notifications/composer.json +++ b/src/Illuminate/Notifications/composer.json @@ -18,7 +18,8 @@ "illuminate/bus": "5.3.*", "illuminate/broadcasting": "5.3.*", "illuminate/contracts": "5.3.*", - "illuminate/support": "5.3.*" + "illuminate/support": "5.3.*", + "ramsey/uuid": "~3.0" }, "autoload": { "psr-4": { From 233b9d8aeb545f8e2ef82e5ed436e4bbf6fa589c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Mon, 8 Aug 2016 18:38:58 -0700 Subject: [PATCH 156/249] Added release notes for v5.2.42 (#14692) --- CHANGELOG.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a80d6ff302b..9247b9538739 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,34 @@ # Release Notes +## v5.2.42 (2016-08-08) + +### Added +- Allow `BelongsToMany::detach()` to accept a collection ([#14412](https://github.com/laravel/framework/pull/14412)) +- Added `whereTime()` and `orWhereTime()` to query builder ([#14528](https://github.com/laravel/framework/pull/14528)) +- Added PHP 7.1 support ([#14549](https://github.com/laravel/framework/pull/14549)) +- Allow collections to be created from objects that implement `Traversable` ([#14628](https://github.com/laravel/framework/pull/14628)) +- Support dot notation in `Request::exists()` ([#14660](https://github.com/laravel/framework/pull/14660)) +- Added missing `Model::makeHidden()` method ([#14641](https://github.com/laravel/framework/pull/14641)) + +### Changed +- Return `true` when `$key` is empty in `MessageBag::has()` ([#14409](https://github.com/laravel/framework/pull/14409)) +- Optimized `Filesystem::moveDirectory` ([#14362](https://github.com/laravel/framework/pull/14362)) +- Convert `$count` to integer in `Str::plural()` ([#14502](https://github.com/laravel/framework/pull/14502)) +- Handle arrays in `validateIn()` method ([#14607](https://github.com/laravel/framework/pull/14607)) + +### Fixed +- Fixed an issue with `wherePivotIn()` ([#14397](https://github.com/laravel/framework/issues/14397)) +- Fixed PDO connection on HHVM ([#14429](https://github.com/laravel/framework/pull/14429)) +- Prevent `make:migration` from creating duplicate classes ([#14432](https://github.com/laravel/framework/pull/14432)) +- Fixed lazy eager loading issue in `LengthAwarePaginator` collection ([#14476](https://github.com/laravel/framework/pull/14476)) +- Fixed plural form of Pokémon ([#14525](https://github.com/laravel/framework/pull/14525)) +- Fixed authentication bug in `TokenGuard::validate()` ([#14568](https://github.com/laravel/framework/pull/14568)) +- Fix missing middleware parameters when using `authorizeResource()` ([#14592](https://github.com/laravel/framework/pull/14592)) + +### Removed +- Removed duplicate interface implementation in `Dispatcher` ([#14515](https://github.com/laravel/framework/pull/14515)) + + ## v5.2.41 (2016-07-20) ### Changed From 8a2ca60dfcd0a6fa67ef9b1ffbb8ab4ad2a0530a Mon Sep 17 00:00:00 2001 From: Matt McDonald Date: Tue, 9 Aug 2016 02:39:36 +0100 Subject: [PATCH 157/249] Allow custom $attributes, default to web middleware (#14691) --- src/Illuminate/Broadcasting/BroadcastManager.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Broadcasting/BroadcastManager.php b/src/Illuminate/Broadcasting/BroadcastManager.php index e44e6f436b7c..289151bc7db5 100644 --- a/src/Illuminate/Broadcasting/BroadcastManager.php +++ b/src/Illuminate/Broadcasting/BroadcastManager.php @@ -49,18 +49,20 @@ public function __construct($app) /** * Register the routes for handling broadcast authentication and sockets. * - * @param array $attributes + * @param array|null $attributes * @return void */ - public function routes() + public function routes(array $attributes = null) { if ($this->app->routesAreCached()) { return; } + $attributes = $attributes ?: ['middleware' => ['web']]; + $router = $this->app['router']; - $router->group(['middleware' => ['web']], function ($router) { + $router->group($attributes, function ($router) { $router->post('/broadcasting/auth', BroadcastController::class.'@authenticate'); $router->post('/broadcasting/socket', BroadcastController::class.'@rememberSocket'); }); From c4cc67d77a5ed07a7de202abc4e22f2dbadf341a Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Tue, 9 Aug 2016 03:40:07 +0200 Subject: [PATCH 158/249] closes #14679 by fixing the route list command for single action controllers (#14683) --- src/Illuminate/Foundation/Console/RouteListCommand.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index 1abd6cae669e..2776068236d2 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -159,7 +159,8 @@ protected function getControllerMiddleware($actionName) $segments = explode('@', $actionName); return $this->getControllerMiddlewareFromInstance( - $this->laravel->make($segments[0]), $segments[1] + $this->laravel->make($segments[0]), + isset($segments[1]) ? $segments[1] : null ); } @@ -167,7 +168,7 @@ protected function getControllerMiddleware($actionName) * Get the middlewares for the given controller instance and method. * * @param \Illuminate\Routing\Controller $controller - * @param string $method + * @param string|null $method * @return array */ protected function getControllerMiddlewareFromInstance($controller, $method) @@ -177,7 +178,7 @@ protected function getControllerMiddlewareFromInstance($controller, $method) $results = []; foreach ($controller->getMiddleware() as $name => $options) { - if (! $this->methodExcludedByOptions($method, $options)) { + if (! $method || ! $this->methodExcludedByOptions($method, $options)) { $results[] = Arr::get($middleware, $name, $name); } } From 1d5b82d27c122e05098ad12ec50143ccb08869bf Mon Sep 17 00:00:00 2001 From: Martin Zurowietz Date: Tue, 9 Aug 2016 10:38:29 +0200 Subject: [PATCH 159/249] Support column aliases in chunkById References #14499 --- tests/Database/DatabaseQueryBuilderTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index b7b731a4e001..3c55d8331e23 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -1712,6 +1712,19 @@ public function testChunkPaginatesUsingId() }, 'someIdField'); } + public function testChunkPaginatesUsingIdWithAlias() + { + $builder = $this->getMockQueryBuilder(); + $builder->shouldReceive('forPageAfterId')->once()->with(2, 0, 'table.id')->andReturn($builder); + $builder->shouldReceive('forPageAfterId')->once()->with(2, 10, 'table.id')->andReturn($builder); + $builder->shouldReceive('get')->times(2)->andReturn( + [(object) ['table_id' => 1], (object) ['table_id' => 10]], + [] + ); + $builder->chunkById(2, function ($results) { + }, 'table.id', 'table_id'); + } + public function testPaginate() { $perPage = 16; From 3e1338b0a537f5086ce2741890c247ddbc2dea33 Mon Sep 17 00:00:00 2001 From: Rafael Mello Campanari Date: Tue, 9 Aug 2016 10:53:22 -0300 Subject: [PATCH 160/249] Fixes undefined index "aggregate" when you try to use paginator with fetchMode set to Entity (#14716) * Fixes undefined index "aggregate" when you try to use paginator with PDO::fetchMode to a custom Object * Builder | fix return casting on getCountForPagination --- src/Illuminate/Database/Query/Builder.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 6b14ad182aaf..a42067cd1284 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1709,7 +1709,17 @@ public function getCountForPagination($columns = ['*']) return count($results); } - return isset($results[0]) ? (int) array_change_key_case((array) $results[0])['aggregate'] : 0; + if (! isset($results[0])) { + return 0; + } + + $item = $results[0]; + + if (is_object($item)) { + return (int) $item->aggregate; + } + + return (int) array_change_key_case((array) $item)['aggregate']; } /** From 8f95e8566ed2c2fc0decb73371ce94d06d43526f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 08:53:34 -0500 Subject: [PATCH 161/249] Applied fixes from StyleCI (#14717) --- src/Illuminate/Database/Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index a42067cd1284..6a21fba028e3 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1718,7 +1718,7 @@ public function getCountForPagination($columns = ['*']) if (is_object($item)) { return (int) $item->aggregate; } - + return (int) array_change_key_case((array) $item)['aggregate']; } From 593b33986c1af67b0478d1de87d7fad8609e797f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 09:30:07 -0500 Subject: [PATCH 162/249] tweak database channel --- src/Illuminate/Notifications/Channels/DatabaseChannel.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Notifications/Channels/DatabaseChannel.php b/src/Illuminate/Notifications/Channels/DatabaseChannel.php index 1cb881bf416b..883578c00b83 100644 --- a/src/Illuminate/Notifications/Channels/DatabaseChannel.php +++ b/src/Illuminate/Notifications/Channels/DatabaseChannel.php @@ -36,7 +36,9 @@ public function send($notifiable, Notification $notification) protected function getData($notifiable, Notification $notification) { if (method_exists($notification, 'toDatabase')) { - return $notification->toDatabase($notifiable)->data; + $data = $notification->toDatabase($notifiable); + + return is_array($data) ? $data : $data->data; } elseif (method_exists($notification, 'toArray')) { return $notification->toArray($notifiable); } From bb3d5b0a60b0e93e8e95eb60387e6bc42bbeb0db Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 12:32:58 -0500 Subject: [PATCH 163/249] 403 on private channels when nobody is logged in --- src/Illuminate/Broadcasting/BroadcastController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Broadcasting/BroadcastController.php b/src/Illuminate/Broadcasting/BroadcastController.php index e4b704f5436f..0913052adf7d 100644 --- a/src/Illuminate/Broadcasting/BroadcastController.php +++ b/src/Illuminate/Broadcasting/BroadcastController.php @@ -17,7 +17,8 @@ class BroadcastController extends Controller */ public function authenticate(Request $request) { - if (Str::startsWith($request->channel_name, 'presence-') && ! $request->user()) { + if (Str::startsWith($request->channel_name, ['private-', 'presence-']) && + ! $request->user()) { abort(403); } From d5025ce76d4f733557fbf368545f5f6d815a24db Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 14:47:46 -0500 Subject: [PATCH 164/249] working on broadcasting --- .../Broadcasting/BroadcastController.php | 18 +------- .../Broadcasting/BroadcastManager.php | 36 ++------------- .../Broadcasting/Broadcasters/Broadcaster.php | 29 +----------- .../Broadcasters/PusherBroadcaster.php | 28 +++++++++++- .../Broadcasters/RedisBroadcaster.php | 45 ++++++++++++++++++- .../Contracts/Broadcasting/Broadcaster.php | 17 +++++++ 6 files changed, 93 insertions(+), 80 deletions(-) diff --git a/src/Illuminate/Broadcasting/BroadcastController.php b/src/Illuminate/Broadcasting/BroadcastController.php index 0913052adf7d..9d10903862f4 100644 --- a/src/Illuminate/Broadcasting/BroadcastController.php +++ b/src/Illuminate/Broadcasting/BroadcastController.php @@ -13,26 +13,10 @@ class BroadcastController extends Controller * Authenticate the request for channel access. * * @param \Illuminate\Http\Request $request - * @return void + * @return \Illuminate\Http\Response */ public function authenticate(Request $request) { - if (Str::startsWith($request->channel_name, ['private-', 'presence-']) && - ! $request->user()) { - abort(403); - } - return Broadcast::check($request); } - - /** - * Store the socket ID for the current user. - * - * @param \Illuminate\Http\Request $request - * @return void - */ - public function rememberSocket(Request $request) - { - return Broadcast::rememberSocket($request); - } } diff --git a/src/Illuminate/Broadcasting/BroadcastManager.php b/src/Illuminate/Broadcasting/BroadcastManager.php index 289151bc7db5..4b79bdfca593 100644 --- a/src/Illuminate/Broadcasting/BroadcastManager.php +++ b/src/Illuminate/Broadcasting/BroadcastManager.php @@ -60,11 +60,8 @@ public function routes(array $attributes = null) $attributes = $attributes ?: ['middleware' => ['web']]; - $router = $this->app['router']; - - $router->group($attributes, function ($router) { + $this->app['router']->group($attributes, function ($router) { $router->post('/broadcasting/auth', BroadcastController::class.'@authenticate'); - $router->post('/broadcasting/socket', BroadcastController::class.'@rememberSocket'); }); } @@ -82,36 +79,9 @@ public function socket($request = null) $request = $request ?: $this->app['request']; - if ($request->hasHeader('X-Socket-Id')) { - return $request->header('X-Socket-Id'); - } - - if (! $request->hasSession()) { - return; + if ($request->hasHeader('X-Socket-ID')) { + return $request->header('X-Socket-ID'); } - - return $this->app['cache']->get( - 'broadcast:socket:'.$request->session()->getId() - ); - } - - /** - * Remember the socket for the given request. - * - * @param \Illuminate\Http\Request|null $request - * @return void - */ - public function rememberSocket($request = null) - { - if (! $request && ! $this->app->bound('request')) { - return; - } - - $request = $request ?: $this->app['request']; - - $this->app['cache']->forever( - 'broadcast:socket:'.$request->session()->getId(), $request->socket_id - ); } /** diff --git a/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php index 05e7e47329b6..466112f8c8f4 100644 --- a/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php +++ b/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php @@ -15,11 +15,6 @@ abstract class Broadcaster implements BroadcasterContract */ protected $channels = []; - /** - * {@inheritdoc} - */ - abstract public function broadcast(array $channels, $event, array $payload = []); - /** * Register a channel authenticator. * @@ -38,12 +33,11 @@ public function auth($channel, callable $callback) * Authenticate the incoming request for a given channel. * * @param \Illuminate\Http\Request $request + * @param string $channel * @return mixed */ - public function check($request) + protected function verifyUserCanAccessChannel($request, $channel) { - $channel = str_replace(['private-', 'presence-'], '', $request->channel_name); - foreach ($this->channels as $pattern => $callback) { if (! Str::is($pattern, $channel)) { continue; @@ -83,25 +77,6 @@ protected function extractAuthParameters($pattern, $channel) return []; } - /** - * Return the valid Pusher authentication response. - * - * @param \Illuminate\Http\Request $request - * @param mixed $result - * @return mixed - */ - protected function validAuthenticationResponse($request, $result) - { - if (is_bool($result)) { - return json_encode($result); - } - - return json_encode(['channel_data' => [ - 'user_id' => $request->user()->getKey(), - 'user_info' => $result, - ]]); - } - /** * Format the channel array into an array of strings. * diff --git a/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php index 17006cc8cad2..f2bd00116061 100644 --- a/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php +++ b/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php @@ -5,6 +5,7 @@ use Pusher; use Illuminate\Support\Arr; use Illuminate\Support\Str; +use Symfony\Component\HttpKernel\Exception\HttpException; class PusherBroadcaster extends Broadcaster { @@ -27,7 +28,25 @@ public function __construct(Pusher $pusher) } /** - * Return the valid Pusher authentication response. + * Authenticate the incoming request for a given channel. + * + * @param \Illuminate\Http\Request $request + * @return mixed + */ + public function check($request) + { + if (Str::startsWith($request->channel_name, ['private-', 'presence-']) && + ! $request->user()) { + throw new HttpException(403); + } + + return parent::verifyUserCanAccessChannel( + $request, str_replace(['private-', 'presence-'], '', $request->channel_name) + ); + } + + /** + * Return the valid authentication response. * * @param \Illuminate\Http\Request $request * @param mixed $result @@ -45,7 +64,12 @@ protected function validAuthenticationResponse($request, $result) } /** - * {@inheritdoc} + * Broadcast the given event. + * + * @param array $channels + * @param string $event + * @param array $payload + * @return void */ public function broadcast(array $channels, $event, array $payload = []) { diff --git a/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php index e00e2653753b..337557fd30ce 100644 --- a/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php +++ b/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php @@ -4,6 +4,7 @@ use Illuminate\Support\Arr; use Illuminate\Contracts\Redis\Database as RedisDatabase; +use Symfony\Component\HttpKernel\Exception\HttpException; class RedisBroadcaster extends Broadcaster { @@ -35,7 +36,49 @@ public function __construct(RedisDatabase $redis, $connection = null) } /** - * {@inheritdoc} + * Authenticate the incoming request for a given channel. + * + * @param \Illuminate\Http\Request $request + * @return mixed + */ + public function check($request) + { + if (Str::startsWith($request->channel_name, ['private-', 'presence-']) && + ! $request->user()) { + throw new HttpException(403); + } + + return parent::verifyUserCanAccessChannel( + $request, str_replace(['private-', 'presence-'], '', $request->channel_name) + ); + } + + /** + * Return the valid authentication response. + * + * @param \Illuminate\Http\Request $request + * @param mixed $result + * @return mixed + */ + protected function validAuthenticationResponse($request, $result) + { + if (is_bool($result)) { + return json_encode($result); + } + + return json_encode(['channel_data' => [ + 'user_id' => $request->user()->getKey(), + 'user_info' => $result, + ]]); + } + + /** + * Broadcast the given event. + * + * @param array $channels + * @param string $event + * @param array $payload + * @return void */ public function broadcast(array $channels, $event, array $payload = []) { diff --git a/src/Illuminate/Contracts/Broadcasting/Broadcaster.php b/src/Illuminate/Contracts/Broadcasting/Broadcaster.php index 73643669c2b4..e8c89fd36e1c 100644 --- a/src/Illuminate/Contracts/Broadcasting/Broadcaster.php +++ b/src/Illuminate/Contracts/Broadcasting/Broadcaster.php @@ -4,6 +4,23 @@ interface Broadcaster { + /** + * Authenticate the incoming request for a given channel. + * + * @param \Illuminate\Http\Request $request + * @return mixed + */ + public function check($request); + + /** + * Return the valid authentication response. + * + * @param \Illuminate\Http\Request $request + * @param mixed $result + * @return mixed + */ + public function validAuthenticationResponse($request, $result); + /** * Broadcast the given event. * From dacf5d80efae125b7bdc0cd46fe28108cf20930f Mon Sep 17 00:00:00 2001 From: Jeffrey Way Date: Tue, 9 Aug 2016 16:32:01 -0400 Subject: [PATCH 165/249] Fix typo (#14721) I mean, were you raised in a barn? --- src/Illuminate/Notifications/Messages/NexmoMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Notifications/Messages/NexmoMessage.php b/src/Illuminate/Notifications/Messages/NexmoMessage.php index e74063e742ca..23ebbe622f79 100644 --- a/src/Illuminate/Notifications/Messages/NexmoMessage.php +++ b/src/Illuminate/Notifications/Messages/NexmoMessage.php @@ -30,7 +30,7 @@ public function __construct($content = '') } /** - * Set the message contnet. + * Set the message content. * * @param string $content * @return $this From c3cb76095d4a0cdbc8f6a50608d6623ec487cee4 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 15:45:50 -0500 Subject: [PATCH 166/249] refactor broadcasting a bit --- .../Broadcasting/BroadcastManager.php | 29 +++++++++++++++++++ src/Illuminate/Events/Dispatcher.php | 12 ++------ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/Illuminate/Broadcasting/BroadcastManager.php b/src/Illuminate/Broadcasting/BroadcastManager.php index 4b79bdfca593..9213ee13e3ea 100644 --- a/src/Illuminate/Broadcasting/BroadcastManager.php +++ b/src/Illuminate/Broadcasting/BroadcastManager.php @@ -7,6 +7,7 @@ use Illuminate\Support\Arr; use InvalidArgumentException; use Illuminate\Broadcasting\Broadcasters\LogBroadcaster; +use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Broadcasting\Broadcasters\NullBroadcaster; use Illuminate\Broadcasting\Broadcasters\RedisBroadcaster; use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster; @@ -84,6 +85,34 @@ public function socket($request = null) } } + /** + * Begin broadcasting an event. + * + * @param mixed $event + * @return \Illuminate\Broadcasting\PendingBroadcast + */ + public function event($event) + { + return new PendingBroadcast($this->app->make('events'), $event); + } + + /** + * Queue the given event for broadcast. + * + * @param mixed $event + * @return void + */ + public function queue($event) + { + $connection = $event instanceof ShouldBroadcastNow ? 'sync' : null; + + $queue = method_exists($event, 'onQueue') ? $event->onQueue() : null; + + $this->app->make('queue')->connection($connection)->pushOn( + $queue, BroadcastEvent::class, ['event' => serialize(clone $event)] + ); + } + /** * Get a driver instance. * diff --git a/src/Illuminate/Events/Dispatcher.php b/src/Illuminate/Events/Dispatcher.php index 63dc8996f034..54353e100ae5 100755 --- a/src/Illuminate/Events/Dispatcher.php +++ b/src/Illuminate/Events/Dispatcher.php @@ -7,8 +7,8 @@ use Illuminate\Support\Str; use Illuminate\Container\Container; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; -use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Contracts\Events\Dispatcher as DispatcherContract; +use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory; use Illuminate\Contracts\Container\Container as ContainerContract; class Dispatcher implements DispatcherContract @@ -252,15 +252,7 @@ public function fire($event, $payload = [], $halt = false) */ protected function broadcastEvent($event) { - if ($this->queueResolver) { - $connection = $event instanceof ShouldBroadcastNow ? 'sync' : null; - - $queue = method_exists($event, 'onQueue') ? $event->onQueue() : null; - - $this->resolveQueue()->connection($connection)->pushOn($queue, 'Illuminate\Broadcasting\BroadcastEvent', [ - 'event' => serialize(clone $event), - ]); - } + $this->container->make(BroadcastFactory::class)->queue($event); } /** From 1b0567a40050e58ac018b45cf019d033afc473de Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 15:45:55 -0500 Subject: [PATCH 167/249] add files --- .../Broadcasting/PendingBroadcast.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/Illuminate/Broadcasting/PendingBroadcast.php diff --git a/src/Illuminate/Broadcasting/PendingBroadcast.php b/src/Illuminate/Broadcasting/PendingBroadcast.php new file mode 100644 index 000000000000..95c57c574fe3 --- /dev/null +++ b/src/Illuminate/Broadcasting/PendingBroadcast.php @@ -0,0 +1,54 @@ +event = $event; + $this->events = $events; + } + + /** + * Broadcast the event to all listeners. + * + * @return void + */ + public function all() + { + $this->events->fire($event->broadcastToEveryone()); + } + + /** + * Broadcast the event to everyone except the current user. + * + * @return void + */ + public function others() + { + $this->events->fire($event->dontBroadcastToCurrentUser()); + } +} From 3d5ad0c62968f4adbf57f787cb4220bd2cb091f2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 15:48:04 -0500 Subject: [PATCH 168/249] add helper --- src/Illuminate/Foundation/helpers.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index 3414e3df4c9f..aa9823763036 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -12,6 +12,7 @@ use Illuminate\Contracts\Cookie\Factory as CookieFactory; use Illuminate\Database\Eloquent\Factory as EloquentFactory; use Illuminate\Contracts\Validation\Factory as ValidationFactory; +use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory; if (! function_exists('abort')) { /** @@ -191,6 +192,19 @@ function bcrypt($value, $options = []) } } +if (! function_exists('broadcast')) { + /** + * Begin broadcasting an event. + * + * @param mixed $event + * @return \Illuminate\Broadcasting\PendingBroadcast + */ + function broadcast($event) + { + return app(BroadcastFactory::class)->event($event); + } +} + if (! function_exists('cache')) { /** * Get / set the specified cache value. From 1ba832d9ccd94d3ab601e3aca6c70fb1eebb280b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 15:48:38 -0500 Subject: [PATCH 169/249] Applied fixes from StyleCI (#14726) --- src/Illuminate/Broadcasting/BroadcastController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Broadcasting/BroadcastController.php b/src/Illuminate/Broadcasting/BroadcastController.php index 9d10903862f4..c80707f2857a 100644 --- a/src/Illuminate/Broadcasting/BroadcastController.php +++ b/src/Illuminate/Broadcasting/BroadcastController.php @@ -2,7 +2,6 @@ namespace Illuminate\Broadcasting; -use Illuminate\Support\Str; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Broadcast; From 104edbb99dfa43dfd10781c18f812977ed5c02cd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 15:52:55 -0500 Subject: [PATCH 170/249] fix vis --- src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php | 2 +- src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php index f2bd00116061..b3fa46adea79 100644 --- a/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php +++ b/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php @@ -52,7 +52,7 @@ public function check($request) * @param mixed $result * @return mixed */ - protected function validAuthenticationResponse($request, $result) + public function validAuthenticationResponse($request, $result) { if (Str::startsWith($request->channel_name, 'private')) { return $this->pusher->socket_auth($request->channel_name, $request->socket_id); diff --git a/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php index 337557fd30ce..6b018f6c6b47 100644 --- a/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php +++ b/src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php @@ -60,7 +60,7 @@ public function check($request) * @param mixed $result * @return mixed */ - protected function validAuthenticationResponse($request, $result) + public function validAuthenticationResponse($request, $result) { if (is_bool($result)) { return json_encode($result); From 5154ec4858ccf41bd3d8a05a4caaaac22e8d7be3 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 16:01:18 -0500 Subject: [PATCH 171/249] fix typo --- src/Illuminate/Broadcasting/PendingBroadcast.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Broadcasting/PendingBroadcast.php b/src/Illuminate/Broadcasting/PendingBroadcast.php index 95c57c574fe3..90e46b850cce 100644 --- a/src/Illuminate/Broadcasting/PendingBroadcast.php +++ b/src/Illuminate/Broadcasting/PendingBroadcast.php @@ -39,7 +39,7 @@ public function __construct(Dispatcher $events, $event) */ public function all() { - $this->events->fire($event->broadcastToEveryone()); + $this->events->fire($this->event->broadcastToEveryone()); } /** @@ -49,6 +49,6 @@ public function all() */ public function others() { - $this->events->fire($event->dontBroadcastToCurrentUser()); + $this->events->fire($this->event->dontBroadcastToCurrentUser()); } } From 50149925f0ce22f4216af8b8311415f0e7e8f926 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 16:37:33 -0500 Subject: [PATCH 172/249] working on broadcasting --- .../Broadcasting/BroadcastManager.php | 14 +++++++--- .../Broadcasting/PendingBroadcast.php | 27 ++++--------------- src/Illuminate/Foundation/helpers.php | 6 ++--- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/Illuminate/Broadcasting/BroadcastManager.php b/src/Illuminate/Broadcasting/BroadcastManager.php index 9213ee13e3ea..0f31300a6c17 100644 --- a/src/Illuminate/Broadcasting/BroadcastManager.php +++ b/src/Illuminate/Broadcasting/BroadcastManager.php @@ -88,12 +88,18 @@ public function socket($request = null) /** * Begin broadcasting an event. * - * @param mixed $event - * @return \Illuminate\Broadcasting\PendingBroadcast + * @param mixed|null $event + * @return \Illuminate\Broadcasting\PendingBroadcast|void */ - public function event($event) + public function event($event = null) { - return new PendingBroadcast($this->app->make('events'), $event); + $events = $this->app->make('events'); + + if (is_null($event)) { + return new PendingBroadcast($events); + } else { + $events->fire($event->broadcastToEveryone()); + } } /** diff --git a/src/Illuminate/Broadcasting/PendingBroadcast.php b/src/Illuminate/Broadcasting/PendingBroadcast.php index 90e46b850cce..b5d4ba94eb9f 100644 --- a/src/Illuminate/Broadcasting/PendingBroadcast.php +++ b/src/Illuminate/Broadcasting/PendingBroadcast.php @@ -13,42 +13,25 @@ class PendingBroadcast */ protected $events; - /** - * The event instance. - * - * @var mixed - */ - protected $event; - /** * Create a new pending broadcast instance. * * @param \Illuminate\Contracts\Events\Dispatcher $events - * @param - */ - public function __construct(Dispatcher $events, $event) - { - $this->event = $event; - $this->events = $events; - } - - /** - * Broadcast the event to all listeners. - * * @return void */ - public function all() + public function __construct(Dispatcher $events) { - $this->events->fire($this->event->broadcastToEveryone()); + $this->events = $events; } /** * Broadcast the event to everyone except the current user. * + * @param mixed $event * @return void */ - public function others() + public function toOthers($event) { - $this->events->fire($this->event->dontBroadcastToCurrentUser()); + $this->events->fire($event->dontBroadcastToCurrentUser()); } } diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index aa9823763036..03fb822a998f 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -196,10 +196,10 @@ function bcrypt($value, $options = []) /** * Begin broadcasting an event. * - * @param mixed $event - * @return \Illuminate\Broadcasting\PendingBroadcast + * @param mixed|null $event + * @return \Illuminate\Broadcasting\PendingBroadcast|void */ - function broadcast($event) + function broadcast($event = null) { return app(BroadcastFactory::class)->event($event); } From 00509480af6691a60ba5dfbde7649fc35b4a1e76 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 9 Aug 2016 16:40:57 -0500 Subject: [PATCH 173/249] tweak so errors arent thrown if not broadcastable --- src/Illuminate/Broadcasting/BroadcastManager.php | 8 ++++++-- src/Illuminate/Broadcasting/PendingBroadcast.php | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Broadcasting/BroadcastManager.php b/src/Illuminate/Broadcasting/BroadcastManager.php index 0f31300a6c17..0a97db0a90fc 100644 --- a/src/Illuminate/Broadcasting/BroadcastManager.php +++ b/src/Illuminate/Broadcasting/BroadcastManager.php @@ -97,9 +97,13 @@ public function event($event = null) if (is_null($event)) { return new PendingBroadcast($events); - } else { - $events->fire($event->broadcastToEveryone()); } + + if (method_exists($event, 'broadcastToEveryone')) { + $event->broadcastToEveryone(); + } + + $events->fire($event); } /** diff --git a/src/Illuminate/Broadcasting/PendingBroadcast.php b/src/Illuminate/Broadcasting/PendingBroadcast.php index b5d4ba94eb9f..f2ac0d3d7de9 100644 --- a/src/Illuminate/Broadcasting/PendingBroadcast.php +++ b/src/Illuminate/Broadcasting/PendingBroadcast.php @@ -32,6 +32,10 @@ public function __construct(Dispatcher $events) */ public function toOthers($event) { - $this->events->fire($event->dontBroadcastToCurrentUser()); + if (method_exists($event, 'dontBroadcastToCurrentUser')) { + $event->dontBroadcastToCurrentUser(); + } + + $this->events->fire($event); } } From 4f3eede482cca4e00f8a1e152ac47143932bc07c Mon Sep 17 00:00:00 2001 From: Chris Nanney Date: Tue, 9 Aug 2016 19:59:34 -0500 Subject: [PATCH 174/249] Fix Request file() return type hint (#14725) `allFiles()` is an array of `\Illuminate\Http\UploadedFile`, not `\Symfony\Component\HttpFoundation\File\UploadedFile`. --- src/Illuminate/Http/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index 555dddb75a95..d7d08f6d1cf0 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -461,7 +461,7 @@ protected function convertUploadedFiles(array $files) * * @param string $key * @param mixed $default - * @return \Symfony\Component\HttpFoundation\File\UploadedFile|array|null + * @return \Illuminate\Http\UploadedFile|array|null */ public function file($key = null, $default = null) { From 10930648680920a50645f8fa70d98351b1505e74 Mon Sep 17 00:00:00 2001 From: Matt McDonald Date: Tue, 9 Aug 2016 09:33:15 +0100 Subject: [PATCH 175/249] Command to create notifications table --- .../Providers/ArtisanServiceProvider.php | 14 ++++ .../Console/NotificationTableCommand.php | 81 +++++++++++++++++++ .../Console/stubs/notifications.stub | 37 +++++++++ 3 files changed, 132 insertions(+) create mode 100644 src/Illuminate/Notifications/Console/NotificationTableCommand.php create mode 100644 src/Illuminate/Notifications/Console/stubs/notifications.stub diff --git a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php index 83f1ec090081..08a1c440ff17 100755 --- a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php @@ -41,6 +41,7 @@ use Illuminate\Foundation\Console\VendorPublishCommand; use Illuminate\Database\Console\Seeds\SeederMakeCommand; use Illuminate\Foundation\Console\NotificationMakeCommand; +use Illuminate\Notifications\Console\NotificationTableCommand; class ArtisanServiceProvider extends ServiceProvider { @@ -93,6 +94,7 @@ class ArtisanServiceProvider extends ServiceProvider 'MiddlewareMake' => 'command.middleware.make', 'ModelMake' => 'command.model.make', 'NotificationMake' => 'command.notification.make', + 'NotificationTable' => 'command.notification.table', 'PolicyMake' => 'command.policy.make', 'ProviderMake' => 'command.provider.make', 'QueueFailedTable' => 'command.queue.failed-table', @@ -590,6 +592,18 @@ protected function registerPolicyMakeCommand() }); } + /** + * Register the command. + * + * @return void + */ + protected function registerNotificationTableCommand() + { + $this->app->singleton('command.notification.table', function ($app) { + return new NotificationTableCommand($app['files'], $app['composer']); + }); + } + /** * Get the services provided by the provider. * diff --git a/src/Illuminate/Notifications/Console/NotificationTableCommand.php b/src/Illuminate/Notifications/Console/NotificationTableCommand.php new file mode 100644 index 000000000000..09b0e3eb5415 --- /dev/null +++ b/src/Illuminate/Notifications/Console/NotificationTableCommand.php @@ -0,0 +1,81 @@ +files = $files; + $this->composer = $composer; + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + $fullPath = $this->createBaseMigration(); + + $this->files->put($fullPath, $this->files->get(__DIR__.'/stubs/notifications.stub')); + + $this->info('Migration created successfully!'); + + $this->composer->dumpAutoloads(); + } + + /** + * Create a base migration file for the notifications. + * + * @return string + */ + protected function createBaseMigration() + { + $name = 'create_notifications_table'; + + $path = $this->laravel->databasePath().'/migrations'; + + return $this->laravel['migration.creator']->create($name, $path); + } +} diff --git a/src/Illuminate/Notifications/Console/stubs/notifications.stub b/src/Illuminate/Notifications/Console/stubs/notifications.stub new file mode 100644 index 000000000000..4c69857eaad4 --- /dev/null +++ b/src/Illuminate/Notifications/Console/stubs/notifications.stub @@ -0,0 +1,37 @@ +string('id')->primary(); + $table->string('type'); + $table->string('notifiable_type'); + $table->integer('notifiable_id'); + $table->text('data'); + $table->boolean('read'); + $table->timestamps(); + + $table->index(['notifiable_type', 'notifiable_id']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('notifications'); + } +} From 4d49a395739b3d706b4fc38677fdd5046a750bc6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Aug 2016 07:09:16 -0500 Subject: [PATCH 176/249] Fix registering Closure commands. --- src/Illuminate/Foundation/Console/Kernel.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/Kernel.php b/src/Illuminate/Foundation/Console/Kernel.php index 0c67528bfd31..ec46c44dbd46 100644 --- a/src/Illuminate/Foundation/Console/Kernel.php +++ b/src/Illuminate/Foundation/Console/Kernel.php @@ -8,6 +8,7 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Console\Application as Artisan; +use Illuminate\Console\Events\ArtisanStarting; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Console\Kernel as KernelContract; use Symfony\Component\Debug\Exception\FatalThrowableError; @@ -167,7 +168,11 @@ protected function commands() */ public function command($signature, Closure $callback) { - $this->registerCommand($command = new ClosureCommand($signature, $callback)); + $command = new ClosureCommand($signature, $callback); + + $this->app['events']->listen(ArtisanStarting::class, function ($event) use ($command) { + $event->artisan->add($command); + }); return $command; } From 28cec4a9dcd4755db6e1c75a5a5611071e71c4ac Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Aug 2016 07:22:59 -0500 Subject: [PATCH 177/249] force integer on inc / dec --- src/Illuminate/Database/Query/Builder.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 6a21fba028e3..48f60780174b 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -2151,6 +2151,10 @@ public function updateOrInsert(array $attributes, array $values = []) */ public function increment($column, $amount = 1, array $extra = []) { + if (! is_numeric($amount)) { + throw new InvalidArgumentException("Non-numeric value passed to increment method."); + } + $wrapped = $this->grammar->wrap($column); $columns = array_merge([$column => $this->raw("$wrapped + $amount")], $extra); @@ -2168,6 +2172,10 @@ public function increment($column, $amount = 1, array $extra = []) */ public function decrement($column, $amount = 1, array $extra = []) { + if (! is_numeric($amount)) { + throw new InvalidArgumentException("Non-numeric value passed to decrement method."); + } + $wrapped = $this->grammar->wrap($column); $columns = array_merge([$column => $this->raw("$wrapped - $amount")], $extra); From 31a1e5dee1adca007e2f0b334f7cf3e23240b7af Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Aug 2016 07:23:17 -0500 Subject: [PATCH 178/249] Applied fixes from StyleCI (#14738) --- src/Illuminate/Database/Query/Builder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 48f60780174b..a05e6207ec92 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -2152,7 +2152,7 @@ public function updateOrInsert(array $attributes, array $values = []) public function increment($column, $amount = 1, array $extra = []) { if (! is_numeric($amount)) { - throw new InvalidArgumentException("Non-numeric value passed to increment method."); + throw new InvalidArgumentException('Non-numeric value passed to increment method.'); } $wrapped = $this->grammar->wrap($column); @@ -2173,7 +2173,7 @@ public function increment($column, $amount = 1, array $extra = []) public function decrement($column, $amount = 1, array $extra = []) { if (! is_numeric($amount)) { - throw new InvalidArgumentException("Non-numeric value passed to decrement method."); + throw new InvalidArgumentException('Non-numeric value passed to decrement method.'); } $wrapped = $this->grammar->wrap($column); From e18a305d6cd176181d8e1a1c2f7a195da0ecdc1b Mon Sep 17 00:00:00 2001 From: Oskar Danielsson Date: Wed, 10 Aug 2016 14:54:21 +0200 Subject: [PATCH 179/249] Improved method description (#14736) --- src/Illuminate/Http/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index d7d08f6d1cf0..bf5b51757abe 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -340,7 +340,7 @@ public function input($key = null, $default = null) } /** - * Get a subset of the items from the input data. + * Get a subset containing the provided keys with values from the input data. * * @param array|mixed $keys * @return array From dd3ce6abca257047a25d239000c44b2480ba110b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Guimar=C3=A3es?= Date: Fri, 22 Jul 2016 16:49:12 -0300 Subject: [PATCH 180/249] Collection mapToAssoc implementation. --- src/Illuminate/Support/Collection.php | 29 +++++++++++++++++++++++++ tests/Support/SupportCollectionTest.php | 29 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index ea34c1746964..4aff05eaf89e 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -599,6 +599,19 @@ public function map(callable $callback) return new static(array_combine($keys, $items)); } + /** + * Run map over each items and + * returns associative array + * + * @param callable $callback + * + * @return array + */ + public function mapToAssoc(callable $callback) + { + return $this->map($callback)->toAssoc(); + } + /** * Map a collection and flatten the result by a single level. * @@ -1166,6 +1179,22 @@ public function toArray() }, $this->items); } + /** + * Return an associative array + * + * @return array + */ + public function toAssoc() + { + return $this->reduce(function ($assoc, $pair) { + list($key, $value) = $pair; + + $assoc[$key] = $value; + + return $assoc; + }); + } + /** * Convert the object into something JSON serializable. * diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 60acb3a90832..66bbb34a29d7 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -895,6 +895,35 @@ public function testFlatMap() $this->assertEquals(['programming', 'basketball', 'music', 'powerlifting'], $data->all()); } + public function testMapToAssoc() + { + $data = new Collection([ + ['name' => 'Blastoise', 'type' => 'Water', 'idx' => 9], + ['name' => 'Charmander', 'type' => 'Fire', 'idx' => 4], + ['name' => 'Dragonair', 'type' => 'Dragon', 'idx' => 148], + ]); + $data = $data->mapToAssoc(function ($pokemon) { + return [$pokemon['name'], $pokemon['type']]; + }); + $this->assertEquals( + ['Blastoise' => 'Water', 'Charmander' => 'Fire', 'Dragonair' => 'Dragon'], + $data + ); + } + + public function testToAssoc() + { + $collection = new Collection([ + ['Blastoise', 'Water'], + ['Charmander', 'Fire'], + ['Dragonair', 'Dragon'] + ]); + $this->assertEquals( + ['Blastoise' => 'Water', 'Charmander' => 'Fire', 'Dragonair' => 'Dragon'], + $collection->toAssoc() + ); + } + public function testTransform() { $data = new Collection(['first' => 'taylor', 'last' => 'otwell']); From ff9b9eb778c54afd134a8a1eab8b90e3cc2431d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Guimar=C3=A3es?= Date: Fri, 22 Jul 2016 17:01:23 -0300 Subject: [PATCH 181/249] Style requirements. --- src/Illuminate/Support/Collection.php | 4 ++-- tests/Support/SupportCollectionTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 4aff05eaf89e..64c38defc35e 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -601,7 +601,7 @@ public function map(callable $callback) /** * Run map over each items and - * returns associative array + * returns associative array. * * @param callable $callback * @@ -1180,7 +1180,7 @@ public function toArray() } /** - * Return an associative array + * Returns an associative array. * * @return array */ diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 66bbb34a29d7..98fd7812626a 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -916,7 +916,7 @@ public function testToAssoc() $collection = new Collection([ ['Blastoise', 'Water'], ['Charmander', 'Fire'], - ['Dragonair', 'Dragon'] + ['Dragonair', 'Dragon'], ]); $this->assertEquals( ['Blastoise' => 'Water', 'Charmander' => 'Fire', 'Dragonair' => 'Dragon'], From 5872de755f98d263cae3b6d68edef362b9f8579a Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Wed, 10 Aug 2016 14:06:20 +0100 Subject: [PATCH 182/249] Allow usage of the worker without pcntl --- src/Illuminate/Queue/Console/WorkCommand.php | 9 ++++++++- src/Illuminate/Queue/Worker.php | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Queue/Console/WorkCommand.php b/src/Illuminate/Queue/Console/WorkCommand.php index 6dd15ea8aa04..baa83c8fc609 100755 --- a/src/Illuminate/Queue/Console/WorkCommand.php +++ b/src/Illuminate/Queue/Console/WorkCommand.php @@ -3,6 +3,7 @@ namespace Illuminate\Queue\Console; use Carbon\Carbon; +use RuntimeException; use Illuminate\Queue\Worker; use Illuminate\Console\Command; use Illuminate\Queue\WorkerOptions; @@ -104,9 +105,15 @@ protected function runWorker($connection, $queue) */ protected function gatherWorkerOptions() { + $timeout = $this->option('timeout', 60); + + if ($timeout && ! function_exist('pcntl_fork')) { + throw new RuntimeException('Timeouts not supported without the pcntl_fork extension.'); + } + return new WorkerOptions( $this->option('delay'), $this->option('memory'), - $this->option('timeout', 60), $this->option('sleep'), + $timeout, $this->option('sleep'), $this->option('tries') ); } diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index af6b42ae0f11..68ba9bd29ef8 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -103,7 +103,9 @@ protected function daemonShouldRun() */ protected function runNextJobForDaemon($connectionName, $queue, WorkerOptions $options) { - if ($processId = pcntl_fork()) { + if (! $options->timeout) { + $this->runNextJob($connectionName, $queue, $options); + } elseif ($processId = pcntl_fork()) { $this->waitForChildProcess($processId, $options->timeout); } else { $this->runNextJob($connectionName, $queue, $options); From 5b134a798b68b038eb1a3c7d3546c011ed9ddb13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Guimar=C3=A3es?= Date: Wed, 10 Aug 2016 10:15:00 -0300 Subject: [PATCH 183/249] toAssoc should receive an associative array, not a pair. --- src/Illuminate/Support/Collection.php | 6 +++--- tests/Support/SupportCollectionTest.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index 64c38defc35e..d6d9a554dd94 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -1186,10 +1186,10 @@ public function toArray() */ public function toAssoc() { - return $this->reduce(function ($assoc, $pair) { - list($key, $value) = $pair; + return $this->reduce(function ($assoc, $item) { + $key = key($item); - $assoc[$key] = $value; + $assoc[$key] = $item[$key]; return $assoc; }); diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 98fd7812626a..cf4e1e787585 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -903,7 +903,7 @@ public function testMapToAssoc() ['name' => 'Dragonair', 'type' => 'Dragon', 'idx' => 148], ]); $data = $data->mapToAssoc(function ($pokemon) { - return [$pokemon['name'], $pokemon['type']]; + return [$pokemon['name'] => $pokemon['type']]; }); $this->assertEquals( ['Blastoise' => 'Water', 'Charmander' => 'Fire', 'Dragonair' => 'Dragon'], @@ -914,9 +914,9 @@ public function testMapToAssoc() public function testToAssoc() { $collection = new Collection([ - ['Blastoise', 'Water'], - ['Charmander', 'Fire'], - ['Dragonair', 'Dragon'], + ['Blastoise' => 'Water'], + ['Charmander' => 'Fire'], + ['Dragonair' => 'Dragon'], ]); $this->assertEquals( ['Blastoise' => 'Water', 'Charmander' => 'Fire', 'Dragonair' => 'Dragon'], From 2011064fedff635f3a39a5c15a8db209504a5f49 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 10 Aug 2016 09:14:43 -0500 Subject: [PATCH 184/249] add csrfToken to layout as JS variable --- .../Auth/Console/stubs/make/views/layouts/app.stub | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub b/src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub index 7c89ec3759f2..3222a70f9cd8 100644 --- a/src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub +++ b/src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub @@ -12,6 +12,13 @@ + + +