Files
cf7-spam-to-telegram/tests/bootstrap.php
T
Vladimir Bryzgalov 2e0a829e06 docs+tests: fix autoloader — underscores → hyphens + slug fallback
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) <noreply@anthropic.com>
2026-04-17 23:02:53 +05:00

37 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
// Simple autoloader that mirrors the runtime plugin autoloader,
// mapping Cf7stg\ClassName → includes/class-class-name.php
spl_autoload_register(static function (string $class): void {
if (strpos($class, 'Cf7stg\\') !== 0) {
return;
}
$relative = substr($class, strlen('Cf7stg\\'));
// 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;
}
});
// Minimal shims for functions used by pure-logic classes when WP is absent.
if (!function_exists('apply_filters')) {
function apply_filters($tag, $value) { return $value; }
}
if (!function_exists('esc_html')) {
function esc_html($s) { return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
}
if (!function_exists('esc_url')) {
function esc_url($s) { return filter_var((string)$s, FILTER_SANITIZE_URL); }
}
if (!function_exists('wp_strip_all_tags')) {
function wp_strip_all_tags($s) { return trim(strip_tags((string)$s)); }
}
if (!function_exists('__')) {
function __($text) { return $text; }
}