Skip to content

Commit

Permalink
Merge branch 'master' of github.com:laravel/framework
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jul 13, 2017
2 parents d58be04 + 1e4f189 commit f111352
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Console/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ protected function buildClass($name)
protected function replaceNamespace(&$stub, $name)
{
$stub = str_replace(
['DummyNamespace', 'DummyRootNamespace'],
[$this->getNamespace($name), $this->rootNamespace()],
['DummyNamespace', 'DummyRootNamespace', 'NamespacedDummyUserModel'],
[$this->getNamespace($name), $this->rootNamespace(), config('auth.providers.users.model')],
$stub
);

Expand Down
16 changes: 7 additions & 9 deletions src/Illuminate/Database/Eloquent/Relations/MorphOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,14 @@ public function save(Model $model)
*/
public function create(array $attributes = [])
{
$instance = $this->related->newInstance($attributes);

// When saving a polymorphic relationship, we need to set not only the foreign
// key, but also the foreign key type, which is typically the class name of
// the parent model. This makes the polymorphic item unique in the table.
$this->setForeignAttributesForCreate($instance);

$instance->save();
return tap($this->related->newInstance($attributes), function ($instance) {
// When saving a polymorphic relationship, we need to set not only the foreign
// key, but also the foreign key type, which is typically the class name of
// the parent model. This makes the polymorphic item unique in the table.
$this->setForeignAttributesForCreate($instance);

return $instance;
$instance->save();
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Relations/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public function __call($method, $parameters)
return $this->macroCall($method, $parameters);
}

$result = call_user_func_array([$this->query, $method], $parameters);
$result = $this->query->{$method}(...$parameters);

if ($result === $this->query) {
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/stubs/policy.plain.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace DummyNamespace;

use DummyRootNamespaceUser;
use NamespacedDummyUserModel;
use Illuminate\Auth\Access\HandlesAuthorization;

class DummyClass
Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Foundation/Console/stubs/policy.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace DummyNamespace;

use DummyRootNamespaceUser;
use NamespacedDummyUserModel;
use NamespacedDummyModel;
use Illuminate\Auth\Access\HandlesAuthorization;

Expand All @@ -13,7 +13,7 @@ class DummyClass
/**
* Determine whether the user can view the dummyModel.
*
* @param \DummyRootNamespaceUser $user
* @param \NamespacedDummyUserModel $user
* @param \NamespacedDummyModel $dummyModel
* @return mixed
*/
Expand All @@ -25,7 +25,7 @@ class DummyClass
/**
* Determine whether the user can create dummyPluralModel.
*
* @param \DummyRootNamespaceUser $user
* @param \NamespacedDummyUserModel $user
* @return mixed
*/
public function create(User $user)
Expand All @@ -36,7 +36,7 @@ class DummyClass
/**
* Determine whether the user can update the dummyModel.
*
* @param \DummyRootNamespaceUser $user
* @param \NamespacedDummyUserModel $user
* @param \NamespacedDummyModel $dummyModel
* @return mixed
*/
Expand All @@ -48,7 +48,7 @@ class DummyClass
/**
* Determine whether the user can delete the dummyModel.
*
* @param \DummyRootNamespaceUser $user
* @param \NamespacedDummyUserModel $user
* @param \NamespacedDummyModel $dummyModel
* @return mixed
*/
Expand Down
27 changes: 27 additions & 0 deletions src/Illuminate/Routing/Contracts/ControllerDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Illuminate\Routing\Contracts;

use Illuminate\Routing\Route;

interface ControllerDispatcher
{
/**
* Dispatch a request to a given controller and method.
*
* @param Route $route
* @param mixed $controller
* @param string $method
* @return mixed
*/
public function dispatch(Route $route, $controller, $method);

/**
* Get the middleware for the controller instance.
*
* @param \Illuminate\Routing\Controller $controller
* @param string $method
* @return array
*/
public function getMiddleware($controller, $method);
}
5 changes: 3 additions & 2 deletions src/Illuminate/Routing/ControllerDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Illuminate\Routing;

use Illuminate\Container\Container;
use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract;

class ControllerDispatcher
class ControllerDispatcher implements ControllerDispatcherContract
{
use RouteDependencyResolverTrait;

Expand Down Expand Up @@ -54,7 +55,7 @@ public function dispatch(Route $route, $controller, $method)
* @param string $method
* @return array
*/
public static function getMiddleware($controller, $method)
public function getMiddleware($controller, $method)
{
if (! method_exists($controller, 'getMiddleware')) {
return [];
Expand Down
19 changes: 17 additions & 2 deletions src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Routing\Matching\MethodValidator;
use Illuminate\Routing\Matching\SchemeValidator;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract;

class Route
{
Expand Down Expand Up @@ -199,7 +200,7 @@ protected function runCallable()
*/
protected function runController()
{
return (new ControllerDispatcher($this->container))->dispatch(
return $this->controllerDispatcher()->dispatch(
$this, $this->getController(), $this->getControllerMethod()
);
}
Expand Down Expand Up @@ -770,11 +771,25 @@ public function controllerMiddleware()
return [];
}

return ControllerDispatcher::getMiddleware(
return $this->controllerDispatcher()->getMiddleware(
$this->getController(), $this->getControllerMethod()
);
}

/**
* Get the dispatcher for the route's controller.
*
* @return ControllerDispatcherContract
*/
public function controllerDispatcher()
{
if ($this->container->bound(ControllerDispatcherContract::class)) {
return $this->container->make(ControllerDispatcherContract::class);
}

return new ControllerDispatcher($this->container);
}

/**
* Get the route validators for the instance.
*
Expand Down
15 changes: 15 additions & 0 deletions src/Illuminate/Routing/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Illuminate\Contracts\View\Factory as ViewFactoryContract;
use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract;
use Illuminate\Routing\Contracts\ControllerDispatcher as ControllerDispatcherContract;

class RoutingServiceProvider extends ServiceProvider
{
Expand All @@ -30,6 +31,8 @@ public function register()
$this->registerPsrResponse();

$this->registerResponseFactory();

$this->registerControllerDispatcher();
}

/**
Expand Down Expand Up @@ -148,4 +151,16 @@ protected function registerResponseFactory()
return new ResponseFactory($app[ViewFactoryContract::class], $app['redirect']);
});
}

/**
* Register the controller dispatcher.
*
* @return void
*/
protected function registerControllerDispatcher()
{
$this->app->singleton(ControllerDispatcherContract::class, function ($app) {
return new ControllerDispatcher($app);
});
}
}
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Str
*/
public static function after($subject, $search)
{
return $search == '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
}

/**
Expand Down Expand Up @@ -72,7 +72,7 @@ public static function ascii($value, $language = 'en')
*/
public static function before($subject, $search)
{
return $search == '' ? $subject : explode($search, $subject)[0];
return $search === '' ? $subject : explode($search, $subject)[0];
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public function testStrBefore()
$this->assertEquals('hannah', Str::before('hannah', 'xxxx'));
$this->assertEquals('hannah', Str::before('hannah', ''));
$this->assertEquals('han', Str::before('han0nah', '0'));
$this->assertEquals('han', Str::before('han0nah', 0));
$this->assertEquals('han', Str::before('han2nah', 2));
}

public function testStrAfter()
Expand All @@ -106,6 +108,8 @@ public function testStrAfter()
$this->assertEquals('hannah', Str::after('hannah', 'xxxx'));
$this->assertEquals('hannah', Str::after('hannah', ''));
$this->assertEquals('nah', Str::after('han0nah', '0'));
$this->assertEquals('nah', Str::after('han0nah', 0));
$this->assertEquals('nah', Str::after('han2nah', 2));
}

public function testStrContains()
Expand Down

0 comments on commit f111352

Please sign in to comment.