Skip to content

Commit

Permalink
Merge branch 'upstream/5.5' into 5.5
Browse files Browse the repository at this point in the history
* upstream/5.5:
  Added missing postgres inet operators. (laravel#21518)
  tag v5.5.14 release notes
  version
  update v5.5 changelog
  Apply fixes from StyleCI (laravel#21514)
  formatting
  Remove unnecessary else statement
  add mapToDictionary tests
  rename method dictionary -> mapToDictionary; avoid pre-pr regression
  formatting
  formatting
  [5.5] Allow marking notifications as unread (laravel#21497)
  methods on facade are static (laravel#21501)
  StyleCI fixes
  Add ability to pass callback to whenLoaded Resource method
  Fix User model typehints & `$user` variable duplicates in Policy stub;
  Add make command for custom exceptions
  add buildToDictionary
  • Loading branch information
edmandiesamonte committed Oct 6, 2017
2 parents 34c97ae + d610151 commit 5ce5d96
Show file tree
Hide file tree
Showing 20 changed files with 298 additions and 33 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG-5.5.md
@@ -1,13 +1,17 @@
# Release Notes for 5.5.x

## [Unreleased]
## v5.5.14 (2017-10-03)

### Added
- Allow testing anonymous notifiables ([#21379](https://github.com/laravel/framework/pull/21379))
- Add relation and model attributes on `RelationNotFoundException` ([#21426](https://github.com/laravel/framework/pull/21426))
- Allow passing a callback to `with()` ([#21445](https://github.com/laravel/framework/pull/21445))
- Added `PotentiallyMissing` interface to `MissingValue` class ([be7dccc](https://github.com/laravel/framework/commit/be7dccca9f9249c928108d957fe70e78d370d26e))
- Accept `$queue` name on `Schedule::job()` ([#21473](https://github.com/laravel/framework/pull/21473))
- Added callback and default parameter `whenLoaded()` method ([#21490](https://github.com/laravel/framework/pull/21490))
- Allow marking notifications as unread ([#21497](https://github.com/laravel/framework/pull/21497))
- Added `Collection::mapToDictionary()` method ([#21505](https://github.com/laravel/framework/pull/21505))
- Added `make:exception` command ([#21483](https://github.com/laravel/framework/pull/21483))

### Changed
- Reset RefreshDatabaseState after DatabaseMigrations rolls back ([#21325](https://github.com/laravel/framework/pull/21325))
Expand All @@ -26,6 +30,7 @@
- Fixed `Collection::contains()` when the found value is `null` ([#21442](https://github.com/laravel/framework/pull/21442))
- Fixed merge issue in `Relation::morphMap()` ([#21458](https://github.com/laravel/framework/pull/21458))
- Clear count query select bindings in `Relation::getRelationExistenceCountQuery()` ([#21468](https://github.com/laravel/framework/pull/21468))
- Fixed user model type hints policy stub ([#21499](https://github.com/laravel/framework/pull/21499))


## v5.5.13 (2017-09-24)
Expand Down
13 changes: 3 additions & 10 deletions src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
Expand Up @@ -162,18 +162,11 @@ protected function getRelationValue(array $dictionary, $key, $type)
*/
protected function buildDictionary(Collection $results)
{
$dictionary = [];

$foreign = $this->getForeignKeyName();

// First we will create a dictionary of models keyed by the foreign key of the
// relationship as this will allow us to quickly access all of the related
// models without having to do nested looping which will be quite slow.
foreach ($results as $result) {
$dictionary[$result->{$foreign}][] = $result;
}

return $dictionary;
return $results->mapToDictionary(function ($result) use ($foreign) {
return [$result->{$foreign} => $result];
})->all();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Expand Up @@ -16,7 +16,7 @@ class PostgresGrammar extends Grammar
protected $operators = [
'=', '<', '>', '<=', '>=', '<>', '!=',
'like', 'not like', 'between', 'ilike',
'&', '|', '#', '<<', '>>',
'&', '|', '#', '<<', '>>', '>>=', '=<<',
'@>', '<@', '?', '?|', '?&', '||', '-', '-', '#-',
];

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Application.php
Expand Up @@ -29,7 +29,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn
*
* @var string
*/
const VERSION = '5.5.13';
const VERSION = '5.5.14';

/**
* The base path for the Laravel installation.
Expand Down
84 changes: 84 additions & 0 deletions src/Illuminate/Foundation/Console/ExceptionMakeCommand.php
@@ -0,0 +1,84 @@
<?php

namespace Illuminate\Foundation\Console;

use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

class ExceptionMakeCommand extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:exception';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new custom exception class';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Exception';

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
if ($this->option('render')) {
return $this->option('report')
? __DIR__.'/stubs/exception-render-report.stub'
: __DIR__.'/stubs/exception-render.stub';
}

return $this->option('report')
? __DIR__.'/stubs/exception-report.stub'
: __DIR__.'/stubs/exception.stub';
}

/**
* Determine if the class already exists.
*
* @param string $rawName
* @return bool
*/
protected function alreadyExists($rawName)
{
return class_exists($this->rootNamespace().'Exceptions\\'.$rawName);
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Exceptions';
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['render', null, InputOption::VALUE_NONE, 'Create the exception with an empty render method.'],

['report', null, InputOption::VALUE_NONE, 'Create the exception with an empty report method.'],
];
}
}
10 changes: 8 additions & 2 deletions src/Illuminate/Foundation/Console/PolicyMakeCommand.php
Expand Up @@ -90,11 +90,17 @@ protected function replaceModel($stub, $model)

$model = class_basename(trim($model, '\\'));

$dummyUser = class_basename(config('auth.providers.users.model'));

$dummyModel = Str::camel($model) === 'user' ? 'model' : Str::camel($model);

$stub = str_replace('DummyModel', $model, $stub);

$stub = str_replace('dummyModel', Str::camel($model), $stub);
$stub = str_replace('dummyModel', $dummyModel, $stub);

$stub = str_replace('DummyUser', $dummyUser, $stub);

return str_replace('dummyPluralModel', Str::plural(Str::camel($model)), $stub);
return str_replace('dummyPluralModel', Str::plural($dummyModel), $stub);
}

/**
Expand Down
@@ -0,0 +1,29 @@
<?php

namespace DummyNamespace;

use Exception;

class DummyClass extends Exception
{
/**
* Report the exception.
*
* @return void
*/
public function report()
{
//
}

/**
* Render the exception as an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function render($request)
{
//
}
}
19 changes: 19 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/exception-render.stub
@@ -0,0 +1,19 @@
<?php

namespace DummyNamespace;

use Exception;

class DummyClass extends Exception
{
/**
* Render the exception as an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function render($request)
{
//
}
}
18 changes: 18 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/exception-report.stub
@@ -0,0 +1,18 @@
<?php

namespace DummyNamespace;

use Exception;

class DummyClass extends Exception
{
/**
* Report the exception.
*
* @return void
*/
public function report()
{
//
}
}
10 changes: 10 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/exception.stub
@@ -0,0 +1,10 @@
<?php

namespace DummyNamespace;

use Exception;

class DummyClass extends Exception
{
//
}
8 changes: 4 additions & 4 deletions src/Illuminate/Foundation/Console/stubs/policy.stub
Expand Up @@ -17,7 +17,7 @@ class DummyClass
* @param \NamespacedDummyModel $dummyModel
* @return mixed
*/
public function view(User $user, DummyModel $dummyModel)
public function view(DummyUser $user, DummyModel $dummyModel)
{
//
}
Expand All @@ -28,7 +28,7 @@ class DummyClass
* @param \NamespacedDummyUserModel $user
* @return mixed
*/
public function create(User $user)
public function create(DummyUser $user)
{
//
}
Expand All @@ -40,7 +40,7 @@ class DummyClass
* @param \NamespacedDummyModel $dummyModel
* @return mixed
*/
public function update(User $user, DummyModel $dummyModel)
public function update(DummyUser $user, DummyModel $dummyModel)
{
//
}
Expand All @@ -52,7 +52,7 @@ class DummyClass
* @param \NamespacedDummyModel $dummyModel
* @return mixed
*/
public function delete(User $user, DummyModel $dummyModel)
public function delete(DummyUser $user, DummyModel $dummyModel)
{
//
}
Expand Down
14 changes: 14 additions & 0 deletions src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php
Expand Up @@ -42,6 +42,7 @@
use Illuminate\Foundation\Console\ResourceMakeCommand;
use Illuminate\Foundation\Console\ClearCompiledCommand;
use Illuminate\Foundation\Console\EventGenerateCommand;
use Illuminate\Foundation\Console\ExceptionMakeCommand;
use Illuminate\Foundation\Console\VendorPublishCommand;
use Illuminate\Console\Scheduling\ScheduleFinishCommand;
use Illuminate\Database\Console\Seeds\SeederMakeCommand;
Expand Down Expand Up @@ -132,6 +133,7 @@ class ArtisanServiceProvider extends ServiceProvider
'ControllerMake' => 'command.controller.make',
'EventGenerate' => 'command.event.generate',
'EventMake' => 'command.event.make',
'ExceptionMake' => 'command.exception.make',
'FactoryMake' => 'command.factory.make',
'JobMake' => 'command.job.make',
'ListenerMake' => 'command.listener.make',
Expand Down Expand Up @@ -338,6 +340,18 @@ protected function registerEventMakeCommand()
});
}

/**
* Register the command.
*
* @return void
*/
protected function registerExceptionMakeCommand()
{
$this->app->singleton('command.exception.make', function ($app) {
return new ExceptionMakeCommand($app['files']);
});
}

/**
* Register the command.
*
Expand Down
20 changes: 17 additions & 3 deletions src/Illuminate/Http/Resources/ConditionallyLoadsAttributes.php
Expand Up @@ -114,15 +114,29 @@ protected function attributes($attributes)
* Retrieve a relationship if it has been loaded.
*
* @param string $relationship
* @param mixed $value
* @param mixed $default
* @return \Illuminate\Http\Resources\MissingValue|mixed
*/
protected function whenLoaded($relationship)
protected function whenLoaded($relationship, $value = null, $default = null)
{
if ($this->resource->relationLoaded($relationship)) {
if (func_num_args() < 3) {
$default = new MissingValue;
}

if (! $this->resource->relationLoaded($relationship)) {
return $default;
}

if (func_num_args() === 1) {
return $this->resource->{$relationship};
}

return new MissingValue;
if ($this->resource->{$relationship} === null) {
return null;
}

return value($value);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/Illuminate/Notifications/DatabaseNotification.php
Expand Up @@ -57,6 +57,18 @@ public function markAsRead()
}
}

/**
* Mark the notification as unread.
*
* @return void
*/
public function markAsUnread()
{
if (! is_null($this->read_at)) {
$this->forceFill(['read_at' => null])->save();
}
}

/**
* Determine if a notification has been read.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Illuminate/Notifications/DatabaseNotificationCollection.php
Expand Up @@ -17,4 +17,16 @@ public function markAsRead()
$notification->markAsRead();
});
}

/**
* Mark all notifications as unread.
*
* @return void
*/
public function markAsUnread()
{
$this->each(function ($notification) {
$notification->markAsUnread();
});
}
}

0 comments on commit 5ce5d96

Please sign in to comment.