matatirosoln / doctrine-fm-data-api-driver
Use FileMaker via the v17+ Data API as your backend database
Package info
github.com/matatirosolutions/doctrine-fm-data-api-driver
pkg:composer/matatirosoln/doctrine-fm-data-api-driver
Requires
- php: >=8.2
- ext-json: *
- doctrine/dbal: ^4.2
- doctrine/orm: ^3.3
- greenlion/php-sql-parser: ^4.5
- symfony/http-client: ^7.4 || ^8.0
- symfony/mime: ^7.4 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^10.5
- symfony/cache: ^7.4 || ^8.0
- symfony/var-exporter: ^7.4 || ^8.0
Suggests
- ext-curl: Needed for the max_tls_version option, which works around servers that reject recent OpenSSL handshakes
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 1.0.0
- 0.x-dev
- 0.11.1
- 0.11.0
- 0.10.11
- 0.10.10
- 0.10.9
- 0.10.8
- 0.10.7
- 0.10.6
- 0.10.5
- 0.10.4
- 0.10.3
- 0.10.2
- 0.10.1
- 0.10.0
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.4
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.8
- 0.6.7
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.0
- dev-branch-0-10-11
- dev-branch-0-10-10
This package is auto-updated.
Last update: 2026-11-25 18:27:19 UTC
README
A Doctrine DBAL driver to interact with FileMaker using the v17+ Data API v1.
| Version | PHP | Doctrine | Symfony |
|---|---|---|---|
| 1.x | >= 8.2 | DBAL 4.x, ORM 3.x | 7.4, 8.x |
| 0.x | >= 8.1 | DBAL 2/3, ORM 2.x | up to 7.x |
Upgrading from 0.x? See UPGRADE.md.
Installation
composer require matatirosoln/doctrine-fm-data-api-driver
Configuration
In your Doctrine configuration replace driver: with
doctrine: dbal: driver_class: MSDev\DoctrineFMDataAPIDriver\Driver\FMDriver host: fm.example.com port: 443 dbname: MyDatabase # the FileMaker file name, without the extension user: '%env(FM_USER)%' password: '%env(FM_PASSWORD)%' # server_version: FMCloud # if you're hosted on FileMaker Cloud, which also needs matatirosoln/fm-cloud-authentication
HTTP client options
These go in the connection's driverOptions (options: in DoctrineBundle's configuration):
doctrine: dbal: options: max_tls_version: '1.2' # optional, see below http_client_options: # any Symfony HttpClient option, e.g. for a self-signed certificate verify_peer: false verify_host: false
http_client- your ownSymfony\Contracts\HttpClient\HttpClientInterface, if you need full control (a PHP object, so only possible when you build the connection in code). Otherwise the driver creates a client withHttpClient::create().http_client_options- default request options for the client the driver creates. Requests are abandoned after 300 seconds without any data arriving unless you settimeout(Symfony's own default, 60 seconds, is too short for the slowest finds).max_tls_version- never negotiate a TLS version above this one (1.2, say). Off by default, so connections use TLS 1.3 where the server offers it.
When to use max_tls_version. Some servers can't cope with the TLS handshake of recent OpenSSL builds (OpenSSL 4, which
current PHP builds can link against) and drop the connection with tlsv1 alert decode error, on every request, while older clients
work. Symfony's HTTP clients can only set a minimum TLS version, so with this option the driver makes its requests through its own
small curl-based client (MaxTlsHttpClient, needs ext-curl) which can cap it. The helper classes use the same client.
Types
The driver ships with types for FileMaker's date, time and timestamp formats, for numbers, and for HTML encoded text and PHP arrays. Register those you need under whatever names you like:
doctrine: dbal: types: fmdatetime: MSDev\DoctrineFMDataAPIDriver\Types\FMDateTimeType # m/d/Y H:i:s fmdate: MSDev\DoctrineFMDataAPIDriver\Types\FMDateType # m/d/Y fmtime: MSDev\DoctrineFMDataAPIDriver\Types\FMTimeType # H:i fmint: MSDev\DoctrineFMDataAPIDriver\Types\FMIntType # '' or non-numeric becomes null fmfloat: MSDev\DoctrineFMDataAPIDriver\Types\FMFloatType # '' or non-numeric becomes null fmhtml: MSDev\DoctrineFMDataAPIDriver\Types\FMHTMLType fmarray: MSDev\DoctrineFMDataAPIDriver\Types\FMArrayType
FileMaker returns an empty string for an empty number, date or time field. The date, time, int and float types turn that (and any
value they can't parse) into null rather than throwing, so map those properties as nullable. Zero is a value, not an empty field.
Conventions
-
Create a model to represent a FileMaker layout. Set the name of the layout as the model table.
#[ORM\Entity(repositoryClass: KeywordRepository::class)] #[ORM\Table(name: 'Keyword')] class Keyword
-
In your model create an id field which is mapped to the special rec_id pseudo field
#[ORM\Column(name: 'rec_id', type: 'integer')] private ?int $id = null;
-
Create your 'actual' ID field, as used for relationships, as a separate property of your model. Usually your application assigns the key itself, for example a UUID generated in the constructor (using ramsey/uuid, say). It is sent to FileMaker with the INSERT, and needs nothing special:
#[ORM\Id] #[ORM\Column(name: '__pk_CanvasID', type: 'string', length: 255)] private string $uuid; public function __construct() { $this->uuid = Uuid::uuid4()->toString(); }
Keys which FileMaker assigns (a serial number, or an auto-enter Get(UUID)) are mapped with
#[ORM\GeneratedValue], and need the driver'sGeneratedKeyListenerregistered for Doctrine'sloadClassMetadataevent. The listener reads the key back from the record which was created, and converts it with the field's type, so a serial number arrives as an int. Without it Doctrine uses FileMaker's record id as the key. doctrine-filemaker-driver-bundle registers it for you (1.11 onwards); otherwise, with DoctrineBundle:# config/services.yaml services: MSDev\DoctrineFMDataAPIDriver\Id\GeneratedKeyListener: tags: [{ name: doctrine.event_listener, event: loadClassMetadata }]
#[ORM\Id] #[ORM\Column(name: 'InvoiceID', type: 'integer')] #[ORM\GeneratedValue] private ?int $id = null;
The listener applies
MSDev\DoctrineFMDataAPIDriver\Id\FMIdentityGeneratorto those keys. You can also map that generator yourself, with#[ORM\GeneratedValue(strategy: 'CUSTOM')]and#[ORM\CustomIdGenerator(class: FMIdentityGenerator::class)]. If you do, map the column withinsertable: false, so that Doctrine doesn't send an empty value which would replace the one FileMaker generates (if you forget, the generator tells you).If you'd rather use FileMaker's own record id as the identifier, map
rec_idas the id with#[ORM\GeneratedValue(strategy: 'IDENTITY')]. The listener leaves that alone. -
Add other properties as required. To access related fields on your layout enclose the field name in single quotes in the column mapping.
#[ORM\Column(name: "'absCon::email'", type: 'string', length: 255)] private ?string $contactEmail = null;
-
If you need access to the record modification ID you can add the special mod_id pseudo property
#[ORM\Column(name: 'mod_id', type: 'integer')] private ?int $modId = null;
-
If you need to know how many records matched the query which loaded a record, map the special rec_meta pseudo property. It holds JSON of the form
{"found": 12, "fetch": 5, "total": 340}: the number of records the query matched, the number returned (limited by the query's limit), and the total number of records in the table.#[ORM\Column(name: 'rec_meta', type: 'string', nullable: true)] private ?string $meta = null;
Considerations
- Because of the way in which more 'conventional' databases handle relationships, there is no concept of a portal. To access related data create a corresponding model for that table (layout) and create standard Doctrine relationships (OneToOne, OneToMany, ManyToOne etc).
- If your model contains calculation fields you will run into issues when trying to create a new record, since Doctrine will try and set those fields to null. One 'solution' to this is to create a 'stub' of your model which contains only the fields which are necessary to create a new record and to instantiate that for record creation. If you head down this route you'll likely want to create an interface which both your stub and your real entity implement so that you can typehint appropriately.
- If you wish to perform an IN query, then it needs to be the last
andWhereset in the query builder so that the previous conditions will be applied to all of the query objects which the Data API requires to simulate an IN query. COUNTqueries are supported (including$repository->count()), and are answered from the found count the Data API reports. Other aggregate functions,GROUP BYand joins aren't.- FileMaker has no transactions. To approximate them while a transaction is open (which includes the duration of every
flush()),UPDATEandDELETErequests are held back until the outermost transaction commits, and discarded if it rolls back. Nested transactions (wrapInTransaction(), savepoints) only discard their own writes.INSERTs are always sent immediately, because the record's key is needed straight away. A commit which fails part way through leaves the earlier writes in place.
Helper classes
These are available whatever your entities look like, and all take the Doctrine Connection.
$scripts = new ScriptAccess($connection); $scripts->executeScript('Layout', 'Script name', 'parameter'); // ['error' => ..., 'result' => ...] $scripts->performScript('Layout', $recordId, 'Script name', 'parameter', true); (new SetGlobals($connection))->setGlobals(['Table::gField' => 'value']); $containers = new ContainerAccess($connection, $scripts); $containers->performContainerInsert('Layout', $recordId, 'Field', '/path/to/file'); $containers->getStreamedContainerContent($url); // a container URL as returned in a Data API response $containers->getExternalContainerContent($path); // externally stored (e.g. Streaming_SSL) content
The Doctrine FileMaker bundle creates services for these, so they can be autowired.
Testing
The test suite runs the real Doctrine ORM on top of the driver with the Data API replaced by a mock, so it needs no FileMaker server.
composer install
vendor/bin/phpunit
The unit and integration suites never leave the process. The functional suite talks to a real FileMaker Server
and is skipped unless it is configured: host tests/Functional/Database/DoctrineFMTest.fmp12, copy
tests/Functional/.env.dist to tests/Functional/.env.local and set FM_HOST, then run
vendor/bin/phpunit --testsuite functional
See tests/Functional/Database/README.md for what the test database contains and how it is rebuilt.