From 2e0a829e06cad89ccdb7c79e997f5c7924ccf9a7 Mon Sep 17 00:00:00 2001 From: Vladimir Bryzgalov Date: Fri, 17 Apr 2026 23:02:53 +0500 Subject: [PATCH] =?UTF-8?q?docs+tests:=20fix=20autoloader=20=E2=80=94=20un?= =?UTF-8?q?derscores=20=E2=86=92=20hyphens=20+=20slug=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The regex '/([a-z0-9])([A-Z])/' does not split on underscores, so Interface_Spam_Source, Settings_Page, Dashboard_Widget stayed as 'interface_spam_source', 'settings_page', 'dashboard_widget' after strtolower — no file matched. Added str_replace('_', '-', ...). Then Interface_Spam_Source's slug became 'interface-spam-source', and the candidate 'includes/sources/interface-' . \$slug doubled the prefix into 'interface-interface-spam-source.php'. Replaced that candidate family with a slug-as-filename fallback that maps interface-* slugs directly to their files. Sanity check on plugin bootstrap: 17/17 classes/interfaces resolve. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../plans/2026-04-17-cf7-spam-to-telegram.md | 14 +++++++++++--- tests/bootstrap.php | 4 +++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/superpowers/plans/2026-04-17-cf7-spam-to-telegram.md b/docs/superpowers/plans/2026-04-17-cf7-spam-to-telegram.md index 39c4214..ca72e88 100644 --- a/docs/superpowers/plans/2026-04-17-cf7-spam-to-telegram.md +++ b/docs/superpowers/plans/2026-04-17-cf7-spam-to-telegram.md @@ -127,8 +127,10 @@ spl_autoload_register(static function (string $class): void { return; } $relative = substr($class, strlen('Cf7stg\\')); - // Turn "PhoneParser" into "phone-parser" + // Turn "PhoneParser" into "phone-parser"; also normalize underscores + // ("Settings_Page" → "settings-page"). $slug = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1-$2', $relative)); + $slug = str_replace('_', '-', $slug); $path = __DIR__ . '/../includes/class-' . $slug . '.php'; if (is_file($path)) { require_once $path; @@ -2293,12 +2295,18 @@ final class Plugin if (strpos($class, 'Cf7stg\\') !== 0) return; $relative = substr($class, strlen('Cf7stg\\')); $slug = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1-$2', $relative)); + // Class names may use underscores (Settings_Page, Interface_Spam_Source); + // normalize both word-boundary conventions to hyphens. + $slug = str_replace('_', '-', $slug); $candidates = [ dirname(__DIR__) . '/includes/class-' . $slug . '.php', dirname(__DIR__) . '/includes/sources/class-' . $slug . '.php', - dirname(__DIR__) . '/includes/sources/interface-' . $slug . '.php', - dirname(__DIR__) . '/includes/interface-' . $slug . '.php', dirname(__DIR__) . '/admin/class-' . $slug . '.php', + // Fallback: treat slug as full filename (for Interface_* classes + // whose slug already becomes 'interface-xxx'). + dirname(__DIR__) . '/includes/' . $slug . '.php', + dirname(__DIR__) . '/includes/sources/' . $slug . '.php', + dirname(__DIR__) . '/admin/' . $slug . '.php', ]; foreach ($candidates as $path) { if (is_file($path)) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 421a14f..6c517e0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -8,8 +8,10 @@ spl_autoload_register(static function (string $class): void { return; } $relative = substr($class, strlen('Cf7stg\\')); - // Turn "PhoneParser" into "phone-parser" + // Turn "PhoneParser" into "phone-parser"; also normalize underscores + // ("Settings_Page" → "settings-page"). $slug = strtolower(preg_replace('/([a-z0-9])([A-Z])/', '$1-$2', $relative)); + $slug = str_replace('_', '-', $slug); $path = __DIR__ . '/../includes/class-' . $slug . '.php'; if (is_file($path)) { require_once $path;