insidesuki / solapimanager
delSOl ApiClient
2.2.5
2022-10-11 04:52 UTC
Requires
- php: >=8.1
- ext-json: *
- insidesuki/apiclient: 1.8.4
- insidesuki/ddd-utils: ^2.1.1
- insidesuki/entitymapping: ^0.1.4
- phpunit/phpunit: >=8
- symfony/css-selector: 5.4.*
- symfony/dom-crawler: 5.4.*
- symfony/framework-bundle: 5.4.*
Requires (Dev)
- symfony/dotenv: 5.4.*
- dev-master
- 2.2.5
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1
- 2.0
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6
- 1.5
- 1.4.6
- 1.4.5
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4
- 1.3.9
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3
- 1.2
- 1.1
- 0.1.1
- 0.0.10
- 0.0.2
- 0.0.1
- dev-dr/feature/190922/embedeble-mapping
- dev-feature/mapping
- dev-dr/refactor/delsolapimanager
- dev-dr/refactor-delsolapimanager
This package is auto-updated.
Last update: 2024-09-11 09:02:34 UTC
README
为您的 symfony 5.4 项目或独立项目提供一个抽象仓库,以便对 ContaSol API 进行查询请求
特性
- 支持通过 $_ENV 文件进行多凭证操作,并有一个类来表示凭证。
- 简单的键值查询条件(findOneBy、insert 和 update)
// example for findOneBy condition
$condition = ['codcli'=>1]
// example for insert petition
$insert = [
'codcli' => '9989'
'nomcli' => 'faraday'
];
REPOSITORY APIS
- findOneBy(array $condition): null|array: 执行 LeerRegistro 请求 https://api.sdelsol.com/admin/LeerRegistro
- findByQuery(string $query): null|array: 执行 LanzarConsulta 请求 https://api.sdelsol.com/admin/LanzarConsulta
- findByFilter(string $filter): array: 执行 CargaTabla 请求 https://api.sdelsol.com/admin/CargaTabla
- insert(array $data):bool: 执行 EscribirRegistro 请求 https://api.sdelsol.com/admin/EscribirRegistro
- update(array $data):bool 执行 ActualizarRegistro 请求 https://api.sdelsol.com/admin/ActualizarRegistro
- delete(array $condition):bool: 执行 BorrarRegistros 请求 https://api.sdelsol.com/admin/BorrarRegistros/:ejercicio/:tabla/:filtro
- getInfo(string $field): array: 执行 LeerConfiguracion 请求 https://api.sdelsol.com/admin/LeerConfiguracion/2021/F_CLI
安装
composer require insidesuki/solapimanager
第一步
1- 添加到 .env 文件
###> DELSOL API CREDENTIAL
### Namespace to use as credentials folder
DELSOL_API_CREDENTIALS="YourProjectNamespace\\ToUse\\AS\\CredentialFolderStore\\"
APIDELSOL_BASE_URL=https://api.sdelsol.com
APIDELSOL_AUTH_URL=https://api.sdelsol.com/login/Autenticar
APIDELSOL_TOKEN_RESPONSE=resultado
APIDELSOL_TOKEN_EXPIRES=60;
## CREDENTIALS1, use as key name the one you want
API1_NAME=delSol1
API1_CODIGO_FABRICANTE=***
API1_CODIGO_CLIENTE=*****
API1_DB=****
API1_SECRET=******
## CREDENTIALS1
API2_NAME=delSol1
API2_CODIGO_FABRICANTE=***
API2_CODIGO_CLIENTE=*****
API2_DB=****
API2_SECRET=******
###< delsolApiClient ###
2- 创建凭证类
转到 DELSOL_API_CREDENTIALS 路径,为在 $_ENV 文件中定义的每个 API 创建一个凭证。必须继承自 AbstractDelSolCredential
namespace F2admin\Application\Contabilidad\Infrastructure\Storage\DelSolApi\Credentials; use Insidesuki\ApiClient\Authentification\Contracts\ApiBearerCredentialInterface;
class DefaultSolCredential extends AbstractDelSolCredential implements ApiBearerCredentialInterface {
public function getApiName(): string
{
return $_ENV['API1_NAME'];
}
public function getBodyAuth(): array
{
return [
'codigoFabricante' => $_ENV['API1_CODIGO_FABRICANTE'],
'codigoCliente' => $_ENV['API1_CODIGO_CLIENTE'],
'baseDatosCliente' => $_ENV['API1_DB'],
'password' => $_ENV['API1_SECRET']
];
}
}
3- 创建仓库
创建一个继承自 AbstractDelSolRepository 的仓库,定义表、凭证等
namespace YourProject\Namespace\Repository; use Symfony\Contracts\HttpClient\HttpClientInterface; class ClientExampleRepository extends AbstractDelSolRepository { public function __construct(HttpClientInterface $httpClient) { parent::__construct($httpClient); } // define the delSol tablename public function tableName(): string { return 'f_cli'; } public function findById(int $idClient) { return $this->delSolManager->findOne(['codcli' => $idClient]); } }
不使用 Symfony
- 执行上述所有步骤
- 创建一个文件,例如
require __DIR__ . '/vendor/autoload.php';
use YourProject\Namespace\Repository\ClientExampleRepository;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpClient\NativeHttpClient;
try {
$dotEnv = new Dotenv();
$dotEnv->load(__DIR__ . '/../config/.env.local');
$clientRepository = new ClientExampleRepository(
new NativeHttpClient()
);
// set the credential to use
$clientRepository->setManager('DelSolCredentialA');
$client = $clientRepository->findById(1);
}
catch (Exception $e) {
dd($e->getMessage());
}
dd($client);