The Game Panel Design record
The Game Panel
ADR-0021 Accepted

All Route all file access goes through Flysystem

Comparing
v1 to v2
Current
Read the document

Context

The engine engine reads files. Configuration loading is the only thing part of it that touches one today, , through PHP's own functions functions and a path taken from Paths. More follows will follow as components land: cached content, the the engine's own data, and the the compiled output that PHP includes, which it the engine will write as well as read.

A path only means anything where the files are on local disk. Some of what the engine keeps keeps could sit elsewhere: , such as configuration in object storage, storage or cached content in a database table, where no host path path exists. Anything that that hands out a path lets its consumers come to depend on local disk, and nothing but review would would notice.

PHP's include is the exception. An includable, opcached A file that is included and opcached has to be a real file at a real path.

Decision

Every I will route every file the engine engine reads or writes goes through Flysystem. Filesystems are will be constructed by whatever composes the the engine and handed in fully formed, and nothing exposes will expose a filesystem path at at runtime. Consumers are , and consumers will be given Flysystem's s own FilesystemOperator rather than a wrapper the engine owns. A path will be kept only where PHP's own include is involved: the modules directory, not an enginefor Composer-owned wrapper around itbased discovery and autoloading; the compiled directory, for compiled templates and module metadata; and the log directory, which is where Monolog writes.

A path is kept only where PHP's own include is involved: the modules directory, for Composer-based discovery and autoloading; the compiled directory, for compiled templates and module metadata; and the log directory, which is where Monolog writes.

Alternatives

PHP's file functions with a path, as the engine engine uses today. A consumer can could come to depend depend on local disk, and a a filesystem backed by object storage or a database table has would have no path to give it, so . I rejected this because substitutability would rest on on review rather than on the type.

An engine-owned interface the engine owns, wrapping Flysystem. It I rejected this because it would cost twenty-one delegating delegating methods, kept in step with a a library that already has them, and module because module authors work work with filesystems directly, so the type they already know is is the one to expose.

Whether any other library was weighed against Flysystem is not recorded.

Consequences

Easier:

  • A filesystem can will be backed by anything Flysystem supports without any consumer noticing, because no consumer can obtain a path. Configuration can will be loaded loadable with every filesystem in memory, touching no disk at all.
  • Flysystem's own guarantees will carry through: its path normaliser rejects path traversal and control characters, and its FilesystemException is a marker interface, which is the convention the engine's s components already follow.
  • Module Module authors will meet a type they already know.

Harder:

  • Every filesystem has will have to be constructed by whatever composes the engine and handed in. . There is no composition root root yet, so until there is, tests will construct them, as they already construct Paths.
  • Anything that wants a real path has will have to justify itself against the include rule. Compiled output is separated from will be kept apart from cached content so that the rule needs no exceptions.

Constrained:

  • league/flysystem becomes will become a dependency of the binary, with league/flysystem-local and league/mime-type-detection behind it, and an adapter for each backend it uses.
  • Local paths will remain in three places only: modules, compiled output and logs.
  • A remote adapter holds a connection, so whatever adds the first one inherits will inherit the question of how long a filesystem a filesystem lives.

Sources

  • Issue #71, Engine - Filesystems, and not edited since: the decision, which is both created and decided. It records every file going through Flysystem, filesystems handed in fully formed, nothing exposing a path at runtime, FilesystemOperator returned rather than a wrapper and why, the three places a path is kept and why each is one, Flysystem's weight and its guarantees, and the lifetime question a remote adapter would bring.
  • Issue #72, Engine - Filesystems - Catalogue, , edited on only to replace names with issue links: the same reasoning for returning FilesystemOperator, and Flysystem's guarantees carrying through unchanged.
  • Issue #74, Engine - Filesystems - TomlLoader migration, , edited on only to replace names with issue links: loading configuration with every filesystem in memory and no disk access as the property that proves nothing depends on a local path.

Source adr/0021-flysystem-only.md · commit 9444a99 · published