From da107296355335bdcd3e9cc3e8b1b6153ea297da Mon Sep 17 00:00:00 2001 From: Developer Date: Mon, 20 Apr 2026 20:03:18 -0400 Subject: [PATCH] FIX: Add source guards to library files to prevent re-sourcing php-analyzer.sh and php-calculator-improved.sh were trying to re-source dependencies when sourced from other scripts, causing 'not found' errors. Added: - _PHP_ANALYZER_LOADED source guard - _PHP_CALCULATOR_LOADED source guard - Conditional checks for dependency sourcing - Prevents double-sourcing of php-detector.sh and system-detect.sh --- lib/php-analyzer.sh | 20 ++++++++++++++++---- lib/php-calculator-improved.sh | 20 ++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/php-analyzer.sh b/lib/php-analyzer.sh index 7ac49ce..293b055 100644 --- a/lib/php-analyzer.sh +++ b/lib/php-analyzer.sh @@ -3,10 +3,22 @@ # Part of Server Toolkit - Phase 2: Analysis # Dependencies: lib/php-detector.sh, lib/system-detect.sh -# Source required libraries -_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$_LIB_DIR/php-detector.sh" 2>/dev/null || { echo "ERROR: php-detector.sh not found"; return 1; } -source "$_LIB_DIR/system-detect.sh" 2>/dev/null || { echo "ERROR: system-detect.sh not found"; return 1; } +# Source guard - prevent re-sourcing (but allow re-initialization if needed) +if [ -n "${_PHP_ANALYZER_LOADED:-}" ]; then + return 0 +fi +readonly _PHP_ANALYZER_LOADED=1 + +# Source required libraries only if not already loaded +if [ -z "${_PHP_DETECTOR_LOADED:-}" ]; then + _LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + source "$_LIB_DIR/php-detector.sh" 2>/dev/null || { echo "ERROR: php-detector.sh not found"; return 1; } +fi + +if [ -z "${_SYSTEM_DETECT_LOADED:-}" ]; then + _LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + source "$_LIB_DIR/system-detect.sh" 2>/dev/null || { echo "ERROR: system-detect.sh not found"; return 1; } +fi # ============================================================================ # HELPER FUNCTIONS - PURE BASH OPTIMIZATIONS diff --git a/lib/php-calculator-improved.sh b/lib/php-calculator-improved.sh index b33350f..ca60dd4 100644 --- a/lib/php-calculator-improved.sh +++ b/lib/php-calculator-improved.sh @@ -9,10 +9,22 @@ # - Safe allocation buffers based on traffic stability ################################################################################ -# Dependencies -_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$_LIB_DIR/php-detector.sh" 2>/dev/null || { echo "ERROR: php-detector.sh not found"; return 1; } -source "$_LIB_DIR/system-detect.sh" 2>/dev/null || { echo "ERROR: system-detect.sh not found"; return 1; } +# Source guard - prevent re-sourcing +if [ -n "${_PHP_CALCULATOR_LOADED:-}" ]; then + return 0 +fi +readonly _PHP_CALCULATOR_LOADED=1 + +# Dependencies - only source if not already loaded +if [ -z "${_PHP_DETECTOR_LOADED:-}" ]; then + _LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + source "$_LIB_DIR/php-detector.sh" 2>/dev/null || { echo "ERROR: php-detector.sh not found"; return 1; } +fi + +if [ -z "${_SYSTEM_DETECT_LOADED:-}" ]; then + _LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + source "$_LIB_DIR/system-detect.sh" 2>/dev/null || { echo "ERROR: system-detect.sh not found"; return 1; } +fi # ============================================================================ # HELPER FUNCTION - Extract field from pipe-delimited string