guillian / afpaconnect-interface
此包的最新版本(1.0.1)没有可用的许可证信息。
1.0.1
2021-06-23 19:35 UTC
Requires
- ext-json: *
- cache/cache: ^1.0
- firebase/php-jwt: ^5.3
- guzzlehttp/guzzle: ^7.3
- symfony/cache: ^5.3
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is not auto-updated.
Last update: 2024-09-26 11:26:05 UTC
README
此模块允许轻松集成一个与AfpaConnect API进行对话的类。
Packagist: guillian/afpaconnect-interface.
安装
要求
- php >= 7.4
- composer >= 2.0
- PHP7.4-http
- PHP7.4-curl
- PHP7.4-json
- PHP7.4-dom
- PHP7.4-xml
- PHP7.4-mbstring
- PHP7.4-pdo
- (PHP7.4-libxml)
步骤
composer require guillian/afpaconnect-interface
AFPA项目
本小指南将向您解释如何集成
-
在命令行中,定位到您的项目根目录。
-
使用composer安装模块
composer require guillian/afpaconnect-interface
. -
使用composer的自动加载器
为了这样做,在文件
DEVS/web/route.php
中在session_start()
之后放置。require $GLOBALS_INI['PATH_HOME'].$GLOBALS_INI['PATH_CLASS'].'vendor/autoload.php';
此自动加载器允许动态加载位于 vendor 文件夹中的类。
-
修改文件
DEVS/modules/initialize.php
以在所有服务中全局包含API Helper。- 在类开始之前添加 use
<?php require_once "database.php"; require_once "security.php"; use Guillian\AfpaConnect\AfpaConnect; /** * Class Initialize | file initialize.php
- 添加这两个属性
public AfpaConnect $api; public static $_apiInstance = null;
- 在构造函数中创建类的实例。
// Instance one time (singleton) AfpaConnect Interface Helper $this->api = self::getApi();
- 添加一个获取AfpaConnect类实例的方法
/** * Get AfpaConnect Interface Helper instance once. * * @return AfpaConnect */ public static function getApi(): AfpaConnect { if (is_null(self::$_apiInstance)) { $conf = Configuration::getGlobalsINI(); $publicKey = file_get_contents($conf['PATH_HOME'].$conf['API_PUBLIC_KEY']); self::$_apiInstance = new AfpaConnect($conf['API_HOSTNAME'], "afpanier", $publicKey); } return self::$_apiInstance; }
如何使用?
现在,在您的所有服务中都可用了一个新的变量 $this->api
。
POST示例
$response = $this->api->post('register', [ 'username' => '123456789', 'password' => 'test' ]); // La réponse est au format JSON. var_dump(json_decode($response));
GET示例
$response = $this->api->get('user', [ 'username' => '123456789' ]); // La réponse est au format JSON. var_dump(json_decode($response));
请参阅文档以了解路由列表。