File tree Expand file tree Collapse file tree 3 files changed +44
-2
lines changed
Expand file tree Collapse file tree 3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 99use DirectoryTree \ImapEngine \Connection \Tokens \Atom ;
1010use DirectoryTree \ImapEngine \Enums \ImapFetchIdentifier ;
1111use DirectoryTree \ImapEngine \Pagination \LengthAwarePaginator ;
12+ use DirectoryTree \ImapEngine \Support \ForwardsCalls ;
1213use DirectoryTree \ImapEngine \Support \Str ;
1314use Illuminate \Support \Collection ;
1415use Illuminate \Support \Traits \Conditionable ;
15- use Illuminate \Support \Traits \ForwardsCalls ;
1616
1717/**
1818 * @mixin \DirectoryTree\ImapEngine\Connection\ImapQueryBuilder
Original file line number Diff line number Diff line change 22
33namespace DirectoryTree \ImapEngine \Pagination ;
44
5+ use DirectoryTree \ImapEngine \Support \ForwardsCalls ;
56use Illuminate \Contracts \Support \Arrayable ;
67use Illuminate \Support \Collection ;
7- use Illuminate \Support \Traits \ForwardsCalls ;
88use JsonSerializable ;
99
1010class LengthAwarePaginator implements Arrayable, JsonSerializable
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments