mirror of
https://gitee.com/yansongda/pay.git
synced 2024-12-02 04:08:21 +08:00
update
This commit is contained in:
parent
06358c970d
commit
bb7acd000b
@ -4,10 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Exception;
|
||||
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Throwable;
|
||||
|
||||
class ContainerNotFoundException extends ContainerException implements NotFoundExceptionInterface
|
||||
class ContainerNotFoundException extends ContainerException
|
||||
{
|
||||
/**
|
||||
* Bootstrap.
|
||||
|
@ -4,9 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Exception;
|
||||
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Throwable;
|
||||
|
||||
class ServiceNotFoundException extends Exception
|
||||
class ServiceNotFoundException extends Exception implements NotFoundExceptionInterface
|
||||
{
|
||||
/**
|
||||
* Bootstrap.
|
||||
|
24
src/Pay.php
24
src/Pay.php
@ -85,7 +85,7 @@ class Pay
|
||||
private function __construct(array $config)
|
||||
{
|
||||
$this->initContainer();
|
||||
$this->registerService($config);
|
||||
$this->registerServices($config);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,6 +152,19 @@ class Pay
|
||||
return self::$container instanceof Container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author yansongda <me@yansongda.cn>
|
||||
*/
|
||||
public static function registerService(string $service, array $config)
|
||||
{
|
||||
$var = self::get($service);
|
||||
|
||||
if ($var instanceof ServiceProviderInterface) {
|
||||
$var->prepare($config);
|
||||
$var->register(self::get(Pay::class));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* clear.
|
||||
*
|
||||
@ -190,15 +203,10 @@ class Pay
|
||||
*
|
||||
* @author yansongda <me@yansongda.cn>
|
||||
*/
|
||||
private function registerService(array $config): void
|
||||
private function registerServices(array $config): void
|
||||
{
|
||||
foreach (array_merge($this->coreService, $this->service) as $service) {
|
||||
$var = self::get($service);
|
||||
|
||||
if ($var instanceof ServiceProviderInterface) {
|
||||
$var->prepare($config);
|
||||
$var->register($this);
|
||||
}
|
||||
self::registerService($service, $config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ class PayTest extends TestCase
|
||||
Pay::foo([]);
|
||||
}
|
||||
|
||||
public function testSetAndGet()
|
||||
public function testMagicCallSetAndGet()
|
||||
{
|
||||
$data = [
|
||||
'name' => 'yansongda',
|
||||
@ -79,7 +79,6 @@ class PayTest extends TestCase
|
||||
|
||||
$container = Pay::getContainer($config);
|
||||
|
||||
self::assertInstanceOf(Container::class, $container);
|
||||
self::assertInstanceOf(Config::class, $container->get(ConfigInterface::class));
|
||||
self::assertEquals($config['name'], Pay::get(ConfigInterface::class)->get('name'));
|
||||
|
||||
@ -149,9 +148,4 @@ class PayTest extends TestCase
|
||||
|
||||
Pay::getContainer();
|
||||
}
|
||||
|
||||
public function testGetForceContainer()
|
||||
{
|
||||
self::assertInstanceOf(Container::class, Pay::getContainer([]));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user