PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.6.01
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.6.01
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / vendor / wpfluent / framework / src / WPFluent / Database / DatabaseManager.php

DatabaseManager.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.6.01, at vendor/wpfluent/framework/src/WPFluent/Database/DatabaseManager.php

54 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Framework\Database;
4
5 use BadMethodCallException;
6 use FluentCommunity\Framework\Support\Arr;
7
8 class DatabaseManager
9 {
10 protected $resolver;
11
12 public function __construct(ConnectionResolver $resolver)
13 {
14 $this->resolver = $resolver;
15 }
16
17 public function connection($name = null)
18 {
19 return $this->resolver->connection($name);
20 }
21
22 protected function suggestMethod($connection, $method)
23 {
24 $methods = get_class_methods($connection);
25
26 return Arr::findSimilar($method, $methods);
27 }
28
29 protected function throwBadMethodCallException($connection, $method)
30 {
31 $message = sprintf(
32 "Call to undefined method %s::%s.",
33 get_class($connection), $method
34 );
35
36 if ($suggested = $this->suggestMethod($connection, $method)) {
37 $message .= sprintf(" Did you mean '%s'?", $suggested);
38 }
39
40 throw new BadMethodCallException($message);
41 }
42
43 public function __call($method, $args)
44 {
45 $connection = $this->connection();
46
47 if (method_exists($connection, $method)) {
48 return $connection->$method(...$args);
49 }
50
51 $this->throwBadMethodCallException($connection, $method);
52 }
53 }
54