sib-retail / fluent-fm
一个使用流畅查询构建器风格的接口的 PHP 包,用于 FileMaker Server 的数据 API。
Requires
- php: ^7.2
- ext-json: *
- guzzlehttp/guzzle: ^7.0.1
- ramsey/uuid: ^3.8 || ^4.0
Requires (Dev)
- phpunit/phpunit: 8.5.5
- symfony/var-dumper: ^4.1
- dev-master
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/composer/phpunit/phpunit-8.5.19
- dev-dependabot/add-v2-config-file
- dev-analysis-yvJorL
- dev-field_meta
- dev-dependabot/composer/symfony/var-dumper-tw-4.1or-tw-5.0
- dev-analysis-ordgaN
- dev-analysis-QM13e3
- dev-analysis-ka7AA4
- dev-bugfix
This package is not auto-updated.
Last update: 2024-09-19 23:14:36 UTC
README
FluentFM 是一个 PHP 包,使用流畅查询构建器风格的接口连接到 FileMaker Server 的数据 API。
要求
- PHP 7.2+
- FileMaker Server 17
安装
使用 Composer
使用以下命令
composer require thyyppa/fluent-fm
或者包含在您的 composer.json
文件中
{ "require": { "thyyppa/fluent-fm": "dev-master" } }
准备 FileMaker
重要!所有表和布局 必须 包含一个 id
字段。
如果您想使用软删除,您的表和布局 必须 包含字段 deleted_at
以下字段也建议使用
created_at
(按最新排序)updated_at
(按最后更新排序)
您希望访问的所有字段都必须在您在通过 API 执行 FileMaker 操作时提供的布局中可用。
理想情况下,这些将是包含所有原始字段的隐藏布局,与表相对应,但根据您的布局结构,您可能能够使用现有的面向人类的布局。
确保您的权限集中启用了 fmrest
,您可以在以下位置定义
文件 > 管理 > 安全性 > [高亮用户] > 权限集 [编辑]
同时确保服务器上启用了数据 API。
如果您的服务器安装在本地,此链接应带您到那里
https://:16001/admin-console/app/connectors/fmdapi
否则将 localhost
替换为服务器地址。
使用方法
从布局获取记录
<?php use Hyyppa\FluentFM\Connection\FluentFMRepository; $fm = new FluentFMRepository([ 'file' => 'FilemakerFilename', 'host' => '127.0.0.1', 'user' => 'Admin', 'pass' => 'secret' ]); // get a single record as array $record = $fm->record('layout', 'id')->get(); // get multiple records as array $records = $fm->records('layout')->limit(10)->get();
执行查找操作
$bobs = $fm->find('customers')->where('first','Bob')->get();
创建记录
$recordId = $fm->create('customers', [ 'id' => 13 'first' => 'Robert', 'last' => 'Paulson', 'phone' => '406-555-0112', ]);
更新记录
// if multiple records are matched each will be updated $fm->update('customers', [ 'phone' => '406-555-0199' ]) ->where('id',13) ->limit(1) ->exec();
删除记录
如果您想使用软删除,您的表和布局 必须 包含字段 deleted_at
// hard delete removes record $fm->delete('customers') ->where('id',13) ->limit(1) ->exec(); // soft delete sets record's deleted_at field $fm->softDelete('customers') ->where('id',13) ->limit(1) ->exec(); // undeletes soft deleted records $fm->undelete('customers') ->where('id',13) ->limit(1) ->exec(); // returns matching records that have not been soft deleted $active = $fm ->find('customers') ->where('first','Bob') ->withoutDeleted() ->get(); // returns matching records even if soft deleted (default behavior) $all = $fm ->find('customers') ->where('first','Bob') ->withDeleted() ->get();
将文件上传和下载到记录的容器中
// if query matches multiple, file will be added to each $fm->upload('customers', 'photo', './path/to/photo.jpg') ->where('id', 13) ->limit(1) ->exec(); // if query matches multiple, all files will be downloaded to path $fm->download('customers', 'photo', './save/to/path/') ->where('id', 13) ->limit(1) ->exec();
运行 FileMaker 脚本
$fm->find('customers') ->where('id',13) ->script('scriptname', 'parameter') ->presort('presort_scriptname', 'presort_scriptparam') ->prerequest('prerequest_scriptname', 'prerequest_scriptparam') ->get()
检索元数据
要检索布局的元数据(列类型和属性),请
$fm->metadata('customers') ->exec();
链式命令
... ->find( <layout> ) ->update( <layout>, [fields], [recordId] ) ->delete( <layout>, [recordId] ) ->softDelete( <layout>, [recordId] ) ->undelete( <layout>, [recordId] ) ->upload( <layout>, <field>, <filename>, [recordId] ) ->download( <layout>, <field>, [output_dir], [recordId] )
链式修饰符
... ->record( <layout>, <id> ) ->records( <layout>, [id] ) ->limit( <limit> ) ->offset( <offset> ) ->sort( <field>, [ascending] ) ->sortAsc( <field> ) ->sortDesc( <field> ) ->withPortals() ->withoutPortals() ->where( <field>, <params> ) // multiple calls act as "and" ->orWhere( <field>, <params> ) ->whereEmpty( <field> ) ->has( <field> ) ->whereNotEmpty( <field> ) ->withDeleted() ->withoutDeleted() ->script( <script>, [param], [type] ) ->prerequest( <script>, [param] ) ->presort( <script>, [param] )
链式方法
... ->get() ->exec() ->create( <layout>, [fields] ) ->latest( <layout>, [field] ) # table must have created_at field if [field] undefined ->oldest( <layout>, [field] ) # table must have created_at field if [field] undefined ->lastUpdate( <layout>, [field] ) # table must have updated_at field if [field] undefined ->first() ->last()
其他命令
... // set global fields on table ->globals( [table], [ key => value ] ) // enable or disable automatic setting of id field (default enabled) ->enableAutoId() ->disableAutoId() // clear query parameters ->clearQuery() // clear query parameters and reset to default options ->reset()
持久认证
如果您的 PHP 安装已安装 APCu 模块,此库能够缓存请求之间的认证令牌。
令牌与
- filemaker 主机、数据库、用户和密码相关联。
- 从创建或最后使用时间起 15 分钟内有效,以查询数据 API。
每次使用令牌进行新的数据 API 请求时,其在缓存中的 TTL(生存时间)将延长 14.5 分钟。
这反映了 Filemaker 的机制,每次使用令牌时都会延长其有效期(最大空闲生存时间为 15 分钟)。
如果令牌在缓存中无效,异常将由库捕获,并且库将透明地执行一次认证并获取新令牌的另一次尝试。
要定义自定义 TTL(以及 TTL 扩展持续时间),在实例化 FluentFMRepository
对象时指定 token_ttl
。
$fm = new FluentFMRepository([ 'file' => 'FilemakerFilename', 'host' => '127.0.0.1', 'user' => 'Admin', 'pass' => 'secret', 'token_ttl' => 60, // shorter token cache TTL specified here ]);
此功能不应在共享托管或您无法确保您的 APCu 严格属于您的服务器上使用
故障排除
错误:SSL 证书问题:无法获取本地发行者证书
如果您遇到此错误,请尝试在设置配置中添加 'client' => [ 'verify' => false ],
如下所示
<?php use Hyyppa\FluentFM\Connection\FluentFMRepository; $fm = new FluentFMRepository([ 'file' => 'FilemakerFilename', 'host' => '127.0.0.1', 'user' => 'Admin', 'pass' => 'secret', 'client' => [ 'verify' => false ], ]); // ...
许可证
MIT 许可证
免责声明
此项目是一个独立实体,未经 FileMaker, Inc. 授权、赞助或以其他方式与 FileMaker, Inc. 联系。FileMaker 是 FileMaker, Inc. 的商标,在美国和其他国家注册。