CLI Scripts

Place batch jobs in the script/ directory.

<?php
// script/cleanup.php
require_once '__flexagon.php';

$deleted = (new \ExampleUser\UserDAO())->deleteExpired();
echo "Deleted: {$deleted} rows\n";
php script/cleanup.php runtimeStage=production days=30

Arguments in key=value form are parsed into both $_PARAMS and $_REQUEST. runtimeStage is reserved and selects the configuration directory to load.

When running from the CLI, FLEXAGON_ENV::$_RUNTIME_ENV is set to RUNTIME_ENV_SCRIPT, bypassing the web request pipeline entirely, including sessions, routing, and output buffering.

Framework CLI

The framework itself provides two commands.

php script/flexagon.php init [--path=DIR] [--force]
php script/flexagon.php check [--path=DIR]
Invocation Supported installation types
php script/flexagon.php All (Composer · PHAR · source)
php vendor/bin/flexagon Composer installation

A PHAR cannot be passed to the PHP CLI as a phar://... script path, so script/flexagon.php acts as the entry point. The PHAR does not contain templates for init, so only check is available in that installation mode.

init

Creates the 34 files that make up the project structure. If you started with composer create-project flexagon/skeleton, these files already exist. This command is primarily useful when adding flexagon/framework to an existing project with composer require.

Existing files are left untouched. You can also run the command after an upgrade to add only newly introduced structure files.

create   script/flexagon.php
keep     public/index.php
1 created, 22 kept, 0 failed

Use --force if you need to overwrite existing files. Be careful: modified files will be replaced with the template versions.

check

Checks that the project layout and runtime configuration are consistent and returns exit code 1 when a problem is found, making it suitable for deployment pipelines.

Item Check Result
php 8.3 or later Error
ext-json · ext-openssl · ext-pdo Loaded Error
opcache.save_comments Enabled Error
project layout flexagon.php · application/_Global.php · public/__flexagon.php · public/_router.php Error
config placement _Config.php and application/ are not exposed under public/ or any public_* Error
bootstrap Framework boots successfully Error
session key $SESSION_ENCRYPTION_STRING length when $SESSION_AUTO_START is enabled Error
data sources Configured; no template placeholders remain Warning
display_errors Enabled in production mode Warning
secrets placement .env.php / .env under public/ or any public_* Error
.env.php Returns an array; not tracked by git Error
settings Keys in .env.example.php that are not set Warning
secrets in config A data source password written into _Config.php Warning
.env Present but not read by Flexagon Warning
opcache.file_cache On while .env.php exists (compiled secrets on disk) Warning

The following checks are especially important because these issues can otherwise fail silently.

  • If opcache.save_comments is disabled, @encrypt, @db_auto_timestamp, and @exclude_from_get_array are all ignored. A column that should be encrypted may be stored in plaintext without any exception.
  • If _Config.php is placed under public/, database credentials may be served directly if PHP handling is unavailable or misconfigured.
  • If a data source still contains the default username / dbname placeholders, the connection simply fails.
$ php script/flexagon.php check

  ok       php 8.3.33
  ok       ext-json
  ok       opcache.save_comments
  ok       project layout
  ok       bootstrap
  warn     data sources  default still contains template placeholders
  ok       session  auto start off
  ok       display_errors  off

  0 problem(s), 1 warning(s)