This commit is contained in:
yansongda 2020-10-14 16:57:05 +08:00
parent 06358c970d
commit bb7acd000b
4 changed files with 20 additions and 18 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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);
}
}
}

View File

@ -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([]));
}
}