Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/6.x' into phpstorm_fixes
Browse files Browse the repository at this point in the history
* upstream/6.x: (21 commits)
  Revert "[6.x] migrate --seed should seed the same database (laravel#31678)" (laravel#31685)
  [6.x] Allow easier customization of the queued mailable job (laravel#31684)
  [6.x] migrate --seed should seed the same database (laravel#31678)
  [6.x] Make newPivotQuery public (laravel#31677)
  [6.x] update changelog
  Fix flakey memcached tests (laravel#31646)
  Fixed phpdoc
  formatting
  [6.x] Expose Notification Id within Message Data (laravel#31632)
  [6.x] Add support for Arr::hasAny (laravel#31636)
  Fix phpdoc
  [6.x] update changelog
  [6.x] update changelog
  Fix styling for phpdoc
  Create resolve method which loads deferred providers if needed
  Revert "Call make instead of resolve to load deffered providers"
  Call make instead of resolve to load deffered providers
  Add test that failes to load deffered provider of implementation while accessing class through interface
  Use correct locale when resolving Faker from the container (laravel#31615)
  clean-up-some-methods
  ...

# Conflicts:
#	src/Illuminate/Database/DatabaseServiceProvider.php
  • Loading branch information
voku committed Mar 2, 2020
2 parents 1430fca + bad08c4 commit 969c370
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 29 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG-6.x.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Release Notes for 6.x

## [Unreleased](https://github.com/laravel/framework/compare/v6.17.0...6.x)
## [Unreleased](https://github.com/laravel/framework/compare/v6.17.1...6.x)

### Added
- Added `Arr::hasAny()` method ([#31636](https://github.com/laravel/framework/pull/31636))

### TODO
- Use correct locale when resolving Faker from the container ([#31615](https://github.com/laravel/framework/pull/31615))
- Expose Notification Id within Message Data ([#31632](https://github.com/laravel/framework/pull/31632))
- Fixed loading deferred providers for binding interfaces and implementations ([#31629](https://github.com/laravel/framework/pull/31629), [1764ff7](https://github.com/laravel/framework/commit/1764ff762966083a12dd2c9b522cec5f1bbda967))


## [v6.17.1 (2020-02-26)](https://github.com/laravel/framework/compare/v6.17.0...v6.17.1)

### Changed
- Don`t do chmod in File cache in case if permission not set ([#31593](https://github.com/laravel/framework/pull/31593))


## [v6.17.0 (2020-02-25)](https://github.com/laravel/framework/compare/v6.16.0...v6.17.0)
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/DatabaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ protected function registerConnectionServices()
*/
protected function registerEloquentFactory()
{
$this->app->singleton(FakerGenerator::class, static function ($app) {
return FakerFactory::create($app['config']->get('app.faker_locale', 'en_US'));
$this->app->singleton(FakerGenerator::class, static function ($app, $parameters) {
return FakerFactory::create($parameters['locale'] ?? $app['config']->get('app.faker_locale', 'en_US'));
});

$this->app->singleton(EloquentFactory::class, function ($app) {
$this->app->singleton(EloquentFactory::class, static function ($app) {
/** @var \Illuminate\Contracts\Foundation\Application $app */
return EloquentFactory::construct(
$app->make(FakerGenerator::class), $this->app->databasePath('factories')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public function newPivotStatementForId($id)
*
* @return \Illuminate\Database\Query\Builder
*/
protected function newPivotQuery()
public function newPivotQuery()
{
$query = $this->newPivotStatement();

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Relations/MorphToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery,
*
* @return \Illuminate\Database\Query\Builder
*/
protected function newPivotQuery()
public function newPivotQuery()
{
return parent::newPivotQuery()->where($this->morphType, $this->morphClass);
}
Expand Down
34 changes: 27 additions & 7 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -759,28 +759,48 @@ public function registerDeferredProvider($provider, $service = null)
/**
* Resolve the given type from the container.
*
* (Overriding Container::make)
*
* @param string $abstract
* @param array $parameters
* @return mixed
*/
public function make($abstract, array $parameters = [])
{
$abstract = $this->getAlias($abstract);
$this->loadDeferredProviderIfNeeded($abstract = $this->getAlias($abstract));

return parent::make($abstract, $parameters);
}

/**
* Resolve the given type from the container.
*
* @param string $abstract
* @param array $parameters
* @param bool $raiseEvents
* @return mixed
*/
protected function resolve($abstract, $parameters = [], $raiseEvents = true)
{
$this->loadDeferredProviderIfNeeded($abstract = $this->getAlias($abstract));

return parent::resolve($abstract, $parameters, $raiseEvents);
}

/**
* Load the deferred provider if the given type is a deferred service and the instance has not been loaded.
*
* @param string $abstract
* @return void
*/
protected function loadDeferredProviderIfNeeded($abstract)
{
if ($this->isDeferredService($abstract) && ! isset($this->instances[$abstract])) {
$this->loadDeferredProvider($abstract);
}

return parent::make($abstract, $parameters);
}

/**
* Determine if the given abstract type has been bound.
*
* (Overriding Container::bound)
*
* @param string $abstract
* @return bool
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Testing/WithFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function makeFaker($locale = null)
$locale = $locale ?? config('app.faker_locale', Factory::DEFAULT_LOCALE);

if (isset($this->app) && $this->app->bound(Generator::class)) {
return $this->app->make(Generator::class, [$locale]);
return $this->app->make(Generator::class, ['locale' => $locale]);
}

return Factory::create($locale);
Expand Down
8 changes: 1 addition & 7 deletions src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,7 @@ public function hasAny($keys)

$input = $this->all();

foreach ($keys as $key) {
if (Arr::has($input, $key)) {
return true;
}
}

return false;
return Arr::hasAny($input, $keys);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function queue(Queue $queue)
$queueName = property_exists($this, 'queue') ? $this->queue : null;

return $queue->connection($connection)->pushOn(
$queueName ?: null, new SendQueuedMailable($this)
$queueName ?: null, $this->newQueuedJob()
);
}

Expand All @@ -196,10 +196,20 @@ public function later($delay, Queue $queue)
$queueName = property_exists($this, 'queue') ? $this->queue : null;

return $queue->connection($connection)->laterOn(
$queueName ?: null, $delay, new SendQueuedMailable($this)
$queueName ?: null, $delay, $this->newQueuedJob()
);
}

/**
* Make the queued mailable job instance.
*
* @return mixed
*/
protected function newQueuedJob()
{
return new SendQueuedMailable($this);
}

/**
* Render the mailable into a view.
*
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Notifications/Channels/MailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected function buildView($message)
protected function additionalMessageData($notification)
{
return [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
'__laravel_notification_queued' => in_array(
ShouldQueue::class, class_implements($notification)
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function group(array $attributes, $routes)
*/
protected function updateGroupStack(array $attributes)
{
if (! empty($this->groupStack)) {
if ($this->hasGroupStack()) {
$attributes = $this->mergeWithLastGroup($attributes);
}

Expand Down Expand Up @@ -424,7 +424,7 @@ protected function loadRoutes($routes)
*/
public function getLastGroupPrefix()
{
if (! empty($this->groupStack)) {
if ($this->hasGroupStack()) {
$last = end($this->groupStack);

return $last['prefix'] ?? '';
Expand Down Expand Up @@ -509,7 +509,7 @@ protected function convertToControllerAction($action)
// Here we'll merge any group "uses" statement if necessary so that the action
// has the proper clause for this property. Then we can simply set the name
// of the controller on the action and return the action array for usage.
if (! empty($this->groupStack)) {
if ($this->hasGroupStack()) {
$action['uses'] = $this->prependGroupNamespace($action['uses']);
}

Expand Down
32 changes: 32 additions & 0 deletions src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,38 @@ public static function has($array, $keys)
return true;
}

/**
* Determine if any of the keys exist in an array using "dot" notation.
*
* @param \ArrayAccess|array $array
* @param string|array $keys
* @return bool
*/
public static function hasAny($array, $keys)
{
if (is_null($keys)) {
return false;
}

$keys = (array) $keys;

if (! $array) {
return false;
}

if ($keys === []) {
return false;
}

foreach ($keys as $key) {
if (static::has($array, $key)) {
return true;
}
}

return false;
}

/**
* Determines if an array is associative.
*
Expand Down
49 changes: 49 additions & 0 deletions tests/Foundation/FoundationApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ public function testSingleProviderCanProvideMultipleDeferredServices()
$this->assertSame('foobar', $app->make('bar'));
}

public function testDeferredServiceIsLoadedWhenAccessingImplementationThroughInterface()
{
$app = new Application;
$app->setDeferredServices([
SampleInterface::class => InterfaceToImplementationDeferredServiceProvider::class,
SampleImplementation::class => SampleImplementationDeferredServiceProvider::class,
]);
$instance = $app->make(SampleInterface::class);
$this->assertEquals($instance->getPrimitive(), 'foo');
}

public function testEnvironment()
{
$app = new Application;
Expand Down Expand Up @@ -473,6 +484,44 @@ public function register()
}
}

interface SampleInterface
{
public function getPrimitive();
}

class SampleImplementation implements SampleInterface
{
private $primitive;

public function __construct($primitive)
{
$this->primitive = $primitive;
}

public function getPrimitive()
{
return $this->primitive;
}
}

class InterfaceToImplementationDeferredServiceProvider extends ServiceProvider implements DeferrableProvider
{
public function register()
{
$this->app->bind(SampleInterface::class, SampleImplementation::class);
}
}

class SampleImplementationDeferredServiceProvider extends ServiceProvider implements DeferrableProvider
{
public function register()
{
$this->app->when(SampleImplementation::class)->needs('$primitive')->give(function () {
return 'foo';
});
}
}

class ApplicationFactoryProviderStub extends ServiceProvider implements DeferrableProvider
{
public function register()
Expand Down
6 changes: 3 additions & 3 deletions tests/Integration/Cache/MemcachedTaggedCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public function testMemcachedCanStoreAndRetrieveTaggedCacheItems()
{
$store = Cache::store('memcached');

$store->tags(['people', 'artists'])->put('John', 'foo', 1);
$store->tags(['people', 'authors'])->put('Anne', 'bar', 1);
$store->tags(['people', 'artists'])->put('John', 'foo', 2);
$store->tags(['people', 'authors'])->put('Anne', 'bar', 2);

$this->assertSame('foo', $store->tags(['people', 'artists'])->get('John'));
$this->assertSame('bar', $store->tags(['people', 'authors'])->get('Anne'));
Expand All @@ -36,7 +36,7 @@ public function testMemcachedCanStoreManyTaggedCacheItems()
{
$store = Cache::store('memcached');

$store->tags(['people', 'artists'])->putMany(['John' => 'foo', 'Jane' => 'bar'], 1);
$store->tags(['people', 'artists'])->putMany(['John' => 'foo', 'Jane' => 'bar'], 2);

$this->assertSame('foo', $store->tags(['people', 'artists'])->get('John'));
$this->assertSame('bar', $store->tags(['people', 'artists'])->get('Jane'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Notifications\Notifiable;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
use Mockery as m;
use Orchestra\Testbench\TestCase;

Expand Down Expand Up @@ -69,6 +70,7 @@ protected function setUp(): void
public function testMailIsSent()
{
$notification = new TestMailNotification;
$notification->id = Str::uuid()->toString();

$user = NotifiableUser::forceCreate([
'email' => '[email protected]',
Expand All @@ -80,6 +82,7 @@ public function testMailIsSent()
$this->mailer->shouldReceive('send')->once()->with(
['html' => 'htmlContent', 'text' => 'textContent'],
array_merge($notification->toMail($user)->toArray(), [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
'__laravel_notification_queued' => false,
]),
Expand Down Expand Up @@ -112,6 +115,7 @@ public function testMailIsSent()
public function testMailIsSentToNamedAddress()
{
$notification = new TestMailNotification;
$notification->id = Str::uuid()->toString();

$user = NotifiableUserWithNamedAddress::forceCreate([
'email' => '[email protected]',
Expand All @@ -124,6 +128,7 @@ public function testMailIsSentToNamedAddress()
$this->mailer->shouldReceive('send')->once()->with(
['html' => 'htmlContent', 'text' => 'textContent'],
array_merge($notification->toMail($user)->toArray(), [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
'__laravel_notification_queued' => false,
]),
Expand Down Expand Up @@ -156,6 +161,7 @@ public function testMailIsSentToNamedAddress()
public function testMailIsSentWithSubject()
{
$notification = new TestMailNotificationWithSubject;
$notification->id = Str::uuid()->toString();

$user = NotifiableUser::forceCreate([
'email' => '[email protected]',
Expand All @@ -167,6 +173,7 @@ public function testMailIsSentWithSubject()
$this->mailer->shouldReceive('send')->once()->with(
['html' => 'htmlContent', 'text' => 'textContent'],
array_merge($notification->toMail($user)->toArray(), [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
'__laravel_notification_queued' => false,
]),
Expand All @@ -189,6 +196,7 @@ public function testMailIsSentWithSubject()
public function testMailIsSentToMultipleAdresses()
{
$notification = new TestMailNotificationWithSubject;
$notification->id = Str::uuid()->toString();

$user = NotifiableUserWithMultipleAddreses::forceCreate([
'email' => '[email protected]',
Expand All @@ -200,6 +208,7 @@ public function testMailIsSentToMultipleAdresses()
$this->mailer->shouldReceive('send')->once()->with(
['html' => 'htmlContent', 'text' => 'textContent'],
array_merge($notification->toMail($user)->toArray(), [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
'__laravel_notification_queued' => false,
]),
Expand Down
Loading

0 comments on commit 969c370

Please sign in to comment.