thyyppa / fluent-fm
一个使用流畅查询构建器风格的接口的PHP包,用于FileMaker Server的数据API。
Requires
- php: ^7.2 || ^8.0 || ^8.1
- 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
Suggests
- ext-apcu: *
- dev-master
- 1.3.0
- 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 auto-updated.
Last update: 2024-09-04 04:27:25 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
(用于按最后更新排序)
您想要访问的所有字段必须在您执行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是FileMaker, Inc.的商标,在美国和其他国家注册。