Server : nginx/1.20.1 System : Linux iZ2ze9ojcl78uluczwag69Z 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Apr 8 19:01:30 UTC 2021 x86_64 User : www ( 1000) PHP Version : 7.3.28 Disable Function : passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/0531yanglao.com/vendor/topthink/framework/src/think/ |
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006~2021 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: yunwuxin <448901948@qq.com> // +---------------------------------------------------------------------- declare (strict_types = 1); namespace think; use InvalidArgumentException; use think\helper\Str; abstract class Manager { /** @var App */ protected $app; /** * 驱动 * @var array */ protected $drivers = []; /** * 驱动的命名空间 * @var string */ protected $namespace = null; public function __construct(App $app) { $this->app = $app; } /** * 获取驱动实例 * @param null|string $name * @return mixed */ protected function driver(string $name = null) { $name = $name ?: $this->getDefaultDriver(); if (is_null($name)) { throw new InvalidArgumentException(sprintf( 'Unable to resolve NULL driver for [%s].', static::class )); } return $this->drivers[$name] = $this->getDriver($name); } /** * 获取驱动实例 * @param string $name * @return mixed */ protected function getDriver(string $name) { return $this->drivers[$name] ?? $this->createDriver($name); } /** * 获取驱动类型 * @param string $name * @return mixed */ protected function resolveType(string $name) { return $name; } /** * 获取驱动配置 * @param string $name * @return mixed */ protected function resolveConfig(string $name) { return $name; } /** * 获取驱动类 * @param string $type * @return string */ protected function resolveClass(string $type): string { if ($this->namespace || false !== strpos($type, '\\')) { $class = false !== strpos($type, '\\') ? $type : $this->namespace . Str::studly($type); if (class_exists($class)) { return $class; } } throw new InvalidArgumentException("Driver [$type] not supported."); } /** * 获取驱动参数 * @param $name * @return array */ protected function resolveParams($name): array { $config = $this->resolveConfig($name); return [$config]; } /** * 创建驱动 * * @param string $name * @return mixed * */ protected function createDriver(string $name) { $type = $this->resolveType($name); $method = 'create' . Str::studly($type) . 'Driver'; $params = $this->resolveParams($name); if (method_exists($this, $method)) { return $this->$method(...$params); } $class = $this->resolveClass($type); return $this->app->invokeClass($class, $params); } /** * 移除一个驱动实例 * * @param array|string|null $name * @return $this */ public function forgetDriver($name = null) { $name = $name ?? $this->getDefaultDriver(); foreach ((array) $name as $cacheName) { if (isset($this->drivers[$cacheName])) { unset($this->drivers[$cacheName]); } } return $this; } /** * 默认驱动 * @return string|null */ abstract public function getDefaultDriver(); /** * 动态调用 * @param string $method * @param array $parameters * @return mixed */ public function __call($method, $parameters) { return $this->driver()->$method(...$parameters); } }