language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | laravel | framework | 53ca0c09ddfbc605ec7552e5080b8db067765f84.json | Add join support | src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php | @@ -270,6 +270,27 @@ public function getDateFormat()
return 'Y-m-d H:i:s.000';
}
+ /**
+ * Compile a delete statement into SQL.
+ *
+ * @param \Illuminate\Database\Query\Builder $query
+ * @return string
+ */
+ public function compileDelete(Builder $query)
+ {
+ $table = $this->wrapTable($query->from);
+
+ $where = is_array($query->wheres) ? $this->compileWheres($query) : '';
+
+ if (isset($query->joins)) {
+ $joins = ' '.$this->compileJoins($query, $query->joins);
+
+ return trim("delete $table from {$table}{$joins} $where");
+ }
+
+ return trim("delete from $table $where");
+ }
+
/**
* Wrap a single string in keyword identifiers.
* | true |
Other | laravel | framework | 53ca0c09ddfbc605ec7552e5080b8db067765f84.json | Add join support | tests/Database/DatabaseQueryBuilderTest.php | @@ -1395,6 +1395,11 @@ public function testDeleteMethod()
$builder->getConnection()->shouldReceive('delete')->once()->with('delete from `users` where `email` = ? order by `id` asc limit 1', ['foo'])->andReturn(1);
$result = $builder->from('users')->where('email', '=', 'foo')->orderBy('id')->take(1)->delete();
$this->assertEquals(1, $result);
+
+ $builder = $this->getSqlServerBuilder();
+ $builder->getConnection()->shouldReceive('delete')->once()->with('delete from [users] where [email] = ?', ['foo'])->andReturn(1);
+ $result = $builder->from('users')->where('email', '=', 'foo')->delete();
+ $this->assertEquals(1, $result);
}
public function testDeleteWithJoinMethod()
@@ -1408,6 +1413,16 @@ public function testDeleteWithJoinMethod()
$builder->getConnection()->shouldReceive('delete')->once()->with('delete `users` from `users` inner join `contacts` on `users`.`id` = `contacts`.`id` where `id` = ?', [1])->andReturn(1);
$result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->orderBy('id')->take(1)->delete(1);
$this->assertEquals(1, $result);
+
+ $builder = $this->getSqlServerBuilder();
+ $builder->getConnection()->shouldReceive('delete')->once()->with('delete [users] from [users] inner join [contacts] on [users].[id] = [contacts].[id] where [email] = ?', ['foo'])->andReturn(1);
+ $result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->where('email', '=', 'foo')->delete();
+ $this->assertEquals(1, $result);
+
+ $builder = $this->getSqlServerBuilder();
+ $builder->getConnection()->shouldReceive('delete')->once()->with('delete [users] from [users] inner join [contacts] on [users].[id] = [contacts].[id] where [id] = ?', [1])->andReturn(1);
+ $result = $builder->from('users')->join('contacts', 'users.id', '=', 'contacts.id')->delete(1);
+ $this->assertEquals(1, $result);
}
public function testTruncateMethod() | true |
Other | laravel | framework | 9b5cd619a441dbd436a0353d0f4ddb97288369b5.json | match coding conventions regarding whitespace | src/Illuminate/Foundation/Console/AppNameCommand.php | @@ -224,6 +224,7 @@ protected function setServicesConfigNamespace()
protected function setDatabaseFactoryNamespaces()
{
$modelFactoryFile = $this->laravel->databasePath().'/factories/ModelFactory.php';
+
if ($this->files->exists($modelFactoryFile)) {
$this->replaceIn($modelFactoryFile, $this->currentRoot, $this->argument('name'));
} | false |
Other | laravel | framework | 481f76000c861e3e2540dcdda986fb44622ccbbe.json | allow array of options on filesystem operations | src/Illuminate/Filesystem/FilesystemAdapter.php | @@ -70,25 +70,23 @@ public function get($path)
*
* @param string $path
* @param string|resource $contents
- * @param string $visibility
+ * @param array $options
* @return bool
*/
- public function put($path, $contents, $visibility = null)
+ public function put($path, $contents, $options = [])
{
- if ($contents instanceof File || $contents instanceof UploadedFile) {
- return $this->putFile($path, $contents, $visibility);
+ if (is_string($options)) {
+ $options = ['visibility' => $options];
}
- if ($visibility = $this->parseVisibility($visibility)) {
- $config = ['visibility' => $visibility];
- } else {
- $config = [];
+ if ($contents instanceof File || $contents instanceof UploadedFile) {
+ return $this->putFile($path, $contents, $options);
}
if (is_resource($contents)) {
- return $this->driver->putStream($path, $contents, $config);
+ return $this->driver->putStream($path, $contents, $options);
} else {
- return $this->driver->put($path, $contents, $config);
+ return $this->driver->put($path, $contents, $options);
}
}
@@ -97,12 +95,12 @@ public function put($path, $contents, $visibility = null)
*
* @param string $path
* @param \Illuminate\Http\UploadedFile $file
- * @param string $visibility
+ * @param array $options
* @return string|false
*/
- public function putFile($path, $file, $visibility = null)
+ public function putFile($path, $file, $options = [])
{
- return $this->putFileAs($path, $file, $file->hashName(), $visibility);
+ return $this->putFileAs($path, $file, $file->hashName(), $options);
}
/**
@@ -111,14 +109,14 @@ public function putFile($path, $file, $visibility = null)
* @param string $path
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile $file
* @param string $name
- * @param string $visibility
+ * @param array $options
* @return string|false
*/
- public function putFileAs($path, $file, $name, $visibility = null)
+ public function putFileAs($path, $file, $name, $options = [])
{
$stream = fopen($file->getRealPath(), 'r+');
- $result = $this->put($path = trim($path.'/'.$name, '/'), $stream, $visibility);
+ $result = $this->put($path = trim($path.'/'.$name, '/'), $stream, $options);
if (is_resource($stream)) {
fclose($stream); | true |
Other | laravel | framework | 481f76000c861e3e2540dcdda986fb44622ccbbe.json | allow array of options on filesystem operations | src/Illuminate/Http/UploadedFile.php | @@ -2,6 +2,7 @@
namespace Illuminate\Http;
+use Illuminate\Support\Arr;
use Illuminate\Container\Container;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
@@ -15,53 +16,70 @@ class UploadedFile extends SymfonyUploadedFile
* Store the uploaded file on a filesystem disk.
*
* @param string $path
- * @param string|null $disk
+ * @param array $options
* @return string|false
*/
- public function store($path, $disk = null)
+ public function store($path, $options = [])
{
- return $this->storeAs($path, $this->hashName(), $disk);
+ if (is_string($options)) {
+ $options = ['disk' => $options];
+ }
+
+ return $this->storeAs($path, $this->hashName(), $options);
}
/**
* Store the uploaded file on a filesystem disk with public visibility.
*
* @param string $path
- * @param string|null $disk
+ * @param array $options
* @return string|false
*/
- public function storePublicly($path, $disk = null)
+ public function storePublicly($path, $options = [])
{
- return $this->storeAs($path, $this->hashName(), $disk, 'public');
+ if (is_string($options)) {
+ $options = ['disk' => $options];
+ }
+
+ $options['visibility'] = 'public';
+
+ return $this->storeAs($path, $this->hashName(), $options);
}
/**
* Store the uploaded file on a filesystem disk with public visibility.
*
* @param string $path
* @param string $name
- * @param string|null $disk
+ * @param array $options
* @return string|false
*/
- public function storePubliclyAs($path, $name, $disk = null)
+ public function storePubliclyAs($path, $name, $options = [])
{
- return $this->storeAs($path, $name, $disk, 'public');
+ if (is_string($options)) {
+ $options = ['disk' => $options];
+ }
+
+ $options['visibility'] = 'public';
+
+ return $this->storeAs($path, $name, $options);
}
/**
* Store the uploaded file on a filesystem disk.
*
* @param string $path
* @param string $name
- * @param string|null $disk
- * @param string|null $visibility
+ * @param array $options
* @return string|false
*/
- public function storeAs($path, $name, $disk = null, $visibility = null)
+ public function storeAs($path, $name, $options = [])
{
$factory = Container::getInstance()->make(FilesystemFactory::class);
- return $factory->disk($disk)->putFileAs($path, $this, $name, $visibility);
+ $disk = Arr::pull($options, 'disk');
+
+ return $factory->disk($disk)->putFileAs($path, $this, $name, $options);
}
/** | true |
Other | laravel | framework | 30016408a6911afba4aa7739d69948d13612ea06.json | add unicode to message | src/Illuminate/Notifications/Channels/NexmoSmsChannel.php | @@ -55,7 +55,7 @@ public function send($notifiable, Notification $notification)
}
return $this->nexmo->message()->send([
- 'type' => 'unicode',
+ 'type' => $message->type,
'from' => $message->from ?: $this->from,
'to' => $to,
'text' => trim($message->content), | true |
Other | laravel | framework | 30016408a6911afba4aa7739d69948d13612ea06.json | add unicode to message | src/Illuminate/Notifications/Messages/NexmoMessage.php | @@ -18,6 +18,13 @@ class NexmoMessage
*/
public $from;
+ /**
+ * The message type.
+ *
+ * @var string
+ */
+ public $type = 'text';
+
/**
* Create a new message instance.
*
@@ -54,4 +61,16 @@ public function from($from)
return $this;
}
+
+ /**
+ * Set the message type.
+ *
+ * @return $this
+ */
+ public function unicode()
+ {
+ $this->type = 'unicode';
+
+ return $this;
+ }
} | true |
Other | laravel | framework | 30016408a6911afba4aa7739d69948d13612ea06.json | add unicode to message | tests/Notifications/NotificationNexmoChannelTest.php | @@ -20,6 +20,7 @@ public function testSmsIsSentViaNexmo()
);
$nexmo->shouldReceive('message->send')->with([
+ 'type' => 'text',
'from' => '4444444444',
'to' => '5555555555',
'text' => 'this is my message',
@@ -38,6 +39,7 @@ public function testSmsIsSentViaNexmoWithCustomFrom()
);
$nexmo->shouldReceive('message->send')->with([
+ 'type' => 'unicode',
'from' => '5554443333',
'to' => '5555555555',
'text' => 'this is my message',
@@ -65,6 +67,6 @@ class NotificationNexmoChannelTestCustomFromNotification extends Notification
{
public function toNexmo($notifiable)
{
- return (new NexmoMessage('this is my message'))->from('5554443333');
+ return (new NexmoMessage('this is my message'))->from('5554443333')->unicode();
}
} | true |
Other | laravel | framework | db4879ae84a3a1959729ac2732ae42cfe377314c.json | fix formatting and tests | src/Illuminate/Notifications/Channels/SlackWebhookChannel.php | @@ -3,10 +3,10 @@
namespace Illuminate\Notifications\Channels;
use GuzzleHttp\Client as HttpClient;
-use Illuminate\Notifications\Messages\SlackAttachmentField;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Messages\SlackAttachment;
+use Illuminate\Notifications\Messages\SlackAttachmentField;
class SlackWebhookChannel
{ | true |
Other | laravel | framework | db4879ae84a3a1959729ac2732ae42cfe377314c.json | fix formatting and tests | src/Illuminate/Notifications/Messages/SlackAttachment.php | @@ -122,9 +122,8 @@ public function field($title, $content = '')
if (is_callable($title)) {
$callback = $title;
- $attachmentField = new SlackAttachmentField();
+ $callback($attachmentField = new SlackAttachmentField);
- $callback($attachmentField);
$this->fields[] = $attachmentField;
return $this; | true |
Other | laravel | framework | db4879ae84a3a1959729ac2732ae42cfe377314c.json | fix formatting and tests | src/Illuminate/Notifications/Messages/SlackAttachmentField.php | @@ -19,8 +19,7 @@ class SlackAttachmentField
protected $content;
/**
- * Whether the content is short enough to fit side by side with
- * other contents.
+ * Whether the content is short.
*
* @var bool
*/
@@ -29,7 +28,7 @@ class SlackAttachmentField
/**
* Set the title of the field.
*
- * @param string $title
+ * @param string $title
* @return $this
*/
public function title($title)
@@ -42,7 +41,7 @@ public function title($title)
/**
* Set the content of the field.
*
- * @param string $content
+ * @param string $content
* @return $this
*/
public function content($content)
@@ -53,19 +52,11 @@ public function content($content)
}
/**
+ * Indicates that the content should not be displayed side-by-side with other fields.
+ *
* @return $this
*/
- public function displaySideBySide()
- {
- $this->short = true;
-
- return $this;
- }
-
- /**
- * @return $this
- */
- public function dontDisplaySideBySide()
+ public function long()
{
$this->short = false;
| true |
Other | laravel | framework | db4879ae84a3a1959729ac2732ae42cfe377314c.json | fix formatting and tests | tests/Notifications/NotificationSlackChannelTest.php | @@ -182,7 +182,7 @@ public function toSlack($notifiable)
$attachmentField
->title('Special powers')
->content('Zonda')
- ->dontDisplaySideBySide();
+ ->long();
});
});
} | true |
Other | laravel | framework | 5526aece584c1d21bc6d1a3d9f294aaaa36b3c50.json | Add whereKey method | src/Illuminate/Database/Eloquent/Builder.php | @@ -166,9 +166,7 @@ public function find($id, $columns = ['*'])
return $this->findMany($id, $columns);
}
- $this->query->where($this->model->getQualifiedKeyName(), '=', $id);
-
- return $this->first($columns);
+ return $this->whereKey($id)->first($columns);
}
/**
@@ -184,9 +182,22 @@ public function findMany($ids, $columns = ['*'])
return $this->model->newCollection();
}
- $this->query->whereIn($this->model->getQualifiedKeyName(), $ids);
+ return $this->whereKey($ids)->get($columns);
+ }
- return $this->get($columns);
+ /**
+ * Add where clause with primary key to the query.
+ *
+ * @param mixed $id
+ * @return $this
+ */
+ public function whereKey($id)
+ {
+ if (is_array($id)) {
+ $this->query->whereIn($this->model->getQualifiedKeyName(), $id);
+ return $this;
+ }
+ return $this->where($this->model->getQualifiedKeyName(), '=', $id);
}
/** | false |
Other | laravel | framework | 7aa30020c09373281292872e7e12518934cc76dd.json | Create custom Collection also on empty page | src/Illuminate/Database/Eloquent/Builder.php | @@ -497,7 +497,9 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
$total = $query->getCountForPagination();
- $results = $total ? $this->forPage($page, $perPage)->get($columns) : new Collection;
+ $results = $total
+ ? $this->forPage($page, $perPage)->get($columns)
+ : $this->model->newCollection();
return new LengthAwarePaginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(), | true |
Other | laravel | framework | 7aa30020c09373281292872e7e12518934cc76dd.json | Create custom Collection also on empty page | src/Illuminate/Database/Query/Builder.php | @@ -1663,7 +1663,7 @@ public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $p
$total = $this->getCountForPagination($columns);
- $results = $total ? $this->forPage($page, $perPage)->get($columns) : [];
+ $results = $total ? $this->forPage($page, $perPage)->get($columns) : collect();
return new LengthAwarePaginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(), | true |
Other | laravel | framework | b81cfae9a7090bc02271fa629aa3d2f17715c899.json | add ipv4 and ipv6 validations | src/Illuminate/Validation/Validator.php | @@ -1551,6 +1551,30 @@ protected function validateIp($attribute, $value)
return filter_var($value, FILTER_VALIDATE_IP) !== false;
}
+ /**
+ * Validate that an attribute is a valid IPv4.
+ *
+ * @param string $attribute
+ * @param mixed $value
+ * @return bool
+ */
+ protected function validateIpv4($attribute, $value)
+ {
+ return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false;
+ }
+
+ /**
+ * Validate that an attribute is a valid IPv6.
+ *
+ * @param string $attribute
+ * @param mixed $value
+ * @return bool
+ */
+ protected function validateIpv6($attribute, $value)
+ {
+ return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false;
+ }
+
/**
* Validate that an attribute is a valid e-mail address.
* | true |
Other | laravel | framework | b81cfae9a7090bc02271fa629aa3d2f17715c899.json | add ipv4 and ipv6 validations | tests/Validation/ValidationValidatorTest.php | @@ -1505,6 +1505,18 @@ public function testValidateIp()
$v = new Validator($trans, ['ip' => '127.0.0.1'], ['ip' => 'Ip']);
$this->assertTrue($v->passes());
+
+ $v = new Validator($trans, ['ip' => '127.0.0.1'], ['ip' => 'Ipv4']);
+ $this->assertTrue($v->passes());
+
+ $v = new Validator($trans, ['ip' => '::1'], ['ip' => 'Ipv6']);
+ $this->assertTrue($v->passes());
+
+ $v = new Validator($trans, ['ip' => '127.0.0.1'], ['ip' => 'Ipv6']);
+ $this->assertTrue($v->fails());
+
+ $v = new Validator($trans, ['ip' => '::1'], ['ip' => 'Ipv4']);
+ $this->assertTrue($v->fails());
}
public function testValidateEmail() | true |
Other | laravel | framework | b1169e82995a6ea628fd77f44e48c833971a104e.json | fix CS issues | tests/Notifications/NotificationSlackChannelTest.php | @@ -108,7 +108,7 @@ public function testCorrectPayloadWithAttachmentFieldBuilderIsSentToSlack()
'title' => 'Special powers',
'value' => 'Zonda',
'short' => false,
- ]
+ ],
],
],
], | false |
Other | laravel | framework | 8351c8f912ace3523f98d97c83a7695ef0c73d1a.json | fix CS issues | tests/Notifications/NotificationSlackChannelTest.php | @@ -107,7 +107,7 @@ public function testCorrectPayloadWithAttachmentFieldBuilderIsSentToSlack()
[
'title' => 'Special powers',
'value' => 'Zonda',
- 'short' => false
+ 'short' => false,
]
],
],
@@ -178,7 +178,7 @@ public function toSlack($notifiable)
$attachment->title('Laravel', 'https://laravel.com')
->content('Attachment Content')
->field('Project', 'Laravel')
- ->field(function($attachmentField) {
+ ->field(function ($attachmentField) {
$attachmentField
->title('Special powers')
->content('Zonda') | false |
Other | laravel | framework | d11cf5f86d90f40c5cb1837cb3820148005517a0.json | Clarify description of method | src/Illuminate/Database/Query/Builder.php | @@ -1730,7 +1730,7 @@ public function getCountForPagination($columns = ['*'])
}
/**
- * Backup some fields for the pagination count.
+ * Backup then remove some fields for the pagination count.
*
* @return void
*/ | false |
Other | laravel | framework | 4f96f429b22b1b09de6a263bd7d50eda18075b52.json | Get the current path formatter. | src/Illuminate/Routing/UrlGenerator.php | @@ -719,6 +719,16 @@ public function formatPathUsing(Closure $callback)
return $this;
}
+ /**
+ * Get the path formatter being used by the URL generator.
+ *
+ * @return \Closure
+ */
+ public function pathFormatter()
+ {
+ return $this->formatPathUsing ?: function ($path) { return $path; };
+ }
+
/**
* Get the request instance.
* | false |
Other | laravel | framework | 41c99e8e47006b5d2dee6e1d728f824b2b23a392.json | Fix doc block | src/Illuminate/View/FileViewFinder.php | @@ -224,7 +224,7 @@ public function addExtension($extension)
}
/**
- * Returns whether or not the view specify a hint information.
+ * Returns whether or not the view name has any hint information.
*
* @param string $name
* @return bool | false |
Other | laravel | framework | 269521ec9702c320e1f9928e19bfe694759589a3.json | add register name | src/Illuminate/Routing/Router.php | @@ -292,7 +292,7 @@ public function auth()
$this->post('logout', 'Auth\LoginController@logout')->name('logout');
// Registration Routes...
- $this->get('register', 'Auth\RegisterController@showRegistrationForm');
+ $this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');
// Password Reset Routes... | false |
Other | laravel | framework | 11d9c71ee1323d69d8768dd2dea2e045c030729b.json | move deprecated exceptions method to DOCBLOCK | tests/Auth/AuthenticateMiddlewareTest.php | @@ -29,10 +29,11 @@ public function setUp()
});
}
+ /**
+ * @expectedException Illuminate\Auth\AuthenticationException
+ */
public function testDefaultUnauthenticatedThrows()
{
- $this->setExpectedException(AuthenticationException::class);
-
$this->registerAuthDriver('default', false);
$this->authenticate();
@@ -73,10 +74,11 @@ public function testSecondaryAuthenticatedUpdatesDefaultDriver()
$this->assertSame($secondary, $this->auth->guard());
}
+ /**
+ * @expectedException Illuminate\Auth\AuthenticationException
+ */
public function testMultipleDriversUnauthenticatedThrows()
{
- $this->setExpectedException(AuthenticationException::class);
-
$this->registerAuthDriver('default', false);
$this->registerAuthDriver('secondary', false); | true |
Other | laravel | framework | 11d9c71ee1323d69d8768dd2dea2e045c030729b.json | move deprecated exceptions method to DOCBLOCK | tests/Auth/AuthorizeMiddlewareTest.php | @@ -9,7 +9,6 @@
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Contracts\Routing\Registrar;
use Illuminate\Contracts\Auth\Factory as Auth;
-use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
@@ -51,10 +50,11 @@ public function setUp()
});
}
+ /**
+ * @expectedException Illuminate\Auth\Access\AuthorizationException
+ */
public function testSimpleAbilityUnauthorized()
{
- $this->setExpectedException(AuthorizationException::class);
-
$this->gate()->define('view-dashboard', function ($user, $additional = null) {
$this->assertNull($additional);
@@ -89,10 +89,11 @@ public function testSimpleAbilityAuthorized()
$this->assertEquals($response->content(), 'success');
}
+ /**
+ * @expectedException Illuminate\Auth\Access\AuthorizationException
+ */
public function testModelTypeUnauthorized()
{
- $this->setExpectedException(AuthorizationException::class);
-
$this->gate()->define('create', function ($user, $model) {
$this->assertEquals($model, 'App\User');
@@ -129,10 +130,11 @@ public function testModelTypeAuthorized()
$this->assertEquals($response->content(), 'success');
}
+ /**
+ * @expectedException Illuminate\Auth\Access\AuthorizationException
+ */
public function testModelUnauthorized()
{
- $this->setExpectedException(AuthorizationException::class);
-
$post = new stdClass;
$this->router->bind('post', function () use ($post) { | true |
Other | laravel | framework | 11d9c71ee1323d69d8768dd2dea2e045c030729b.json | move deprecated exceptions method to DOCBLOCK | tests/Database/DatabaseEloquentBelongsToManyTest.php | @@ -365,13 +365,14 @@ public function testCreateMethodCreatesNewModelAndInsertsAttachmentRecord()
$this->assertEquals($model, $relation->create(['attributes'], ['joining']));
}
+ /**
+ * @expectedException Illuminate\Database\Eloquent\ModelNotFoundException
+ */
public function testFindOrFailThrowsException()
{
$relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['find'])->setConstructorArgs($this->getRelationArguments())->getMock();
$relation->expects($this->once())->method('find')->with('foo')->will($this->returnValue(null));
- $this->setExpectedException(Illuminate\Database\Eloquent\ModelNotFoundException::class);
-
try {
$relation->findOrFail('foo');
} catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
@@ -381,13 +382,14 @@ public function testFindOrFailThrowsException()
}
}
+ /**
+ * @expectedException Illuminate\Database\Eloquent\ModelNotFoundException
+ */
public function testFirstOrFailThrowsException()
{
$relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['first'])->setConstructorArgs($this->getRelationArguments())->getMock();
$relation->expects($this->once())->method('first')->with(['id' => 'foo'])->will($this->returnValue(null));
- $this->setExpectedException(Illuminate\Database\Eloquent\ModelNotFoundException::class);
-
try {
$relation->firstOrFail(['id' => 'foo']);
} catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) { | true |
Other | laravel | framework | 11d9c71ee1323d69d8768dd2dea2e045c030729b.json | move deprecated exceptions method to DOCBLOCK | tests/Database/DatabaseEloquentHasManyThroughTest.php | @@ -174,13 +174,14 @@ public function testFirstMethod()
$this->assertEquals('first', $relation->first());
}
+ /**
+ * @expectedException Illuminate\Database\Eloquent\ModelNotFoundException
+ */
public function testFindOrFailThrowsException()
{
$relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\HasManyThrough')->setMethods(['find'])->setConstructorArgs($this->getRelationArguments())->getMock();
$relation->expects($this->once())->method('find')->with('foo')->will($this->returnValue(null));
- $this->setExpectedException(\Illuminate\Database\Eloquent\ModelNotFoundException::class);
-
try {
$relation->findOrFail('foo');
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
@@ -190,13 +191,14 @@ public function testFindOrFailThrowsException()
}
}
+ /**
+ * @expectedException Illuminate\Database\Eloquent\ModelNotFoundException
+ */
public function testFirstOrFailThrowsException()
{
$relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\HasManyThrough')->setMethods(['first'])->setConstructorArgs($this->getRelationArguments())->getMock();
$relation->expects($this->once())->method('first')->with(['id' => 'foo'])->will($this->returnValue(null));
- $this->setExpectedException(\Illuminate\Database\Eloquent\ModelNotFoundException::class);
-
try {
$relation->firstOrFail(['id' => 'foo']);
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { | true |
Other | laravel | framework | 11d9c71ee1323d69d8768dd2dea2e045c030729b.json | move deprecated exceptions method to DOCBLOCK | tests/Foundation/FoundationHelpersTest.php | @@ -31,10 +31,11 @@ public function testCache()
$this->assertEquals('default', cache('baz', 'default'));
}
+ /**
+ * @expectedException Exception
+ */
public function testCacheThrowsAnExceptionIfAnExpirationIsNotProvided()
{
- $this->setExpectedException('Exception');
-
cache(['foo' => 'bar']);
}
@@ -52,4 +53,5 @@ public function testUnversionedElixir()
unlink(public_path($file));
}
+
} | true |
Other | laravel | framework | 0749932b7914edd551ffa8a8ec420a09b71b325f.json | Fix code style | src/Illuminate/Notifications/Messages/SlackAttachment.php | @@ -158,7 +158,7 @@ public function footer($footer)
public function footerIcon($icon)
{
$this->footerIcon = $icon;
-
+
return $this;
}
| false |
Other | laravel | framework | 81e3c2378fecf7a7861d31f41ec665fecc65ebf7.json | Fix code style | src/Illuminate/Notifications/Messages/SlackAttachment.php | @@ -158,6 +158,7 @@ public function footer($footer)
public function footerIcon($icon)
{
$this->footerIcon = $icon;
+
return $this;
}
| false |
Other | laravel | framework | ab204ff619444ee16882e15d0f70443ebfd299e3.json | Fix code style | src/Illuminate/Notifications/Channels/SlackWebhookChannel.php | @@ -85,7 +85,7 @@ protected function attachments(SlackMessage $message)
'mrkdwn_in' => $attachment->markdown,
'footer' => $attachment->footer,
'footer_icon' => $attachment->footerIcon,
- 'ts' => $attachment->timestamp
+ 'ts' => $attachment->timestamp,
]);
})->all();
} | false |
Other | laravel | framework | 2f7cec4653ba2345561916e3d289543630e551bc.json | Add support for setting attachment’s footer icon | src/Illuminate/Notifications/Channels/SlackWebhookChannel.php | @@ -84,6 +84,7 @@ protected function attachments(SlackMessage $message)
'fields' => $this->fields($attachment),
'mrkdwn_in' => $attachment->markdown,
'footer' => $attachment->footer,
+ 'footer_icon' => $attachment->footerIcon,
'ts' => $attachment->timestamp
]);
})->all(); | true |
Other | laravel | framework | 2f7cec4653ba2345561916e3d289543630e551bc.json | Add support for setting attachment’s footer icon | src/Illuminate/Notifications/Messages/SlackAttachment.php | @@ -55,6 +55,13 @@ class SlackAttachment
*/
public $footer;
+ /**
+ * The attachment's footer icon.
+ *
+ * @var string
+ */
+ public $footerIcon;
+
/**
* The attachment's timestamp.
*
@@ -142,6 +149,18 @@ public function footer($footer)
return $this;
}
+ /**
+ * Set the footer icon.
+ *
+ * @param string $icon
+ * @return $this
+ */
+ public function footerIcon($icon)
+ {
+ $this->footerIcon = $icon;
+ return $this;
+ }
+
/**
* Set the timestamp.
* | true |
Other | laravel | framework | f996b9e9627c776b1f385a8f4441f411be7a167b.json | Add support for setting footer of Slack attachment | src/Illuminate/Notifications/Channels/SlackWebhookChannel.php | @@ -83,6 +83,8 @@ protected function attachments(SlackMessage $message)
'title_link' => $attachment->url,
'fields' => $this->fields($attachment),
'mrkdwn_in' => $attachment->markdown,
+ 'footer' => $attachment->footer,
+ 'ts' => $attachment->timestamp
]);
})->all();
} | true |
Other | laravel | framework | f996b9e9627c776b1f385a8f4441f411be7a167b.json | Add support for setting footer of Slack attachment | src/Illuminate/Notifications/Messages/SlackAttachment.php | @@ -2,6 +2,8 @@
namespace Illuminate\Notifications\Messages;
+use Carbon\Carbon;
+
class SlackAttachment
{
/**
@@ -46,6 +48,20 @@ class SlackAttachment
*/
public $markdown;
+ /**
+ * The attachment's footer.
+ *
+ * @var string
+ */
+ public $footer;
+
+ /**
+ * The attachment's timestamp.
+ *
+ * @var int
+ */
+ public $timestamp;
+
/**
* Set the title of the attachment.
*
@@ -112,4 +128,30 @@ public function markdown(array $fields)
return $this;
}
+
+ /**
+ * Set the footer content.
+ *
+ * @param string $footer
+ * @return $this
+ */
+ public function footer($footer)
+ {
+ $this->footer = $footer;
+
+ return $this;
+ }
+
+ /**
+ * Set the timestamp.
+ *
+ * @param Carbon $timestamp
+ * @return $this
+ */
+ public function timestamp(Carbon $timestamp)
+ {
+ $this->timestamp = $timestamp->timestamp;
+
+ return $this;
+ }
} | true |
Other | laravel | framework | dc0b9def6e2e284f09775139b76bdd1577f75ea9.json | Add support for markdown in Slack attachment | src/Illuminate/Notifications/Channels/SlackWebhookChannel.php | @@ -82,6 +82,7 @@ protected function attachments(SlackMessage $message)
'text' => $attachment->content,
'title_link' => $attachment->url,
'fields' => $this->fields($attachment),
+ 'mrkdwn_in' => $attachment->markdown,
]);
})->all();
} | true |
Other | laravel | framework | dc0b9def6e2e284f09775139b76bdd1577f75ea9.json | Add support for markdown in Slack attachment | src/Illuminate/Notifications/Messages/SlackAttachment.php | @@ -39,6 +39,13 @@ class SlackAttachment
*/
public $fields;
+ /**
+ * The fields containing markdown.
+ *
+ * @var array
+ */
+ public $markdown;
+
/**
* Set the title of the attachment.
*
@@ -92,4 +99,17 @@ public function fields(array $fields)
return $this;
}
+
+ /**
+ * Set the fields containing markdown.
+ *
+ * @param array $fields
+ * @return $this
+ */
+ public function markdown(array $fields)
+ {
+ $this->markdown = $fields;
+
+ return $this;
+ }
} | true |
Other | laravel | framework | fcf3b659197413766665be728537cebf0f70af0a.json | Offer an "Attribute Casting" of encrypt
This would allow the user to easily encrypt and decrypt a field by setting it to that `cast`
For example
```
protected $casts = [
'secret' => 'encrypt',
'data' => 'array'
];
``` | src/Illuminate/Database/Eloquent/Model.php | @@ -2793,6 +2793,16 @@ protected function isJsonCastable($key)
return $this->hasCast($key, ['array', 'json', 'object', 'collection']);
}
+ /**
+ * Determine whether a value should be encrypted.
+ *
+ * @param string $key
+ * @return bool
+ */
+ protected function isEncryptCastable($key) {
+ return $this->hasCast($key, ['encrypt']);
+ }
+
/**
* Get the type of cast for a model attribute.
*
@@ -2842,6 +2852,8 @@ protected function castAttribute($key, $value)
return $this->asDateTime($value);
case 'timestamp':
return $this->asTimeStamp($value);
+ case 'encrypt':
+ return decrypt($value);
default:
return $value;
}
@@ -2872,6 +2884,10 @@ public function setAttribute($key, $value)
$value = $this->fromDateTime($value);
}
+ if($this->isEncryptCastable($key) && ! is_null($value)) {
+ $value = $this->asEncrypted($value);
+ }
+
if ($this->isJsonCastable($key) && ! is_null($value)) {
$value = $this->asJson($value);
}
@@ -3045,7 +3061,7 @@ protected function asJson($value)
{
return json_encode($value);
}
-
+
/**
* Decode the given JSON back into an array or object.
*
@@ -3058,6 +3074,17 @@ public function fromJson($value, $asObject = false)
return json_decode($value, ! $asObject);
}
+ /**
+ * Encrypt to given value
+ *
+ * @param mixed $value
+ * @return string
+ */
+ protected function asEncrypted($value)
+ {
+ return encrypt($value);
+ }
+
/**
* Clone the model into a new, non-existing instance.
* | false |
Other | laravel | framework | 52b182cdff0a115ae31b2c1f03007e73e06e12b3.json | fix docblock type | src/Illuminate/Foundation/helpers.php | @@ -155,9 +155,9 @@ function auth($guard = null)
/**
* Create a new redirect response to the previous location.
*
- * @param int $status
- * @param array $headers
- * @param bool $fallback
+ * @param int $status
+ * @param array $headers
+ * @param string $fallback
* @return \Illuminate\Http\RedirectResponse
*/
function back($status = 302, $headers = [], $fallback = false) | false |
Other | laravel | framework | 1ab41fb385441494016aeb518b7b809b311e725c.json | Add new JSON loader for translations | src/Illuminate/Foundation/helpers.php | @@ -796,6 +796,21 @@ function trans_choice($id, $number, array $replace = [], $locale = null)
}
}
+if (! function_exists('__')) {
+ /**
+ * Translate the given message.
+ *
+ * @param string $id
+ * @param array $replace
+ * @param string $locale
+ * @return \Illuminate\Contracts\Translation\Translator|string
+ */
+ function __($id = null, $replace = [], $locale = null)
+ {
+ return app('translator')->getJson($id, $replace, $locale);
+ }
+}
+
if (! function_exists('url')) {
/**
* Generate a url for the application. | true |
Other | laravel | framework | 1ab41fb385441494016aeb518b7b809b311e725c.json | Add new JSON loader for translations | src/Illuminate/Translation/FileLoader.php | @@ -50,6 +50,10 @@ public function __construct(Filesystem $files, $path)
*/
public function load($locale, $group, $namespace = null)
{
+ if ($group == '*' && $namespace == '*') {
+ return $this->loadJson($this->path, $locale);
+ }
+
if (is_null($namespace) || $namespace == '*') {
return $this->loadPath($this->path, $locale, $group);
}
@@ -113,6 +117,22 @@ protected function loadPath($path, $locale, $group)
return [];
}
+ /**
+ * Load a locale from a given JSON file.
+ *
+ * @param string $path
+ * @param string $locale
+ * @return array
+ */
+ protected function loadJson($path, $locale)
+ {
+ if ($this->files->exists($full = "{$path}/{$locale}.json")) {
+ return (array) json_decode($this->files->get($full));
+ }
+
+ return [];
+ }
+
/**
* Add a new namespace to the loader.
* | true |
Other | laravel | framework | 1ab41fb385441494016aeb518b7b809b311e725c.json | Add new JSON loader for translations | src/Illuminate/Translation/Translator.php | @@ -87,6 +87,33 @@ public function has($key, $locale = null, $fallback = true)
return $this->get($key, [], $locale, $fallback) !== $key;
}
+ /**
+ * Get the JSON translation for a given key.
+ *
+ * @param string $key
+ * @param array $replace
+ * @param string $locale
+ * @return string
+ */
+ public function getJson($key, array $replace = [], $locale = null)
+ {
+ $locale = $locale ?: $this->locale;
+
+ $this->load('*', '*', $locale);
+
+ $line = Arr::get($this->loaded['*']['*'][$locale], $key);
+
+ if (! isset($line)) {
+ $alternativeLine = $this->get($key, $replace, $locale);
+
+ if ($alternativeLine != $key) {
+ return $alternativeLine;
+ }
+ }
+
+ return $this->makeJsonReplacements($line ?: $key, $replace);
+ }
+
/**
* Get the translation for the given key.
*
@@ -187,6 +214,28 @@ protected function makeReplacements($line, array $replace)
return $line;
}
+ /**
+ * Make the place-holder replacements on a JSON line.
+ *
+ * @param string $line
+ * @param array $replace
+ * @return string
+ */
+ protected function makeJsonReplacements($line, array $replace)
+ {
+ preg_match_all('#:(?:[a-zA-Z1-9]*)#s', $line, $placeholders);
+
+ $placeholders = $placeholders[0];
+
+ foreach ($placeholders as $i => $key) {
+ $line = str_replace_first(
+ $key, isset($replace[$i]) ? $replace[$i] : $key, $line
+ );
+ }
+
+ return $line;
+ }
+
/**
* Sort the replacements array.
* | true |
Other | laravel | framework | 1ab41fb385441494016aeb518b7b809b311e725c.json | Add new JSON loader for translations | tests/Translation/TranslationFileLoaderTest.php | @@ -58,4 +58,13 @@ public function testEmptyArraysReturnedWhenFilesDontExistForNamespacedItems()
$this->assertEquals([], $loader->load('en', 'foo', 'bar'));
}
+
+ public function testLoadMethodForJSONProperlyCallsLoader()
+ {
+ $loader = new FileLoader($files = m::mock('Illuminate\Filesystem\Filesystem'), __DIR__);
+ $files->shouldReceive('exists')->once()->with(__DIR__.'/en.json')->andReturn(true);
+ $files->shouldReceive('get')->once()->with(__DIR__.'/en.json')->andReturn('{"foo":"bar"}');
+
+ $this->assertEquals(['foo' => 'bar'], $loader->load('en', '*', '*'));
+ }
} | true |
Other | laravel | framework | 1ab41fb385441494016aeb518b7b809b311e725c.json | Add new JSON loader for translations | tests/Translation/TranslationTranslatorTest.php | @@ -94,6 +94,52 @@ public function testChoiceMethodProperlyCountsCollectionsAndLoadsAndRetrievesIte
$t->choice('foo', $values, ['replace']);
}
+ public function testGetJsonMethod()
+ {
+ $t = new Illuminate\Translation\Translator($this->getLoader(), 'en');
+ $t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn(['foo' => 'one']);
+ $this->assertEquals('one', $t->getJson('foo'));
+ }
+
+ public function testGetJsonReplaces()
+ {
+ $t = new Illuminate\Translation\Translator($this->getLoader(), 'en');
+ $t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn(['foo :message' => 'bar :message']);
+ $this->assertEquals('bar baz', $t->getJson('foo :message', ['baz']));
+ }
+
+ public function testGetJsonForNonExistingJsonKeyLooksForRegularKeys()
+ {
+ $t = new Illuminate\Translation\Translator($this->getLoader(), 'en');
+ $t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn([]);
+ $t->getLoader()->shouldReceive('load')->once()->with('en', 'foo', '*')->andReturn(['bar' => 'one']);
+ $this->assertEquals('one', $t->getJson('foo.bar'));
+ }
+
+ public function testGetJsonForNonExistingJsonKeyLooksForRegularKeysAndReplace()
+ {
+ $t = new Illuminate\Translation\Translator($this->getLoader(), 'en');
+ $t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn([]);
+ $t->getLoader()->shouldReceive('load')->once()->with('en', 'foo', '*')->andReturn(['bar' => 'one :message']);
+ $this->assertEquals('one two', $t->getJson('foo.bar', ['message' => 'two']));
+ }
+
+ public function testGetJsonForNonExistingReturnsSameKey()
+ {
+ $t = new Illuminate\Translation\Translator($this->getLoader(), 'en');
+ $t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn([]);
+ $t->getLoader()->shouldReceive('load')->once()->with('en', 'Foo that bar', '*')->andReturn([]);
+ $this->assertEquals('Foo that bar', $t->getJson('Foo that bar'));
+ }
+
+ public function testGetJsonForNonExistingReturnsSameKeyAndReplaces()
+ {
+ $t = new Illuminate\Translation\Translator($this->getLoader(), 'en');
+ $t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn([]);
+ $t->getLoader()->shouldReceive('load')->once()->with('en', 'foo :message', '*')->andReturn([]);
+ $this->assertEquals('foo baz', $t->getJson('foo :message', ['baz']));
+ }
+
protected function getLoader()
{
return m::mock('Illuminate\Translation\LoaderInterface'); | true |
Other | laravel | framework | fc302a6667f9dcce53395d01d8e6ba752ea62955.json | Add AuthenticateSession middleware. | src/Illuminate/Foundation/Http/Kernel.php | @@ -75,6 +75,7 @@ class Kernel implements KernelContract
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Illuminate\Auth\Middleware\Authenticate::class,
+ \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Auth\Middleware\Authorize::class,
]; | true |
Other | laravel | framework | fc302a6667f9dcce53395d01d8e6ba752ea62955.json | Add AuthenticateSession middleware. | src/Illuminate/Session/Middleware/AuthenticateSession.php | @@ -0,0 +1,88 @@
+<?php
+
+namespace Illuminate\Session\Middleware;
+
+use Closure;
+use Illuminate\Auth\AuthenticationException;
+use Illuminate\Contracts\Auth\Factory as AuthFactory;
+
+class AuthenticateSession
+{
+ /**
+ * The authentication factory implementation.
+ *
+ * @var \Illuminate\Contracts\Auth\Factory
+ */
+ protected $auth;
+
+ /**
+ * Create a new middleware instance.
+ *
+ * @param \Illuminate\Contracts\Auth\Factory $auth
+ * @return void
+ */
+ public function __construct(AuthFactory $auth)
+ {
+ $this->auth = $auth;
+ }
+
+ /**
+ * Handle an incoming request.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @param \Closure $next
+ * @return mixed
+ */
+ public function handle($request, Closure $next)
+ {
+ if (! $request->user() || ! $request->session()) {
+ return $next($request);
+ }
+
+ if (! $request->session()->has('password_hash') && $this->auth->viaRemember()) {
+ $this->logout($request);
+ }
+
+ if (! $request->session()->has('password_hash')) {
+ $this->storePasswordHashInSession($request);
+ }
+
+ if ($request->session()->get('password_hash') !== $request->user()->password) {
+ $this->logout($request);
+ }
+
+ return tap($next($request), function () use ($request) {
+ $this->storePasswordHashInSession($request);
+ });
+ }
+
+ /**
+ * Store the user's current password hash in the session.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @return void
+ */
+ protected function storePasswordHashInSession($request)
+ {
+ $request->session()->put([
+ 'password_hash' => $request->user()->password,
+ ]);
+ }
+
+ /**
+ * Log the user out of the application.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @return void
+ *
+ * @throws \Illuminate\Auth\AuthenticationException
+ */
+ protected function logout($request)
+ {
+ $this->auth->logout();
+
+ $request->session()->flush();
+
+ throw new AuthenticationException;
+ }
+} | true |
Other | laravel | framework | 2ce1ed4eca81574d6929e350d5b9a6444797a0bb.json | add return statement | src/Illuminate/Queue/SyncQueue.php | @@ -56,6 +56,7 @@ public function push($job, $data = '', $queue = null)
*
* @param \Illuminate\Queue\Jobs\Job $queueJob
* @param \Exception $e
+ * @return void
*
* @throws \Exception
*/ | false |
Other | laravel | framework | 1ad9a66b93f82ce2a21f651620818f4557682d68.json | Remove unused imports | src/Illuminate/Database/Connectors/ConnectionFactory.php | @@ -2,7 +2,6 @@
namespace Illuminate\Database\Connectors;
-use PDO;
use PDOException;
use Illuminate\Support\Arr;
use InvalidArgumentException; | true |
Other | laravel | framework | 1ad9a66b93f82ce2a21f651620818f4557682d68.json | Remove unused imports | src/Illuminate/Database/Eloquent/Model.php | @@ -3,7 +3,6 @@
namespace Illuminate\Database\Eloquent;
use Closure;
-use DateTime;
use Exception;
use ArrayAccess;
use Carbon\Carbon; | true |
Other | laravel | framework | 1ad9a66b93f82ce2a21f651620818f4557682d68.json | Remove unused imports | src/Illuminate/Database/Eloquent/Relations/HasOne.php | @@ -2,7 +2,6 @@
namespace Illuminate\Database\Eloquent\Relations;
-use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
| true |
Other | laravel | framework | 1ad9a66b93f82ce2a21f651620818f4557682d68.json | Remove unused imports | src/Illuminate/Mail/Jobs/HandleQueuedMessage.php | @@ -5,7 +5,6 @@
use Closure;
use Illuminate\Support\Str;
use SuperClosure\Serializer;
-use Illuminate\Contracts\Queue\Job;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Queue\SerializesAndRestoresModelIdentifiers;
| true |
Other | laravel | framework | 1ad9a66b93f82ce2a21f651620818f4557682d68.json | Remove unused imports | src/Illuminate/Notifications/Events/BroadcastNotificationCreated.php | @@ -3,7 +3,6 @@
namespace Illuminate\Notifications\Events;
use Illuminate\Queue\SerializesModels;
-use Illuminate\Notifications\Notification;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
| true |
Other | laravel | framework | 1ad9a66b93f82ce2a21f651620818f4557682d68.json | Remove unused imports | src/Illuminate/Queue/Worker.php | @@ -4,7 +4,6 @@
use Exception;
use Throwable;
-use Illuminate\Contracts\Queue\Job;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Symfony\Component\Debug\Exception\FatalThrowableError; | true |
Other | laravel | framework | dc5f1317364ac426b326052c213742b48316cb99.json | throw broadcast exception | src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php | @@ -3,9 +3,9 @@
namespace Illuminate\Broadcasting\Broadcasters;
use Pusher;
-use RuntimeException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
+use Illuminate\Broadcasting\BroadcastException;
use Symfony\Component\HttpKernel\Exception\HttpException;
class PusherBroadcaster extends Broadcaster
@@ -97,11 +97,12 @@ public function broadcast(array $channels, $event, array $payload = [])
$response = $this->pusher->trigger($this->formatChannels($channels), $event, $payload, $socket);
- if ((is_array($response) && $response['status'] == 200) || $response === true) {
+ if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
+ || $response === true) {
return;
}
- throw new RuntimeException(
+ throw new BroadcastException(
is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
);
} | false |
Other | laravel | framework | 67e7beb119b40abf31a65affa0abe0c9cb9463ac.json | Throw exception on Pusher broadcaster error | src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php | @@ -3,6 +3,7 @@
namespace Illuminate\Broadcasting\Broadcasters;
use Pusher;
+use RuntimeException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -90,7 +91,13 @@ public function broadcast(array $channels, $event, array $payload = [])
{
$socket = Arr::pull($payload, 'socket');
- $this->pusher->trigger($this->formatChannels($channels), $event, $payload, $socket);
+ if (true === $response = $this->pusher->trigger($this->formatChannels($channels), $event, $payload, $socket)) {
+ return;
+ }
+
+ throw new RuntimeException(
+ is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
+ );
}
/** | false |
Other | laravel | framework | adabe9a6b78e71f661da7f58ba36970d63295e8e.json | Use Blade instead of raw PHP to display JSON | src/Illuminate/Auth/Console/stubs/make/views/layouts/app.stub | @@ -15,10 +15,9 @@
<!-- Scripts -->
<script>
- window.Laravel = <?php echo json_encode([
+ window.Laravel = {!! json_encode([
'csrfToken' => csrf_token(),
- ]); ?>
-
+ ]) !!};
</script>
</head>
<body> | false |
Other | laravel | framework | efc38817413c92213e3268d3b109daa74211f446.json | Fix foreign key issue when primary key is not 'id' | src/Illuminate/Database/Eloquent/Model.php | @@ -2128,7 +2128,7 @@ public function setPerPage($perPage)
*/
public function getForeignKey()
{
- return Str::snake(class_basename($this)).'_id';
+ return Str::snake(class_basename($this)).'_'.$this->primaryKey;
}
/** | false |
Other | laravel | framework | 84842c1d845cd01a2def163539204cbc15a59821.json | Allow SlackAttachment color override (#16360)
* Add color to SlackAttachment
* Allow override of Slack Attachment color | src/Illuminate/Notifications/Channels/SlackWebhookChannel.php | @@ -77,7 +77,7 @@ protected function attachments(SlackMessage $message)
{
return collect($message->attachments)->map(function ($attachment) use ($message) {
return array_filter([
- 'color' => $message->color(),
+ 'color' => $attachment->color ?: $message->color(),
'title' => $attachment->title,
'text' => $attachment->content,
'title_link' => $attachment->url, | true |
Other | laravel | framework | 84842c1d845cd01a2def163539204cbc15a59821.json | Allow SlackAttachment color override (#16360)
* Add color to SlackAttachment
* Allow override of Slack Attachment color | src/Illuminate/Notifications/Messages/SlackAttachment.php | @@ -25,6 +25,13 @@ class SlackAttachment
*/
public $content;
+ /**
+ * The attachment's color.
+ *
+ * @var string
+ */
+ public $color;
+
/**
* The attachment's fields.
*
@@ -60,6 +67,19 @@ public function content($content)
return $this;
}
+ /**
+ * Set the color of the attachment.
+ *
+ * @param string $color
+ * @return $this
+ */
+ public function color($color)
+ {
+ $this->color = $color;
+
+ return $this;
+ }
+
/**
* Set the fields of the attachment.
* | true |
Other | laravel | framework | 57be173daca2e85964b02f50d5de2fa7c83bdbdb.json | Add doc-block for code auto-complete (#16341)
Add doc-block Illuminate\Database\Eloquent\Builder for code auto-complete in PhpStorm | src/Illuminate/Database/Eloquent/Builder.php | @@ -12,6 +12,9 @@
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Query\Builder as QueryBuilder;
+/**
+ * @mixin \Illuminate\Database\Query\Builder
+ */
class Builder
{
/** | false |
Other | laravel | framework | c2e4b5c000961800650f8ef6b40160ff664261f5.json | Catch Throwable in timezone validation (#16344) | src/Illuminate/Validation/Validator.php | @@ -6,6 +6,7 @@
use DateTime;
use Countable;
use Exception;
+use Throwable;
use DateTimeZone;
use RuntimeException;
use DateTimeInterface;
@@ -1976,6 +1977,8 @@ protected function validateTimezone($attribute, $value)
new DateTimeZone($value);
} catch (Exception $e) {
return false;
+ } catch (Throwable $e) {
+ return false;
}
return true; | true |
Other | laravel | framework | c2e4b5c000961800650f8ef6b40160ff664261f5.json | Catch Throwable in timezone validation (#16344) | tests/Validation/ValidationValidatorTest.php | @@ -2063,6 +2063,9 @@ public function testValidateTimezone()
$v = new Validator($trans, ['foo' => 'GMT'], ['foo' => 'Timezone']);
$this->assertTrue($v->passes());
+
+ $v = new Validator($trans, ['foo' => ['this_is_not_a_timezone']], ['foo' => 'Timezone']);
+ $this->assertFalse($v->passes());
}
public function testValidateRegex() | true |
Other | laravel | framework | 6b906e3d45d023a7432f3f509bc9509d1f9bf2e3.json | escape the delimiter before preg_match (#16309) | src/Illuminate/Validation/Validator.php | @@ -2790,7 +2790,7 @@ protected function dependsOnOtherFields($rule)
*/
protected function getExplicitKeys($attribute)
{
- $pattern = str_replace('\*', '([^\.]+)', preg_quote($this->getPrimaryAttribute($attribute)));
+ $pattern = str_replace('\*', '([^\.]+)', preg_quote($this->getPrimaryAttribute($attribute), '/'));
if (preg_match('/^'.$pattern.'/', $attribute, $keys)) {
array_shift($keys); | false |
Other | laravel | framework | 8c8eb21546b1ae949c459c244d8188308e423f69.json | use forceReconnection method (#16298) | src/Illuminate/Mail/Mailer.php | @@ -373,7 +373,7 @@ protected function sendSwiftMessage($message)
try {
return $this->swift->send($message, $this->failedRecipients);
} finally {
- $this->swift->getTransport()->stop();
+ $this->forceReconnection();
}
}
| false |
Other | laravel | framework | 9f19107fe952aac76560a694d580b5ca328323e9.json | Fix CookieJar::queue() method signature | src/Illuminate/Contracts/Cookie/QueueingFactory.php | @@ -7,9 +7,11 @@ interface QueueingFactory extends Factory
/**
* Queue a cookie to send with the next response.
*
+ * @param array $params
+ *
* @return void
*/
- public function queue();
+ public function queue(...$params);
/**
* Remove a cookie from the queue. | true |
Other | laravel | framework | 9f19107fe952aac76560a694d580b5ca328323e9.json | Fix CookieJar::queue() method signature | src/Illuminate/Cookie/CookieJar.php | @@ -113,14 +113,16 @@ public function queued($key, $default = null)
/**
* Queue a cookie to send with the next response.
*
+ * @param array $params
+ *
* @return void
*/
- public function queue()
+ public function queue(...$params)
{
- if (head(func_get_args()) instanceof Cookie) {
- $cookie = head(func_get_args());
+ if (head($params) instanceof Cookie) {
+ $cookie = head($params);
} else {
- $cookie = call_user_func_array([$this, 'make'], func_get_args());
+ $cookie = call_user_func_array([$this, 'make'], $params);
}
$this->queued[$cookie->getName()] = $cookie; | true |
Other | laravel | framework | 2dcf1a0f9b767a937fbcad0af5f96cbe1856f85f.json | Fix some docblocks
Also, updated the receiveJson type hint | src/Illuminate/Foundation/Testing/Concerns/InteractsWithAuthentication.php | @@ -7,7 +7,7 @@ trait InteractsWithAuthentication
/**
* Assert that the user is authenticated.
*
- * @param string|null $guard
+ * @param string|null $guard
* @return $this
*/
public function seeIsAuthenticated($guard = null)
@@ -100,7 +100,7 @@ public function dontSeeCredentials(array $credentials, $guard = null)
/**
* Return true is the credentials are valid, false otherwise.
*
- * @param array $credentials
+ * @param array $credentials
* @param string|null $guard
* @return bool
*/ | true |
Other | laravel | framework | 2dcf1a0f9b767a937fbcad0af5f96cbe1856f85f.json | Fix some docblocks
Also, updated the receiveJson type hint | src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php | @@ -16,8 +16,8 @@ trait InteractsWithConsole
/**
* Call artisan command and return code.
*
- * @param string $command
- * @param array $parameters
+ * @param string $command
+ * @param array $parameters
* @return int
*/
public function artisan($command, $parameters = []) | true |
Other | laravel | framework | 2dcf1a0f9b767a937fbcad0af5f96cbe1856f85f.json | Fix some docblocks
Also, updated the receiveJson type hint | src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php | @@ -118,8 +118,8 @@ public function get($uri, array $headers = [])
/**
* Visit the given URI with a GET request, expecting a JSON response.
*
- * @param string $uri
- * @param array $headers
+ * @param string $uri
+ * @param array $headers
* @return $this
*/
public function getJson($uri, array $headers = [])
@@ -147,9 +147,9 @@ public function post($uri, array $data = [], array $headers = [])
/**
* Visit the given URI with a POST request, expecting a JSON response.
*
- * @param string $uri
- * @param array $data
- * @param array $headers
+ * @param string $uri
+ * @param array $data
+ * @param array $headers
* @return $this
*/
public function postJson($uri, array $data = [], array $headers = [])
@@ -177,9 +177,9 @@ public function put($uri, array $data = [], array $headers = [])
/**
* Visit the given URI with a PUT request, expecting a JSON response.
*
- * @param string $uri
- * @param array $data
- * @param array $headers
+ * @param string $uri
+ * @param array $data
+ * @param array $headers
* @return $this
*/
public function putJson($uri, array $data = [], array $headers = [])
@@ -207,9 +207,9 @@ public function patch($uri, array $data = [], array $headers = [])
/**
* Visit the given URI with a PATCH request, expecting a JSON response.
*
- * @param string $uri
- * @param array $data
- * @param array $headers
+ * @param string $uri
+ * @param array $data
+ * @param array $headers
* @return $this
*/
public function patchJson($uri, array $data = [], array $headers = [])
@@ -237,9 +237,9 @@ public function delete($uri, array $data = [], array $headers = [])
/**
* Visit the given URI with a DELETE request, expecting a JSON response.
*
- * @param string $uri
- * @param array $data
- * @param array $headers
+ * @param string $uri
+ * @param array $data
+ * @param array $headers
* @return $this
*/
public function deleteJson($uri, array $data = [], array $headers = [])
@@ -281,7 +281,7 @@ protected function shouldReturnJson(array $data = null)
* @param array|null $data
* @return $this|null
*/
- protected function receiveJson($data = null)
+ protected function receiveJson(array $data = null)
{
return $this->seeJson($data);
}
@@ -559,10 +559,10 @@ protected function withServerVariables(array $server)
*
* @param string $method
* @param string $uri
- * @param array $parameters
- * @param array $cookies
- * @param array $files
- * @param array $server
+ * @param array $parameters
+ * @param array $cookies
+ * @param array $files
+ * @param array $server
* @param string $content
* @return \Illuminate\Http\Response
*/
@@ -593,10 +593,10 @@ public function call($method, $uri, $parameters = [], $cookies = [], $files = []
*
* @param string $method
* @param string $uri
- * @param array $parameters
- * @param array $cookies
- * @param array $files
- * @param array $server
+ * @param array $parameters
+ * @param array $cookies
+ * @param array $files
+ * @param array $server
* @param string $content
* @return \Illuminate\Http\Response
*/
@@ -612,11 +612,11 @@ public function callSecure($method, $uri, $parameters = [], $cookies = [], $file
*
* @param string $method
* @param string $action
- * @param array $wildcards
- * @param array $parameters
- * @param array $cookies
- * @param array $files
- * @param array $server
+ * @param array $wildcards
+ * @param array $parameters
+ * @param array $cookies
+ * @param array $files
+ * @param array $server
* @param string $content
* @return \Illuminate\Http\Response
*/
@@ -632,11 +632,11 @@ public function action($method, $action, $wildcards = [], $parameters = [], $coo
*
* @param string $method
* @param string $name
- * @param array $routeParameters
- * @param array $parameters
- * @param array $cookies
- * @param array $files
- * @param array $server
+ * @param array $routeParameters
+ * @param array $parameters
+ * @param array $cookies
+ * @param array $files
+ * @param array $server
* @param string $content
* @return \Illuminate\Http\Response
*/
@@ -816,7 +816,7 @@ public function assertViewMissing($key)
* Assert whether the client was redirected to a given URI.
*
* @param string $uri
- * @param array $with
+ * @param array $with
* @return $this
*/
public function assertRedirectedTo($uri, $with = [])
@@ -834,8 +834,8 @@ public function assertRedirectedTo($uri, $with = [])
* Assert whether the client was redirected to a given route.
*
* @param string $name
- * @param array $parameters
- * @param array $with
+ * @param array $parameters
+ * @param array $with
* @return $this
*/
public function assertRedirectedToRoute($name, $parameters = [], $with = [])
@@ -847,8 +847,8 @@ public function assertRedirectedToRoute($name, $parameters = [], $with = [])
* Assert whether the client was redirected to a given action.
*
* @param string $name
- * @param array $parameters
- * @param array $with
+ * @param array $parameters
+ * @param array $with
* @return $this
*/
public function assertRedirectedToAction($name, $parameters = [], $with = []) | true |
Other | laravel | framework | 2dcf1a0f9b767a937fbcad0af5f96cbe1856f85f.json | Fix some docblocks
Also, updated the receiveJson type hint | tests/Database/DatabaseMigrationRefreshCommandTest.php | @@ -69,7 +69,7 @@ protected function runCommand($command, $input = [])
class InputMatcher extends m\Matcher\MatcherAbstract
{
/**
- * @param \Symfony\Component\Console\Input\ArrayInput $actual
+ * @param \Symfony\Component\Console\Input\ArrayInput $actual
* @return bool
*/
public function match(&$actual) | true |
Other | laravel | framework | ee385fa5eab0c4642f47636f0e033e982d402bb9.json | use tries as the property | src/Illuminate/Queue/Jobs/Job.php | @@ -239,9 +239,9 @@ public function payload()
*
* @return int|null
*/
- public function retries()
+ public function maxTries()
{
- return array_get($this->payload(), 'retries');
+ return array_get($this->payload(), 'maxTries');
}
/** | true |
Other | laravel | framework | ee385fa5eab0c4642f47636f0e033e982d402bb9.json | use tries as the property | src/Illuminate/Queue/Queue.php | @@ -81,7 +81,7 @@ protected function createPayload($job, $data = '', $queue = null)
if (is_object($job)) {
$payload = json_encode([
'job' => 'Illuminate\Queue\CallQueuedHandler@call',
- 'retries' => isset($job->retries) ? $job->retries : null,
+ 'maxTries' => isset($job->tries) ? $job->tries : null,
'timeout' => isset($job->timeout) ? $job->timeout : null,
'data' => [
'commandName' => get_class($job), | true |
Other | laravel | framework | ee385fa5eab0c4642f47636f0e033e982d402bb9.json | use tries as the property | src/Illuminate/Queue/Worker.php | @@ -281,7 +281,7 @@ protected function handleJobException($connectionName, $job, WorkerOptions $opti
*/
protected function markJobAsFailedIfAlreadyExceedsMaxAttempts($connectionName, $job, $maxTries)
{
- $maxTries = ! is_null($job->retries()) ? $job->retries() : $maxTries;
+ $maxTries = ! is_null($job->maxTries()) ? $job->maxTries() : $maxTries;
if ($maxTries === 0 || $job->attempts() <= $maxTries) {
return;
@@ -308,7 +308,7 @@ protected function markJobAsFailedIfAlreadyExceedsMaxAttempts($connectionName, $
protected function markJobAsFailedIfHasExceededMaxAttempts(
$connectionName, $job, $maxTries, $e
) {
- $maxTries = ! is_null($job->retries()) ? $job->retries() : $maxTries;
+ $maxTries = ! is_null($job->maxTries()) ? $job->maxTries() : $maxTries;
if ($maxTries === 0 || $job->attempts() < $maxTries) {
return; | true |
Other | laravel | framework | ee385fa5eab0c4642f47636f0e033e982d402bb9.json | use tries as the property | tests/Queue/QueueWorkerTest.php | @@ -136,7 +136,7 @@ public function test_job_based_max_retries()
});
$job->attempts = 2;
- $job->retries = 10;
+ $job->maxTries = 10;
$worker = $this->getWorker('default', ['queue' => [$job]]);
$worker->runNextJob('default', 'queue', $this->workerOptions(['maxTries' => 1]));
@@ -239,7 +239,7 @@ class WorkerFakeJob
public $callback;
public $deleted = false;
public $releaseAfter;
- public $retries;
+ public $maxTries;
public $attempts = 0;
public $failedWith;
@@ -260,9 +260,9 @@ public function payload()
return [];
}
- public function retries()
+ public function maxTries()
{
- return $this->retries;
+ return $this->maxTries;
}
public function delete() | true |
Other | laravel | framework | 2382dc3f374bee7ad966d11ecb35a1429d9a09e8.json | tweak a few things | src/Illuminate/Queue/Jobs/Job.php | @@ -15,13 +15,6 @@ abstract class Job
*/
protected $instance;
- /**
- * The command instance.
- *
- * @var mixed
- */
- protected $command;
-
/**
* The IoC container instance.
*
@@ -241,41 +234,24 @@ public function payload()
return json_decode($this->getRawBody(), true);
}
- /**
- * The underlying command.
- *
- * @return mixed
- */
- public function getCommand()
- {
- if ($this->command) {
- return $this->command;
- }
-
- $payload = $this->payload();
-
- return $this->command = isset($payload['data']['command'])
- ? unserialize($payload['data']['command']) : null;
- }
-
/**
* The number of times to attempt a job.
*
- * @return int
+ * @return int|null
*/
public function retries()
{
- return $this->getCommand() ? $this->getCommand()->retries : null;
+ return array_get($this->payload(), 'retries');
}
/**
* The number of seconds the job can run.
*
- * @return int
+ * @return int|null
*/
public function timeout()
{
- return $this->getCommand() ? $this->getCommand()->timeout : null;
+ return array_get($this->payload(), 'timeout');
}
/** | true |
Other | laravel | framework | 2382dc3f374bee7ad966d11ecb35a1429d9a09e8.json | tweak a few things | src/Illuminate/Queue/Queue.php | @@ -81,6 +81,8 @@ protected function createPayload($job, $data = '', $queue = null)
if (is_object($job)) {
$payload = json_encode([
'job' => 'Illuminate\Queue\CallQueuedHandler@call',
+ 'retries' => isset($job->retries) ? $job->retries : null,
+ 'timeout' => isset($job->timeout) ? $job->timeout : null,
'data' => [
'commandName' => get_class($job),
'command' => serialize(clone $job), | true |
Other | laravel | framework | 2382dc3f374bee7ad966d11ecb35a1429d9a09e8.json | tweak a few things | src/Illuminate/Queue/Worker.php | @@ -102,7 +102,7 @@ protected function registerTimeoutHandler($job, WorkerOptions $options)
return;
}
- $timeout = $job && $job->timeout() !== null ? $job->timeout() : $options->timeout;
+ $timeout = $job && ! is_null($job->timeout()) ? $job->timeout() : $options->timeout;
pcntl_async_signals(true);
@@ -281,7 +281,7 @@ protected function handleJobException($connectionName, $job, WorkerOptions $opti
*/
protected function markJobAsFailedIfAlreadyExceedsMaxAttempts($connectionName, $job, $maxTries)
{
- $maxTries = $job->retries() !== null ? $job->retries() : $maxTries;
+ $maxTries = ! is_null($job->retries()) ? $job->retries() : $maxTries;
if ($maxTries === 0 || $job->attempts() <= $maxTries) {
return;
@@ -308,7 +308,7 @@ protected function markJobAsFailedIfAlreadyExceedsMaxAttempts($connectionName, $
protected function markJobAsFailedIfHasExceededMaxAttempts(
$connectionName, $job, $maxTries, $e
) {
- $maxTries = $job->retries() !== null ? $job->retries() : $maxTries;
+ $maxTries = ! is_null($job->retries()) ? $job->retries() : $maxTries;
if ($maxTries === 0 || $job->attempts() < $maxTries) {
return;
@@ -331,14 +331,16 @@ protected function failJob($connectionName, $job, $e)
return;
}
- // If the job has failed, we will delete it, call the "failed" method and then call
- // an event indicating the job has failed so it can be logged if needed. This is
- // to allow every developer to better keep monitor of their failed queue jobs.
- $job->delete();
-
- $job->failed($e);
+ try {
+ // If the job has failed, we will delete it, call the "failed" method and then call
+ // an event indicating the job has failed so it can be logged if needed. This is
+ // to allow every developer to better keep monitor of their failed queue jobs.
+ $job->delete();
- $this->raiseFailedJobEvent($connectionName, $job, $e);
+ $job->failed($e);
+ } finally {
+ $this->raiseFailedJobEvent($connectionName, $job, $e);
+ }
}
/** | true |
Other | laravel | framework | 57ba218e1dd4a543f24623b1b4e3e89b5e690469.json | Fix chunk test when negative value (#16246) | tests/Support/SupportCollectionTest.php | @@ -698,7 +698,7 @@ public function testChunkWhenGivenLessThanZero()
$this->assertEquals(
[],
- $collection->chunk(0)->toArray()
+ $collection->chunk(-1)->toArray()
);
}
| false |
Other | laravel | framework | 799164513891a258e858061fc7f86a415cb38821.json | Add hook functions and tests | src/Illuminate/Validation/ValidatesWhenResolvedTrait.php | @@ -14,13 +14,15 @@ trait ValidatesWhenResolvedTrait
*/
public function validate()
{
+ $this->beforeValidation();
$instance = $this->getValidatorInstance();
if (! $this->passesAuthorization()) {
$this->failedAuthorization();
} elseif (! $instance->passes()) {
$this->failedValidation($instance);
}
+ $this->afterValidation();
}
/**
@@ -71,4 +73,24 @@ protected function failedAuthorization()
{
throw new UnauthorizedException;
}
+
+ /**
+ * Provide a hook for taking action before validation
+ *
+ * @return void
+ */
+ protected function beforeValidation()
+ {
+ // no default action
+ }
+
+ /**
+ * Provide a hook for taking action after validation
+ *
+ * @return void
+ */
+ protected function afterValidation()
+ {
+ // no default action
+ }
} | true |
Other | laravel | framework | 799164513891a258e858061fc7f86a415cb38821.json | Add hook functions and tests | tests/Foundation/FoundationFormRequestTest.php | @@ -76,6 +76,35 @@ public function testRedirectResponseIsProperlyCreatedWithGivenErrors()
$request->response(['errors']);
}
+
+ public function testValidateFunctionRunsBeforeValidationFunction()
+ {
+ $request = FoundationTestFormRequestHooks::create('/', 'GET', ['name' => 'abigail']);
+ $request->setContainer($container = new Container);
+ $factory = m::mock('Illuminate\Validation\Factory');
+ $factory->shouldReceive('make')->once()->with(['name' => 'Taylor'], ['name' => 'required'], [], [])->andReturn(
+ $validator = m::mock('Illuminate\Validation\Validator')
+ );
+ $container->instance('Illuminate\Contracts\Validation\Factory', $factory);
+ $validator->shouldReceive('passes')->once()->andReturn(true);
+
+ $request->validate($factory);
+ }
+
+ public function testValidateFunctionRunsAfterValidationFunctionIfValidationPasses()
+ {
+ $request = FoundationTestFormRequestStub::create('/', 'GET', ['name' => 'abigail']);
+ $request->setContainer($container = new Container);
+ $factory = m::mock('Illuminate\Validation\Factory');
+ $factory->shouldReceive('make')->once()->with(['name' => 'abigail'], ['name' => 'required'], [], [])->andReturn(
+ $validator = m::mock('Illuminate\Validation\Validator')
+ );
+ $container->instance('Illuminate\Contracts\Validation\Factory', $factory);
+ $validator->shouldReceive('passes')->once()->andReturn(true);
+
+ $request->validate($factory);
+ $this->assertSame('Jeffrey', $request->get('name'));
+ }
}
class FoundationTestFormRequestStub extends Illuminate\Foundation\Http\FormRequest
@@ -89,6 +118,11 @@ public function authorize()
{
return true;
}
+
+ public function afterValidation()
+ {
+ $this->replace(['name' => 'Jeffrey']);
+ }
}
class FoundationTestFormRequestForbiddenStub extends Illuminate\Foundation\Http\FormRequest
@@ -103,3 +137,20 @@ public function authorize()
return false;
}
}
+class FoundationTestFormRequestHooks extends Illuminate\Foundation\Http\FormRequest
+{
+ public function rules()
+ {
+ return ['name' => 'required'];
+ }
+
+ public function authorize()
+ {
+ return true;
+ }
+
+ public function beforeValidation()
+ {
+ $this->replace(['name' => 'Taylor']);
+ }
+} | true |
Other | laravel | framework | 2f2da143b27e5d2522c76e8e2c0bf0c9e9f79f02.json | Fix Translator::sortReplacements (#16221) | src/Illuminate/Translation/Translator.php | @@ -198,7 +198,7 @@ protected function sortReplacements(array $replace)
{
return (new Collection($replace))->sortBy(function ($value, $key) {
return mb_strlen($key) * -1;
- });
+ })->all();
}
/** | false |
Other | laravel | framework | 5d8d7bab941e19894400a5cda5a61b81828b98ae.json | Remove merge comments | src/Illuminate/Queue/Worker.php | @@ -235,11 +235,6 @@ protected function handleJobException($connectionName, $job, WorkerOptions $opti
$this->raiseExceptionOccurredJobEvent(
$connectionName, $job, $e
);
-<<<<<<< HEAD
-=======
- } catch (Exception $exception) {
- $this->raiseFailedJobEvent($connectionName, $job, $exception);
->>>>>>> origin/fix-queue-failed-job-event
} finally {
if (! $job->isDeleted()) {
$job->release($options->delay); | false |
Other | laravel | framework | c1de4911bba6ad3b273106f3af26b14bafc8a204.json | Try catch failJob
failJob gets called from 2 separate places. Better to put this code
around a try catch instead of in the try catch in handleJobException | src/Illuminate/Queue/Worker.php | @@ -3,6 +3,7 @@
namespace Illuminate\Queue;
use Exception;
+use RuntimeException;
use Throwable;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Contracts\Events\Dispatcher;
@@ -234,8 +235,6 @@ protected function handleJobException($connectionName, $job, WorkerOptions $opti
$this->raiseExceptionOccurredJobEvent(
$connectionName, $job, $e
);
- } catch(Exception $exception) {
- $this->raiseFailedJobEvent($connectionName, $job, $exception);
} finally {
if (! $job->isDeleted()) {
$job->release($options->delay);
@@ -266,8 +265,6 @@ protected function markJobAsFailedIfAlreadyExceedsMaxAttempts($connectionName, $
);
$this->failJob($connectionName, $job, $e);
-
- throw $e;
}
/**
@@ -303,14 +300,20 @@ protected function failJob($connectionName, $job, $e)
return;
}
- // If the job has failed, we will delete it, call the "failed" method and then call
- // an event indicating the job has failed so it can be logged if needed. This is
- // to allow every developer to better keep monitor of their failed queue jobs.
- $job->delete();
+ try {
+ // If the job has failed, we will delete it, call the "failed" method and then call
+ // an event indicating the job has failed so it can be logged if needed. This is
+ // to allow every developer to better keep monitor of their failed queue jobs.
+ $job->delete();
- $job->failed($e);
+ $job->failed($e);
+ } catch(Exception $exception) {
+ $e = new RuntimeException($exception->getMessage(), $exception->getCode(), $e);
+ }
$this->raiseFailedJobEvent($connectionName, $job, $e);
+
+ throw $e;
}
/** | false |
Other | laravel | framework | f2c1253fc2aae9df160f6cc8686196066083c0d4.json | Fix docblock typo. (#16199) | src/Illuminate/Database/Query/Grammars/Grammar.php | @@ -824,7 +824,7 @@ protected function removeLeadingBoolean($value)
}
/**
- * Get the gramar specific operators.
+ * Get the grammar specific operators.
*
* @return array
*/ | false |
Other | laravel | framework | 2d301e31203eb6fa2364b3857d2fd4f4a0e85ea1.json | Use UUID for generating file names | src/Illuminate/Http/FileHelpers.php | @@ -46,6 +46,6 @@ public function hashName($path = null)
$path = rtrim($path, '/').'/';
}
- return $path.md5_file($this->getRealPath()).'.'.$this->guessExtension();
+ return $path.Uuid::uuid4()->toString().'.'.$this->guessExtension();
}
} | false |
Other | laravel | framework | c460b69aa1be9838ea8c74c80417c92444677772.json | change method order | src/Illuminate/Notifications/HasDatabaseNotifications.php | @@ -14,22 +14,22 @@ public function notifications()
}
/**
- * Get the entity's unread notifications.
+ * Get the entity's read notifications.
*/
- public function unreadNotifications()
+ public function readNotifications()
{
return $this->morphMany(DatabaseNotification::class, 'notifiable')
- ->whereNull('read_at')
+ ->whereNotNull('read_at')
->orderBy('created_at', 'desc');
}
/**
- * Get the entity's read notifications.
+ * Get the entity's unread notifications.
*/
- public function readNotifications()
+ public function unreadNotifications()
{
return $this->morphMany(DatabaseNotification::class, 'notifiable')
- ->whereNotNull('read_at')
+ ->whereNull('read_at')
->orderBy('created_at', 'desc');
}
} | false |
Other | laravel | framework | 148564c49fd55be19ffb00d6cc506a232bec413d.json | Add test when last chunk is complete | tests/Database/DatabaseEloquentBuilderTest.php | @@ -154,7 +154,28 @@ public function testValueMethodWithModelNotFound()
$this->assertNull($builder->value('name'));
}
- public function testChunkExecuteCallbackOverPaginatedRequest()
+ public function testChunkWithLastChunkComplete()
+ {
+ $builder = m::mock('Illuminate\Database\Eloquent\Builder[forPage,get]', [$this->getMockQueryBuilder()]);
+ $chunk1 = new Collection(['foo1', 'foo2']);
+ $chunk2 = new Collection(['foo3', 'foo4']);
+ $chunk3 = new Collection([]);
+ $builder->shouldReceive('forPage')->once()->with(1, 2)->andReturn($builder);
+ $builder->shouldReceive('forPage')->once()->with(2, 2)->andReturn($builder);
+ $builder->shouldReceive('forPage')->once()->with(3, 2)->andReturn($builder);
+ $builder->shouldReceive('get')->times(3)->andReturn($chunk1, $chunk2, $chunk3);
+
+ $callbackExecutionAssertor = m::mock('StdClass');
+ $callbackExecutionAssertor->shouldReceive('doSomething')->with($chunk1)->once();
+ $callbackExecutionAssertor->shouldReceive('doSomething')->with($chunk2)->once();
+ $callbackExecutionAssertor->shouldReceive('doSomething')->with($chunk3)->never();
+
+ $builder->chunk(2, function ($results) use ($callbackExecutionAssertor) {
+ $callbackExecutionAssertor->doSomething($results);
+ });
+ }
+
+ public function testChunkWithLastChunkPartial()
{
$builder = m::mock('Illuminate\Database\Eloquent\Builder[forPage,get]', [$this->getMockQueryBuilder()]);
$chunk1 = new Collection(['foo1', 'foo2']); | false |
Other | laravel | framework | 2da3d433e57975198c9c3f4d000e8bf6359ceddb.json | add file to optimize | src/Illuminate/Foundation/Console/Optimize/config.php | @@ -20,6 +20,7 @@
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Cookie/QueueingFactory.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Encryption/Encrypter.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Queue/QueueableEntity.php',
+ $basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Routing/BindingRegistrar.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Routing/Registrar.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Routing/ResponseFactory.php',
$basePath.'/vendor/laravel/framework/src/Illuminate/Contracts/Routing/UrlGenerator.php', | false |
Other | laravel | framework | 03e44e6406dd0c8cf9de94e1ed58db586858bc24.json | add option shortcut 'r' for resource. (#16141) | src/Illuminate/Routing/Console/ControllerMakeCommand.php | @@ -61,7 +61,7 @@ protected function getDefaultNamespace($rootNamespace)
protected function getOptions()
{
return [
- ['resource', null, InputOption::VALUE_NONE, 'Generate a resource controller class.'],
+ ['resource', 'r', InputOption::VALUE_NONE, 'Generate a resource controller class.'],
];
}
| false |
Other | laravel | framework | e5697d5f0c244b443a7622328a6d3d99b93dbe72.json | Remove duplicate useless empty lines. (#16130) | tests/Validation/ValidationExistsRuleTest.php | @@ -8,7 +8,6 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
$rule->where('foo', 'bar');
$this->assertEquals('exists:table,NULL,foo,bar', (string) $rule);
-
$rule = new Illuminate\Validation\Rules\Exists('table', 'column');
$rule->where('foo', 'bar');
$this->assertEquals('exists:table,column,foo,bar', (string) $rule); | true |
Other | laravel | framework | e5697d5f0c244b443a7622328a6d3d99b93dbe72.json | Remove duplicate useless empty lines. (#16130) | tests/Validation/ValidationUniqueRuleTest.php | @@ -8,7 +8,6 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
$rule->where('foo', 'bar');
$this->assertEquals('unique:table,NULL,NULL,id,foo,bar', (string) $rule);
-
$rule = new Illuminate\Validation\Rules\Unique('table', 'column');
$rule->ignore(1, 'id_column');
$rule->where('foo', 'bar'); | true |
Other | laravel | framework | e5697d5f0c244b443a7622328a6d3d99b93dbe72.json | Remove duplicate useless empty lines. (#16130) | tests/Validation/ValidationValidatorTest.php | @@ -1424,7 +1424,6 @@ public function testValidateUniqueAndExistsSendsCorrectFieldNameToDBWithArrays()
$v->setPresenceVerifier($mock);
$this->assertTrue($v->passes());
-
$trans = $this->getIlluminateArrayTranslator();
$closure = function () {
}; | true |
Other | laravel | framework | 08ee66ade116f6ba1cc743dd36210bfdfbd196ea.json | Fix incorrect return value | src/Illuminate/Validation/Rule.php | @@ -46,7 +46,7 @@ public static function in(array $values)
* Get a not_in constraint builder instance.
*
* @param array $values
- * @return \Illuminate\Validation\Rules\In
+ * @return \Illuminate\Validation\Rules\NotIn
*/
public static function notIn(array $values)
{ | false |
Other | laravel | framework | e9ed079a6a3b51508273488c1f90fe95a47e9dcc.json | Fix empty session (#15998)
Fix session being empty when the file is being read and/or written by multiple instance of apache simultaneously. This append to me when assets (javascript / css) are being loaded dynamically using php. Multiples assets in the same request cause the sessions to be corrupted. | src/Illuminate/Session/FileSessionHandler.php | @@ -68,7 +68,7 @@ public function read($sessionId)
{
if ($this->files->exists($path = $this->path.'/'.$sessionId)) {
if (filemtime($path) >= Carbon::now()->subMinutes($this->minutes)->getTimestamp()) {
- return $this->files->get($path);
+ return $this->files->get($path, true);
}
}
| false |
Other | laravel | framework | 18d26df24f1f3b17bd20c7244d9b85d273138d79.json | Fix UUIDs when queueing. | src/Illuminate/Notifications/ChannelManager.php | @@ -68,7 +68,9 @@ public function sendNow($notifiables, $notification, array $channels = null)
foreach ($channels as $channel) {
$notification = clone $original;
- $notification->id = $notificationId;
+ if (! $notification->id) {
+ $notification->id = $notificationId;
+ }
if (! $this->shouldSendNotification($notifiable, $notification, $channel)) {
continue;
@@ -111,8 +113,16 @@ protected function queueNotification($notifiables, $notification)
$bus = $this->app->make(Bus::class);
+ $original = clone $notification;
+
foreach ($notifiables as $notifiable) {
+ $notificationId = (string) Uuid::uuid4();
+
foreach ($notification->via($notifiable) as $channel) {
+ $notification = clone $original;
+
+ $notification->id = $notificationId;
+
$bus->dispatch(
(new SendQueuedNotifications($this->formatNotifiables($notifiable), $notification, [$channel]))
->onConnection($notification->connection) | false |
Other | laravel | framework | 810311e3309ab0c1672af94a3ead1aab9200f330.json | Fix improper use of mb_substr() (#16081) | src/Illuminate/Routing/UrlGenerator.php | @@ -171,8 +171,8 @@ public function to($path, $extra = [], $secure = null)
$root = $this->getRootUrl($scheme);
if (($queryPosition = strpos($path, '?')) !== false) {
- $query = mb_substr($path, $queryPosition);
- $path = mb_substr($path, 0, $queryPosition);
+ $query = substr($path, $queryPosition);
+ $path = substr($path, 0, $queryPosition);
} else {
$query = '';
} | false |
Other | laravel | framework | 415724e94e696ce90755cf0374547982f26b9e07.json | Fix typo in doc block. | src/Illuminate/Notifications/ChannelManager.php | @@ -102,7 +102,7 @@ protected function shouldSendNotification($notifiable, $notification, $channel)
* Queue the given notification instances.
*
* @param mixed $notifiables
- * @param array[\Illuminate\Notifcations\Channels\Notification] $notification
+ * @param array[\Illuminate\Notifications\Channels\Notification] $notification
* @return void
*/
protected function queueNotification($notifiables, $notification) | false |
Other | laravel | framework | dadc76237b58ded295fa5459b1d7a9e4e6f4f33a.json | Add registered method (#16036)
call to registered method just like what AuthenticatesUsers Trait does to authenticated. | src/Illuminate/Foundation/Auth/RegistersUsers.php | @@ -34,7 +34,8 @@ public function register(Request $request)
$this->guard()->login($user);
- return redirect($this->redirectPath());
+ return $this->registered($request, $user)
+ ?: redirect($this->redirectPath());
}
/**
@@ -46,4 +47,16 @@ protected function guard()
{
return Auth::guard();
}
+
+ /**
+ * The user has been registered.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @param mixed $user
+ * @return mixed
+ */
+ protected function registered(Request $request, $user)
+ {
+ return null;
+ }
} | false |
Other | laravel | framework | 9adce329ede8750b92dd96eb791434e0cf9aa7e2.json | Update ListenerMakeCommand.php (#16038) | src/Illuminate/Foundation/Console/ListenerMakeCommand.php | @@ -114,9 +114,9 @@ protected function getDefaultNamespace($rootNamespace)
protected function getOptions()
{
return [
- ['event', null, InputOption::VALUE_REQUIRED, 'The event class being listened for.'],
+ ['event', 'e', InputOption::VALUE_REQUIRED, 'The event class being listened for.'],
- ['queued', null, InputOption::VALUE_NONE, 'Indicates the event listener should be queued.'],
+ ['queued', 'q', InputOption::VALUE_NONE, 'Indicates the event listener should be queued.'],
];
}
} | false |
Other | laravel | framework | 1a0930650601cbcbbaf4b4ede904bd147e0f461f.json | Use bootstrappers instead of events | src/Illuminate/Console/Application.php | @@ -27,6 +27,13 @@ class Application extends SymfonyApplication implements ApplicationContract
*/
protected $lastOutput;
+ /**
+ * The console application bootstrappers.
+ *
+ * @var array
+ */
+ protected static $bootstrappers = [];
+
/**
* Create a new Artisan console application.
*
@@ -44,6 +51,20 @@ public function __construct(Container $laravel, Dispatcher $events, $version)
$this->setCatchExceptions(false);
$events->fire(new Events\ArtisanStarting($this));
+
+ $this->bootstrap();
+ }
+
+ /**
+ * Bootstrap the console application.
+ *
+ * @return void
+ */
+ protected function bootstrap()
+ {
+ foreach (static::$bootstrappers as $bootstrapper) {
+ $bootstrapper($this);
+ }
}
/**
@@ -169,4 +190,15 @@ public function getLaravel()
{
return $this->laravel;
}
+
+ /**
+ * Register an application starting bootstrapper.
+ *
+ * @param \Closure $callback
+ * @return void
+ */
+ public static function starting(\Closure $callback)
+ {
+ static::$bootstrappers[] = $callback;
+ }
} | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.