Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit d3674c8

Browse files
committed
Clone ForwardsCalls trait locally for Laravel 5.5/5.6 support
Closes #872
1 parent fe13cb4 commit d3674c8

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/Auth/DatabaseUserProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Illuminate\Support\Facades\Bus;
1818
use Illuminate\Support\Facades\Config;
1919
use Illuminate\Support\Facades\Event;
20-
use Illuminate\Support\Traits\ForwardsCalls;
2120

2221
/** @mixin EloquentUserProvider */
2322
class DatabaseUserProvider extends UserProvider

src/Auth/ForwardsCalls.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Adldap\Laravel\Auth;
4+
5+
use Error;
6+
use BadMethodCallException;
7+
8+
trait ForwardsCalls
9+
{
10+
/**
11+
* Forward a method call to the given object.
12+
*
13+
* @param mixed $object
14+
* @param string $method
15+
* @param array $parameters
16+
*
17+
* @throws BadMethodCallException
18+
*
19+
* @return mixed
20+
*/
21+
protected function forwardCallTo($object, $method, $parameters)
22+
{
23+
try {
24+
return $object->{$method}(...$parameters);
25+
} catch (Error | BadMethodCallException $e) {
26+
$pattern = '~^Call to undefined method (?P<class>[^:]+)::(?P<method>[^\(]+)\(\)$~';
27+
28+
if (! preg_match($pattern, $e->getMessage(), $matches)) {
29+
throw $e;
30+
}
31+
32+
if ($matches['class'] != get_class($object) ||
33+
$matches['method'] != $method) {
34+
throw $e;
35+
}
36+
37+
static::throwBadMethodCallException($method);
38+
}
39+
}
40+
41+
/**
42+
* Throw a bad method call exception for the given method.
43+
*
44+
* @param string $method
45+
*
46+
* @throws BadMethodCallException
47+
*
48+
* @return void
49+
*/
50+
protected static function throwBadMethodCallException($method)
51+
{
52+
throw new BadMethodCallException(sprintf(
53+
'Call to undefined method %s::%s()', static::class, $method
54+
));
55+
}
56+
}

0 commit comments

Comments
 (0)