MOON
Server: Apache
System: Linux server1.studioinfinity.com.br 2.6.32-954.3.5.lve1.4.90.el6.x86_64 #1 SMP Tue Feb 21 12:26:30 UTC 2023 x86_64
User: artinside (517)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/artinside/www/finance/vendor/frenet/frenet-php/src/ApiFactory.php
<?php

declare(strict_types = 1);

namespace Frenet;

use Frenet\Framework\DI\ContainerRepository;

/**
 * Class ApiFactory
 * @package Frenet
 */
class ApiFactory
{

    /**
     * @var \DI\Container
     */
    private static $container;

    /**
     * @var array
     */
    public static $config = [
        'definitions' => FRENET_DIR_DI_CONFIG
    ];

    /**
     * @var array
     */
    private static $customConfig = [];

    /**
     * @param string $token
     * @param array  $config
     *
     * @return ApiInterface
     * @throws \DI\DependencyException
     * @throws \DI\NotFoundException
     */
    public static function create(string $token, array $config = [])
    {
        if (!empty($config)) {
            /** If there's a customized configuration the application can load it. */
            self::$customConfig = (array) $config;
        }

        self::setupContainer();

        $api = self::createApiInstance($token);

        self::$container->set(Api::class, $api);

        return $api;
    }

    /**
     * @param string $token
     *
     * @return ApiInterface
     * @throws \DI\DependencyException
     * @throws \DI\NotFoundException
     */
    private static function createApiInstance(string $token)
    {
        return self::$container->make(ApiInterface::class, [
            'token' => $token,
        ]);
    }

    /**
     * Setup the container.
     *
     * @throws \Frenet\Framework\Exception\ExceptionInterface
     */
    private static function setupContainer()
    {
        self::$container = ContainerRepository::getInstance(self::getConfig());
    }

    /**
     * @return array
     */
    private static function getConfig()
    {
        $config = array_merge_recursive(self::$config, self::$customConfig);
        return $config;
    }
}