rcconsulting / myfmapilibrary-for-php
FileMaker 17/18/19 数据 API PHP 封装
Requires
- php: >=7.1.0
- ext-curl: *
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^5.6
This package is auto-updated.
Last update: 2024-09-29 05:28:25 UTC
README
团队
Lesterius 是一家欧洲 FileMaker 商务联盟白金会员,在比利时、法国、荷兰、葡萄牙和西班牙运营。我们是一群富有创意的商业顾问,与客户共同创造基于 FileMaker 平台的业务解决方案。
分享知识是我们基因的一部分,这就是为什么我们开发了这个库,让 FileMaker 数据 API 与 PHP 容易使用。
打破你应用的界限!
Richard Carlton Consulting 是一家全栈 Claris FileMaker 开发咨询公司,为全球客户提供任何与 FileMaker 相关的服务。我们还发布了 FileMaker 社区中最大、最完整的视频培训课程。
描述
这个库是 Claris FileMaker 数据 API 的 PHP 封装。它支持 17/18/19 版本数据 API 命令,尽管如果你在 17 版本上使用 18 命令(例如元数据命令),它将会失败。
你将能够使用所有功能,就像在 FileMaker 服务器数据 API 文档(通过 https://[你的服务器域名]/fmi/data/apidoc 访问)中记录的那样。
FMS 17 数据 API 的通用 FileMaker 文档在此 这里 可用
FMS 18 数据 API 的通用 FileMaker 文档在此 这里 可用
FMS 19 数据 API 的通用 FileMaker 文档在此 这里 可用
理由
这个分支是为了使 myFMApiLibrary 具有更好的开箱即用兼容性,与 Lesterius 的上游代码相比。我们非常感谢 Lesterius 所付出的辛勤努力。
要求
库版本 <2.1.0
- PHP >= 5.5
- PHP cURL 扩展
- PHP mbstring 扩展
库版本 >=2.1.0
- PHP >= 7.1
- PHP cURL 扩展
- PHP mbstring 扩展
安装
推荐的安装方式是通过 Composer。
composer require rcconsulting/myfmapilibrary-for-php:\>=2.0.0
安装后,你需要注明将使用此库,并需要 Composer 的自动加载器
use \RCConsulting\FileMakerApi\DataApi; require_once __DIR__ . '/vendor/autoload.php';
使用
准备你的 FileMaker 解决方案
- 在 FileMaker 服务器管理员控制台中启用 FileMaker 数据 API。
- 在你的 FileMaker 数据库中创建一个用户,并为其设置一个自定义权限集,至少包含 'fmrest' 扩展权限
- 为该用户定义记录和布局访问权限
使用库
登录
使用凭据登录
// Please note that the library does not currently support external data source authentication $dataApi = new \RCConsulting\FileMakerApi\DataApi('https://test.fmconnection.com/fmi/data', 'MyDatabase'); $dataApi->login('filemaker api user', 'filemaker api password');
使用凭据登录的一行示例
// Arguments: DAPI URL, Database Name, DAPI User, DAPI Password, SSL Verification Enabled?, Force Legacy HTTP 1.1? $dataApi = new \RCConsulting\FileMakerApi\DataApi('https://test.fmconnection.com/fmi/data','MyDatabase', "DAP_User", "DAPI_Pass_1234~", True, False);
使用 oauth 登录
// Please note that RCC has not tested OAuth logins. We welcome any PR's which improve support. $dataApi = new \RCConsulting\FileMakerApi\DataApi('https://test.fmconnection.com/fmi/data', 'MyDatabase'); $dataApi->loginOauth('oAuthRequestId', 'oAuthIdentifier');
登出
// It is highly recommended to log out at each script or large process end. The Data API tokens last 15 minutes after last use, and so will hold a slot open for 15 minutes after your last connection if you do not clean up after yourself. Additionally, logout() does not destroy the DataAPI object you created (via new) previously, but it does clean out any authorization tokens from the object. $dataApi->logout();
创建记录
// Call login method first $data = [ 'FirstName' => 'John', 'LastName' => 'Doe', 'email' => 'johndoe@acme.inc', 'RepeatingField(1)' => 'Test' ]; $scripts = [ [ 'name' => 'ValidateUser', 'param' => 'johndoe@acme.inc', 'type' => RCConsulting\FileMakerApi\DataApi::SCRIPT_PREREQUEST ], [ 'name' => 'SendEmail', 'param' => 'johndoe@acme.inc', 'type' => RCConsulting\FileMakerApi\DataApi::SCRIPT_POSTREQUEST ] ]; $portalData = [ 'lunchDate' => '17/04/2013', 'lunchPlace' => 'Acme Inc.' ]; try { $recordId = $dataApi->createRecord('layout name', $data, $scripts, $portalData); } catch(\Exception $e) { // handle exception }
删除记录
// Call login method first try { $dataApi->deleteRecord('layout name', $recordId, $script); } catch(\Exception $e) { // handle exception }
编辑记录
// Call login method first try { $recordId = $dataApi->editRecord('layout name', $recordId, $data, $lastModificationId, $portalData, $scripts); } catch(\Exception $e) { // handle exception }
获取记录
// Call login method first $portals = [ [ 'name' => 'Portal1', 'limit' => 10 ], [ 'name' => 'Portal2', 'offset' => 3 ] ]; try { $record = $dataApi->getRecord('layout name', $recordId, $portals, $scripts); } catch(\Exception $e) { // handle exception }
获取记录
// Call login method first $sort = [ [ 'fieldName' => 'FirstName', 'sortOrder' => 'ascend' ], [ 'fieldName' => 'City', 'sortOrder' => 'descend' ] ]; try { $record = $dataApi->getRecords('layout name', $sort, $offset, $limit, $portals, $scripts); } catch(\Exception $e) { // handle exception }
查找记录
// Call login method first $query = [ [ 'fields' => [ ['fieldname' => 'FirstName', 'fieldvalue' => '==Test'], ['fieldname' => 'LastName', 'fieldvalue' => '==Test'], ], 'options' => [ 'omit' => false ] ] ]; try { $results = $dataApi->findRecords('layout name', $query, $sort, $offset, $limit, $portals, $scripts, $responseLayout); } catch(\Exception $e) { // handle exception }
盲火脚本
try { $dataApi->executeScript($layout, $scriptName, $scriptParameters); } catch(\Exception $e) { // handle exception }
设置全局字段
// Call login method first $data = [ 'FieldName1' => 'value', 'FieldName2' => 'value' ]; try { $dataApi->setGlobalFields('layout name', $data); } catch(\Exception $e) { // handle exception }
上传文件到容器
通过 Web 表单传递的文件
// Call login method first $containerFieldName = 'Picture'; $containerFieldRepetition = 1; // replace 'upload' below with the name="value" of the file input element of your web form $filepath = $_FILES['upload']['tmp_name']; $filename = $_FILES['upload']['name']; try { $dataApi->uploadToContainer('layout name', $recordId, $containerFieldName, $containerFieldRepetition, $filepath, $filename); } catch(\Exception $e) { // handle exception }
服务器上的文件
// Call login method first $containerFieldName = 'Picture'; $containerFieldRepetition = 1; $filepath = '/usr/home/acme/pictures/photo.jpg'; try { $dataApi->uploadToContainer('layout name', $recordId, $containerFieldName, $containerFieldRepetition, $filepath); } catch(\Exception $e) { // handle exception }
库辅助方法
token 使用
// useful when not explicitly logging into data api, but already have valid token // note that this implicitly sets the token retrieval date to now() $dataApi->setApiToken($token); // also supported $dataApi->setApiToken($token, $tokenDate); // + unix timestamp // returns current api token (without checking if it's valid) $token = $dataApi->getApiToken(); // to check if the token is expired: if ($dataApi->isApiTokenExpired()) { // token expired } else { // do stuff } // to refresh the token in the case you've ever previously logged into the data api with this instance of the class // currently only works with a data api username/password combo (ie not oauth) if ($dataApi->refreshToken()) { // success } // Validate whether the session authorization token we're using ... is actually valid ... according to FileMaker Server if ($dataApi->validateTokenWithServer()){ // token is valid according to FMS! } else { // token has expired according to FMS! }