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