<commit_before><?php

declare(strict_types=1);

/*
 * This file is part of the ************************ package.
 * _____________                           _______________
 *  ______/     \__  _____  ____  ______  / /_  _________
 *   ____/ __   / / / / _ \/ __`\/ / __ \/ __ \/ __ \___
 *    __/ / /  / /_/ /  __/ /  \  / /_/ / / / / /_/ /__
 *      \_\ \_/\____/\___/_/   / / .___/_/ /_/ .___/
 *         \_\                /_/_/         /_/
 *
 * The PHP Framework For Code Poem As Free As Wind. <Query Yet Simple>
 * (c) 2010-2020 http://queryphp.com All rights reserved.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Leevel\Manager;

use Closure;
use InvalidArgumentException;
use Leevel\Di\IContainer;

/**
 * 管理器.
 */
abstract class Manager
{
    /**
     * IOC 容器.
     *
     * @var \Leevel\Di\IContainer
     */
    protected IContainer $container;

    /**
     * 连接对象.
     *
     * @var array
     */
    protected array $connects = [];

    /**
     * 扩展连接.
     *
     * @var array
     */
    protected array $extendConnect = [];

    /**
     * 过滤全局配置项.
     *
     * @var array
     */
    protected array $defaultCommonOption = [
        'default',
        'connect',
    ];

    /**
     * 构造函数.
     */
    public function __construct(IContainer $container)
    {
        $this->container = $container;
    }

    /**
     * call.
     *
     * @return mixed
     */
    public function __call(string $method, array $args)
    {
        return $this->connect()->{$method}(...$args);
    }

    /**
     * 返回 IOC 容器.
     */
    public function container(): IContainer
    {
        return $this->container;
    }

    /**
     * 连接并返回连接对象.
     *
     * @@throws \InvalidArgumentException
     */
    public function connect(?string $connect = null, bool $onlyNew = false): object
    {
        if (!$connect) {
            $connect = $this->getDefaultConnect();
        }

        if (false === $onlyNew && isset($this->connects[$connect])) {
            return $this->connects[$connect];
        }

        if (!is_array($options = $this->getContainerOption('connect.'.$connect))) {
            $e = sprintf('Connection %s option is not an array.', $connect);

            throw new InvalidArgumentException($e);
        }

        if (!isset($options['driver'])) {<commit_msg>fix(manager): fix for phpstan level 7<commit_after><?php

declare(strict_types=1);

/*
 * This file is part of the ************************ package.
 * _____________                           _______________
 *  ______/     \__  _____  ____  ______  / /_  _________
 *   ____/ __   / / / / _ \/ __`\/ / __ \/ __ \/ __ \___
 *    __/ / /  / /_/ /  __/ /  \  / /_/ / / / / /_/ /__
 *      \_\ \_/\____/\___/_/   / / .___/_/ /_/ .___/
 *         \_\                /_/_/         /_/
 *
 * The PHP Framework For Code Poem As Free As Wind. <Query Yet Simple>
 * (c) 2010-2020 http://queryphp.com All rights reserved.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Leevel\Manager;

use Closure;
use InvalidArgumentException;
use Leevel\Di\IContainer;

/**
 * 管理器.
 */
abstract class Manager
{
    /**
     * IOC 容器.
     *
     * @var \Leevel\Di\IContainer
     */
    protected IContainer $container;

    /**
     * 连接对象.
     *
     * @var array
     */
    protected array $connects = [];

    /**
     * 扩展连接.
     *
     * @var array
     */
    protected array $extendConnect = [];

    /**
     * 过滤全局配置项.
     *
     * @var array
     */
    protected array $defaultCommonOption = [
        'default',
        'connect',
    ];

    /**
     * 构造函数.
     */
    public function __construct(IContainer $container)
    {
        $this->container = $container;
    }

    /**
     * call.
     *
     * @return mixed
     */
    public function __call(string $method, array $args)
    {
        return $this->connect()->{$method}(...$args);
    }

    /**
     * 返回 IOC 容器.
     */
    public function container(): IContainer
    {
        return $this->container;
    }

    /**
     * 连接并返回连接对象.
     *
     * @throws \InvalidArgumentException
     */
    public function connect(?string $connect = null, bool $onlyNew = false): object
    {
        if (!$connect) {
            $connect = $this->getDefaultConnect();
        }

        if (false === $onlyNew && isset($this->connects[$connect])) {
            return $this->connects[$connect];
        }

        if (!is_array($options = $this->getContainerOption('connect.'.$connect))) {
            $e = sprintf('Connection %s option is not an array.', $connect);

            throw new InvalidArgumentException($e);
        }

        if (!isset($options['driver'])) {
{'fraction_non_alphanumeric': 0.15971790085044596, 'fraction_numerical': 0.00394109105994607, 'mean_word_length': 1.646542261251372, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2738102', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1541, 'n_words': 309}