init
- 框架初始化 - 安装插件 - 修复PHP8.4报错
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Service;
|
||||
|
||||
use Yansongda\Pay\Contract\ServiceProviderInterface;
|
||||
use Yansongda\Pay\Exception\ContainerException;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Provider\Alipay;
|
||||
|
||||
class AlipayServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws ContainerException
|
||||
*/
|
||||
public function register($data = null): void
|
||||
{
|
||||
$service = new Alipay();
|
||||
|
||||
Pay::set(Alipay::class, $service);
|
||||
Pay::set('alipay', $service);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Service;
|
||||
|
||||
use Yansongda\Pay\Contract\ConfigInterface;
|
||||
use Yansongda\Pay\Contract\ServiceProviderInterface;
|
||||
use Yansongda\Pay\Exception\ContainerException;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Supports\Config;
|
||||
|
||||
class ConfigServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
private array $config = [
|
||||
'logger' => [
|
||||
'enable' => false,
|
||||
'file' => null,
|
||||
'identify' => 'yansongda.pay',
|
||||
'level' => 'debug',
|
||||
'type' => 'daily',
|
||||
'max_files' => 30,
|
||||
],
|
||||
'http' => [
|
||||
'timeout' => 5.0,
|
||||
'connect_timeout' => 3.0,
|
||||
'headers' => [
|
||||
'User-Agent' => 'yansongda/pay-v3',
|
||||
],
|
||||
],
|
||||
'mode' => Pay::MODE_NORMAL,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws ContainerException
|
||||
*/
|
||||
public function register($data = null): void
|
||||
{
|
||||
$config = new Config(array_replace_recursive($this->config, $data ?? []));
|
||||
|
||||
Pay::set(ConfigInterface::class, $config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Service;
|
||||
|
||||
use Closure;
|
||||
use Hyperf\Pimple\ContainerFactory as DefaultContainer;
|
||||
use Hyperf\Utils\ApplicationContext as HyperfContainer;
|
||||
use Illuminate\Container\Container as LaravelContainer;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Yansongda\Pay\Contract\ServiceProviderInterface;
|
||||
use Yansongda\Pay\Exception\ContainerException;
|
||||
use Yansongda\Pay\Exception\ContainerNotFoundException;
|
||||
use Yansongda\Pay\Exception\Exception;
|
||||
use Yansongda\Pay\Pay;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class ContainerServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
private array $detectApplication = [
|
||||
'laravel' => LaravelContainer::class,
|
||||
'hyperf' => HyperfContainer::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws ContainerException
|
||||
*/
|
||||
public function register($data = null): void
|
||||
{
|
||||
if ($data instanceof ContainerInterface || $data instanceof Closure) {
|
||||
Pay::setContainer($data);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Pay::hasContainer()) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->detectApplication as $framework => $application) {
|
||||
$method = $framework.'Application';
|
||||
|
||||
if (class_exists($application) && method_exists($this, $method) && $this->{$method}()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->defaultApplication();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws ContainerNotFoundException
|
||||
*/
|
||||
protected function laravelApplication(): bool
|
||||
{
|
||||
Pay::setContainer(static fn () => LaravelContainer::getInstance());
|
||||
|
||||
Pay::set(\Yansongda\Pay\Contract\ContainerInterface::class, LaravelContainer::getInstance());
|
||||
|
||||
if (!Pay::has(ContainerInterface::class)) {
|
||||
Pay::set(ContainerInterface::class, LaravelContainer::getInstance());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws ContainerNotFoundException
|
||||
*/
|
||||
protected function hyperfApplication(): bool
|
||||
{
|
||||
if (!HyperfContainer::hasContainer()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Pay::setContainer(static fn () => HyperfContainer::getContainer());
|
||||
|
||||
Pay::set(\Yansongda\Pay\Contract\ContainerInterface::class, HyperfContainer::getContainer());
|
||||
|
||||
if (!Pay::has(ContainerInterface::class)) {
|
||||
Pay::set(ContainerInterface::class, HyperfContainer::getContainer());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerNotFoundException
|
||||
*/
|
||||
protected function defaultApplication(): void
|
||||
{
|
||||
if (!class_exists(DefaultContainer::class)) {
|
||||
throw new ContainerNotFoundException('Init failed! Maybe you should install `hyperf/pimple` first', Exception::CONTAINER_NOT_FOUND);
|
||||
}
|
||||
|
||||
$container = (new DefaultContainer())();
|
||||
|
||||
Pay::setContainer($container);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Service;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Yansongda\Pay\Contract\EventDispatcherInterface;
|
||||
use Yansongda\Pay\Contract\ServiceProviderInterface;
|
||||
use Yansongda\Pay\Exception\ContainerException;
|
||||
use Yansongda\Pay\Pay;
|
||||
|
||||
class EventServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws ContainerException
|
||||
*/
|
||||
public function register($data = null): void
|
||||
{
|
||||
if (class_exists(EventDispatcher::class)) {
|
||||
Pay::set(EventDispatcherInterface::class, new EventDispatcher());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Service;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Yansongda\Pay\Contract\ConfigInterface;
|
||||
use Yansongda\Pay\Contract\HttpClientInterface;
|
||||
use Yansongda\Pay\Contract\ServiceProviderInterface;
|
||||
use Yansongda\Pay\Exception\ContainerException;
|
||||
use Yansongda\Pay\Exception\ServiceNotFoundException;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Supports\Config;
|
||||
|
||||
class HttpServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws ContainerException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function register($data = null): void
|
||||
{
|
||||
/* @var Config $config */
|
||||
$config = Pay::get(ConfigInterface::class);
|
||||
|
||||
if (class_exists(Client::class)) {
|
||||
$service = new Client($config->get('http', []));
|
||||
|
||||
Pay::set(HttpClientInterface::class, $service);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Service;
|
||||
|
||||
use Yansongda\Pay\Contract\ConfigInterface;
|
||||
use Yansongda\Pay\Contract\LoggerInterface;
|
||||
use Yansongda\Pay\Contract\ServiceProviderInterface;
|
||||
use Yansongda\Pay\Exception\ContainerException;
|
||||
use Yansongda\Pay\Exception\ServiceNotFoundException;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Supports\Logger;
|
||||
|
||||
class LoggerServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws ContainerException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function register($data = null): void
|
||||
{
|
||||
/* @var ConfigInterface $config */
|
||||
$config = Pay::get(ConfigInterface::class);
|
||||
|
||||
if (class_exists(\Monolog\Logger::class) && true === $config->get('logger.enable', false)) {
|
||||
$logger = new Logger(array_merge(
|
||||
['identify' => 'yansongda.pay'],
|
||||
$config->get('logger', [])
|
||||
));
|
||||
|
||||
Pay::set(LoggerInterface::class, $logger);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Service;
|
||||
|
||||
use Yansongda\Pay\Contract\ServiceProviderInterface;
|
||||
use Yansongda\Pay\Exception\ContainerException;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Provider\Unipay;
|
||||
|
||||
class UnipayServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws ContainerException
|
||||
*/
|
||||
public function register($data = null): void
|
||||
{
|
||||
$service = new Unipay();
|
||||
|
||||
Pay::set(Unipay::class, $service);
|
||||
Pay::set('unipay', $service);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Service;
|
||||
|
||||
use Yansongda\Pay\Contract\ServiceProviderInterface;
|
||||
use Yansongda\Pay\Exception\ContainerException;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Provider\Wechat;
|
||||
|
||||
class WechatServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @throws ContainerException
|
||||
*/
|
||||
public function register($data = null): void
|
||||
{
|
||||
$service = new Wechat();
|
||||
|
||||
Pay::set(Wechat::class, $service);
|
||||
Pay::set('wechat', $service);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user