Skip to content

Latest commit

 

History

History
95 lines (75 loc) · 2.93 KB

File metadata and controls

95 lines (75 loc) · 2.93 KB

ProcessWirePhpStormMeta

Generates .phpstorm.meta.php for ProcessWire API autocompletion in PhpStorm.

Configuration

Setting Type Default Description
metaFilePath string site/assets/.phpstorm.meta.php Path relative to PW root
generatePageClassFieldMeta bool false Field-type autocompletion per Page class
generateDebounceSeconds int 2 Min seconds between regenerations

CLI usage

Run via php index.php --at-eval 'CODE'.

Check status

php index.php --at-eval '
    $m = wire("modules")->get("ProcessWirePhpStormMeta");
    $f = wire("config")->paths->root . $m->get("metaFilePath");
    echo json_encode([
        "exists" => file_exists($f),
        "path" => $f,
        "modified" => is_file($f) ? date("Y-m-d H:i:s", filemtime($f)) : null,
        "config" => [
            "pageClassFieldMeta" => (bool) $m->get("generatePageClassFieldMeta"),
            "debounce" => (int) $m->get("generateDebounceSeconds"),
        ],
    ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
'

Regenerate

php index.php --at-eval 'wire("modules")->get("ProcessWirePhpStormMeta")->generateMetaFile();'

Read config

# All saved values
php index.php --at-eval '
    echo json_encode(
        wire("modules")->getConfig("ProcessWirePhpStormMeta"),
        JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
    );
'
# Single value
php index.php --at-eval 'echo wire("modules")->get("ProcessWirePhpStormMeta")->get("metaFilePath");'

Modify config (and regenerate)

php index.php --at-eval '
    wire("modules")->saveConfig("ProcessWirePhpStormMeta", [
        "generatePageClassFieldMeta" => true,
    ]);
    wire("modules")->get("ProcessWirePhpStormMeta")->generateMetaFile();
'

Hook: generateCustomMetaContent()

Injects custom PHP into the PHPSTORM_META {} namespace block. Multiple hooks concatenate.

$wire->addHookAfter("ProcessWirePhpStormMeta::generateCustomMetaContent", function($event) {
    $names = [];
    foreach (glob(wire()->config->paths->templates . "blocks/*.php") ?: [] as $f) {
        $names[] = pathinfo($f, PATHINFO_FILENAME);
    }
    sort($names);
    if (empty($names)) return;
    $custom = "\n    registerArgumentsSet(\"block_names\",\n";
    foreach ($names as $n) $custom .= "        \"{$n}\",\n";
    $custom .= "    );\n\n";
    $custom .= "    expectedArguments(\\ProcessWire\\renderBlock(), 0, argumentsSet(\"block_names\"));\n";
    $event->return .= $custom;
});

When the file regenerates

  • Field saved/deleted · Template saved/deleted · Module installed/uninstalled
  • "Regenerate Meta File" button in module settings

Notes

  • autoload = template=admin — only loads in admin.
  • Generated file is safe to commit (but overwritten on each regeneration).
  • For richer per-page property stubs, combine with AutoTemplateStubs.