项目作者: myFMbutler

项目描述 :
A wrapper in PHP to use the FileMaker Data API
高级语言: PHP
项目地址: git://github.com/myFMbutler/myFMApiLibrary-for-PHP.git
创建时间: 2018-06-04T14:48:31Z
项目社区:https://github.com/myFMbutler/myFMApiLibrary-for-PHP

开源协议:GNU General Public License v3.0

下载


Lesterius (Claris) FileMaker 19 Data API wrapper - myFMApiLibrary for PHP

Presentation

Team

Lesterius is a European Claris (FileMaker) Business Alliance Platinum member that operates in Belgium, France, the Netherlands, Portugal and Spain. We are creative business consultants who co-create FileMaker Platform based solutions with our customers.\
Sharing knowledge takes part of our DNA, that’s why we developed this library to make the FileMaker Data API easy-to-use with PHP.\
Break the limits of your application!\
Lesterius logo

Description

This library is a PHP wrapper of the (Claris) FileMaker Data API 19.

You can find the PHP wrapper of the FileMaker Data API 17 on the releases <= v.1. .

You can find the PHP wrapper of the FileMaker Data API 18 on the releases <= v.2.
.

You will be able to use every functions like it’s documented in your FileMaker server Data Api documentation (accessible via https://[your server domain]/fmi/data/apidoc).
General Claris document on the Data API is available here

Requirements

  • PHP >= 5.5
  • PHP cURL extension
  • PHP mb_string extension

Installation

The recommended way to install it is through Composer.

  1. composer require myfmbutler/myfmapilibrary-for-php

After installing, you need to require Composer’s autoloader:

  1. require_once __DIR__ . '/vendor/autoload.php';

Usage

Prepare your Claris (Filmaker) solution

  1. Enable the (Claris) FileMaker Data API option on your FileMaker server admin console.
  2. Create a specific user in your (Claris) FileMaker database with the ‘fmrest’ privilege
  3. Define records & layouts access for this user

Use the library

Login

Login with credentials:

  1. $dataApi = new \Lesterius\FileMakerApi\DataApi('https://test.fmconnection.com/fmi/data', 'MyDatabase', null, 'filemaker api user', 'filemaker api password');

Login with oauth:

  1. $dataApi = new \Lesterius\FileMakerApi\DataApi('https://test.fmconnection.com/fmi/data', 'MyDatabase', null, null, true, 'oAuthRequestId', 'oAuthIdentifier');

Logout

  1. $dataApi->logout();

Validate Session

  1. $dataApi->validateSession();

Create record

  1. $data = [
  2. 'FirstName' => 'John',
  3. 'LastName' => 'Doe',
  4. 'email' => 'johndoe@acme.inc',
  5. 'RepeatingField(1)' => 'Test'
  6. ];
  7. $scripts = [
  8. [
  9. 'name' => 'ValidateUser',
  10. 'param' => 'johndoe@acme.inc',
  11. 'type' => Lesterius\FileMakerApi\DataApi::SCRIPT_PREREQUEST
  12. ],
  13. [
  14. 'name' => 'SendEmail',
  15. 'param' => 'johndoe@acme.inc',
  16. 'type' => Lesterius\FileMakerApi\DataApi::SCRIPT_POSTREQUEST
  17. ]
  18. ];
  19. $portalData = [
  20. 'portalName or OccurenceName' => [
  21. [
  22. "Occurence::PortalField 1" => "Value",
  23. "Occurence::PortalField 2" => "Value",
  24. ]
  25. ]
  26. ];
  27. try {
  28. $recordId = $dataApi->createRecord('layout name', $data, $scripts, $portalData);
  29. } catch(\Exception $e) {
  30. // handle exception
  31. }

Delete record

  1. try {
  2. $dataApi->deleteRecord('layout name', $recordId, $script);
  3. } catch(\Exception $e) {
  4. // handle exception
  5. }

Edit record

  1. try {
  2. $recordId = $dataApi->editRecord('layout name', $recordId, $data, $lastModificationId, $portalData, $scripts);
  3. } catch(\Exception $e) {
  4. // handle exception
  5. }

Duplicate record

  1. try {
  2. $recordId = $dataApi->editRecord('layout name', $recordId, $scripts);
  3. } catch(\Exception $e) {
  4. // handle exception
  5. }

Get record

  1. $portals = [
  2. [
  3. 'name' => 'Portal1',
  4. 'limit' => 10
  5. ],
  6. [
  7. 'name' => 'Portal2',
  8. 'offset' => 3
  9. ]
  10. ];
  11. try {
  12. $record = $dataApi->getRecord('layout name', $recordId, $portals, $scripts);
  13. } catch(\Exception $e) {
  14. // handle exception
  15. }

Get records

  1. $sort = [
  2. [
  3. 'fieldName' => 'FirstName',
  4. 'sortOrder' => 'ascend'
  5. ],
  6. [
  7. 'fieldName' => 'City',
  8. 'sortOrder' => 'descend'
  9. ]
  10. ];
  11. try {
  12. $record = $dataApi->getRecords('layout name', $sort, $offset, $limit, $portals, $scripts);
  13. } catch(\Exception $e) {
  14. // handle exception
  15. }

Find records

  1. $query = [
  2. [
  3. 'fields' => [
  4. ['fieldname' => 'FirstName', 'fieldvalue' => '==Test'],
  5. ['fieldname' => 'LastName', 'fieldvalue' => '==Test'],
  6. ],
  7. 'options' => [
  8. 'omit' => false
  9. ]
  10. ]
  11. ];
  12. try {
  13. $results = $dataApi->findRecords('layout name', $query, $sort, $offset, $limit, $portals, $scripts, $responseLayout);
  14. } catch(\Exception $e) {
  15. // handle exception
  16. }

Set global fields

  1. $data = [
  2. 'FieldName1' => 'value',
  3. 'FieldName2' => 'value'
  4. ];
  5. try {
  6. $dataApi->setGlobalFields('layout name', $data);
  7. } catch(\Exception $e) {
  8. // handle exception
  9. }

Execute script

  1. try {
  2. $dataApi->executeScript('script name', $scriptsParams);
  3. } catch(\Exception $e) {
  4. // handle exception
  5. }

Upload file to container

Renaming file

  1. $containerFieldName = 'Picture';
  2. $containerFieldRepetition = 1;
  3. // replace 'upload' below with the name="value" of the file input element of your web form
  4. $filepath = $_FILES['upload']['tmp_name'];
  5. $filename = $_FILES['upload']['name'];
  6. try {
  7. $dataApi->uploadToContainer('layout name', $recordId, $containerFieldName, $containerFieldRepetition, $filepath, $filename);
  8. } catch(\Exception $e) {
  9. // handle exception
  10. }

Without checking filename

  1. $containerFieldName = 'Picture';
  2. $containerFieldRepetition = 1;
  3. $filepath = '/usr/home/acme/pictures/photo.jpg';
  4. try {
  5. $dataApi->uploadToContainer('layout name', $recordId, $containerFieldName, $containerFieldRepetition, $filepath);
  6. } catch(\Exception $e) {
  7. // handle exception
  8. }

Metadata Info

Product Info

  1. try {
  2. $dataApi->getProductInfo();
  3. } catch(\Exception $e) {
  4. // handle exception
  5. }

Database Names

  1. try {
  2. $dataApi->getDatabaseNames();
  3. } catch(\Exception $e) {
  4. // handle exception
  5. }

Layout Names

  1. try {
  2. $dataApi->getLayoutNames();
  3. } catch(\Exception $e) {
  4. // handle exception
  5. }

Script Names

  1. try {
  2. $dataApi->getScriptNames();
  3. } catch(\Exception $e) {
  4. // handle exception
  5. }

Layout Metadata

  1. try {
  2. $dataApi->getLayoutMetadata('layout name', $recordId);
  3. } catch(\Exception $e) {
  4. // handle exception
  5. }