Search by

matatirosoln / doctrine-fm-data-api-driver

matatirosolutions

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

Statistics

Installs: 1 880

Dependents: 0

Suggesters: 1

Stars: 3

Open Issues: 0

1.0.0 2026-11-25 18:24 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 own Symfony\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 with HttpClient::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 set timeout (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

  1. 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
  2. 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;
  3. 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's GeneratedKeyListener registered for Doctrine's loadClassMetadata event. 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\FMIdentityGenerator to 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 with insertable: 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_id as the id with #[ORM\GeneratedValue(strategy: 'IDENTITY')]. The listener leaves that alone.

  4. 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;
  5. 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;
  6. 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

  1. 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).
  2. 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.
  3. If you wish to perform an IN query, then it needs to be the last andWhere set 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.
  4. COUNT queries are supported (including $repository->count()), and are answered from the found count the Data API reports. Other aggregate functions, GROUP BY and joins aren't.
  5. FileMaker has no transactions. To approximate them while a transaction is open (which includes the duration of every flush()), UPDATE and DELETE requests 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.