Files
kiri-core/System/Pool/ObjectPool.php
T

71 lines
1.3 KiB
PHP
Raw Normal View History

2021-02-22 17:44:24 +08:00
<?php
namespace Snowflake\Pool;
use Exception;
use ReflectionException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
/**
* Class ObjectPool
* @package Snowflake\Pool
*/
class ObjectPool extends \Snowflake\Abstracts\Pool
{
2021-02-23 00:40:51 +08:00
/**
* set pool max length
*/
public function init()
{
$this->max = 100;
}
2021-02-23 00:38:33 +08:00
/**
* @param array $config
* @param bool $isMaster
* @return mixed
* @throws Exception
*/
public function getConnection(array $config, bool $isMaster): mixed
{
2021-02-23 00:42:44 +08:00
if (is_object($config[0])) {
return $config[0];
}
2021-02-23 00:40:51 +08:00
return $this->get(md5($config[0]), $config);
2021-02-23 00:38:33 +08:00
}
/**
* @param string $name
* @param array $config
* @return mixed
* @throws ReflectionException
* @throws NotFindClassException
*/
public function createClient(string $name, array $config): mixed
{
// TODO: Implement createClient() method.
return Snowflake::createObject(array_shift($config));
}
/**
* @param string $name
* @param $object
*/
public function release(string $name, mixed $object)
{
if (method_exists($object, 'clean')) {
$object->clean();
}
$this->push($name, $object);
}
2021-02-22 17:44:24 +08:00
}