adachsoft / code-operations-mql5
MQL5 code validation and MetaEditor runtime discovery for the AdachSoft Code Operations API.
Requires
- php: ^8.3
- adachsoft/code-operations-contracts: ^0.2
- adachsoft/command-executor-lib: ^2.4
Requires (Dev)
- adachsoft/php-code-style: ^0.9.0
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
adachsoft/code-operations-mql5 implements the shared adachsoft/code-operations-contracts API for MQL5 projects. It validates MQL5 syntax with MetaEditor and exposes the configured MetaEditor installations as runtimes.
Installation
Install the library with Composer:
composer require adachsoft/code-operations-mql5
Requirements
- PHP 8.3 or newer.
- MetaTrader 5 with MetaEditor installed on Windows.
- For WSL, PHP runs on Linux and the configured MetaEditor executable path ends in
.exe. - In WSL, project, temporary log, and optional include paths must be accessible below
/mnt/<drive>.
In WSL mode, the adapter maps /mnt/d/path/to/file.mq5 to D:\path\to\file.mq5 for MetaEditor. MetaEditor logs are read as UTF-16LE and parsed for compiler diagnostics. The process exit code is not used to determine validation success because MetaEditor may return an unreliable value.
Usage
<?php
declare(strict_types=1);
use AdachSoft\CodeOperationsContracts\ExecutionContextDto;
use AdachSoft\CodeOperationsMql5\MetaEditorInstallationDto;
use AdachSoft\CodeOperationsMql5\Mql5CodeOperations;
use AdachSoft\CodeOperationsMql5\Mql5RuntimeResolver;
use AdachSoft\CommandExecutorLib\SimpleCommandRunner;
$operations = new Mql5CodeOperations(
new Mql5RuntimeResolver([
new MetaEditorInstallationDto(
version: '5',
binaryPath: '/mnt/c/Program Files/OANDA TMS MT5 Terminal/MetaEditor64.exe',
includePath: '/mnt/c/Users/username/AppData/Roaming/MetaQuotes/Terminal/terminal-id',
),
]),
new SimpleCommandRunner(),
);
$context = new ExecutionContextDto(
projectPath: '/mnt/d/projects/my-mql5-project',
runtime: null,
timeoutSeconds: 60,
);
$result = $operations->validate($context);
When ExecutionContextDto::$paths is empty, validation selects all .mq5 files recursively, excluding .git, vendor, and node_modules. When paths are supplied, the adapter validates the selected relative .mq5 and .mqh files. A configured include directory is passed to MetaEditor with /inc.
Limitations
- Only the
validateoperation is supported. MetaEditor is invoked in syntax-check mode (/s), so no.ex5file is generated. test()andrun()throw the contract'sUnsupportedOperationException.- Projects must contain an
.mq5or.mqhfile to be supported.
Integration tests
The mql5 integration group uses the real MetaEditor when METAEDITOR_PATH is set. CODE_OPERATIONS_TMP must name an existing directory under /mnt/<drive>; temporary MQL5 projects are created there. Without METAEDITOR_PATH, the integration tests are skipped. The default vendor/bin/phpunit run includes this group.
To run the integration group explicitly in WSL:
METAEDITOR_PATH='/mnt/c/Program Files/OANDA TMS MT5 Terminal/MetaEditor64.exe' \
CODE_OPERATIONS_TMP='/mnt/d/tmp/code-operations' \
vendor/bin/phpunit --group mql5