Skip to content

Commit

Permalink
formatting and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 2, 2020
1 parent 943b23c commit 28fa74e
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1375,21 +1375,7 @@ public static function __callStatic($method, $parameters)
}

if ($method === 'mixin') {
$mixin = $parameters[0];
$replace = $parameters[1] ?? true;

$methods = (new ReflectionClass($mixin))->getMethods(
ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED
);

foreach ($methods as $method) {
if ($replace || ! static::hasMacro($method->name)) {
$method->setAccessible(true);
static::macro($method->name, $method->invoke($mixin));
}
}

return;
return static::registerMixin($parameters[0], $parameters[1] ?? true);
}

if (! static::hasGlobalMacro($method)) {
Expand All @@ -1403,6 +1389,28 @@ public static function __callStatic($method, $parameters)
return call_user_func_array(static::$macros[$method], $parameters);
}

/**
* Register the given mixin with the builder.
*
* @param string $mixin
* @param bool $replace
* @return void
*/
protected static function registerMixin($mixin, $replace)
{
$methods = (new ReflectionClass($mixin))->getMethods(
ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED
);

foreach ($methods as $method) {
if ($replace || ! static::hasGlobalMacro($method->name)) {
$method->setAccessible(true);

static::macro($method->name, $method->invoke($mixin));
}
}
}

/**
* Force a clone of the underlying query builder when cloning.
*
Expand Down

0 comments on commit 28fa74e

Please sign in to comment.