Skip to content

Commit 796463e

Browse files
committed
Replace ForwardsCalls with local version
1 parent 614617a commit 796463e

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/MessageQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
1010
use DirectoryTree\ImapEngine\Enums\ImapFetchIdentifier;
1111
use DirectoryTree\ImapEngine\Pagination\LengthAwarePaginator;
12+
use DirectoryTree\ImapEngine\Support\ForwardsCalls;
1213
use DirectoryTree\ImapEngine\Support\Str;
1314
use Illuminate\Support\Collection;
1415
use Illuminate\Support\Traits\Conditionable;
15-
use Illuminate\Support\Traits\ForwardsCalls;
1616

1717
/**
1818
* @mixin \DirectoryTree\ImapEngine\Connection\ImapQueryBuilder

src/Pagination/LengthAwarePaginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace DirectoryTree\ImapEngine\Pagination;
44

5+
use DirectoryTree\ImapEngine\Support\ForwardsCalls;
56
use Illuminate\Contracts\Support\Arrayable;
67
use Illuminate\Support\Collection;
7-
use Illuminate\Support\Traits\ForwardsCalls;
88
use JsonSerializable;
99

1010
class LengthAwarePaginator implements Arrayable, JsonSerializable

src/Support/ForwardsCalls.php

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

0 commit comments

Comments
 (0)