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
This commit is contained in:
Developer
2026-04-20 20:03:18 -04:00
parent 168e8f5909
commit da10729635
2 changed files with 32 additions and 8 deletions
+16 -4
View File
@@ -3,10 +3,22 @@
# Part of Server Toolkit - Phase 2: Analysis # Part of Server Toolkit - Phase 2: Analysis
# Dependencies: lib/php-detector.sh, lib/system-detect.sh # Dependencies: lib/php-detector.sh, lib/system-detect.sh
# Source required libraries # Source guard - prevent re-sourcing (but allow re-initialization if needed)
_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" if [ -n "${_PHP_ANALYZER_LOADED:-}" ]; then
source "$_LIB_DIR/php-detector.sh" 2>/dev/null || { echo "ERROR: php-detector.sh not found"; return 1; } return 0
source "$_LIB_DIR/system-detect.sh" 2>/dev/null || { echo "ERROR: system-detect.sh not found"; return 1; } 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 # HELPER FUNCTIONS - PURE BASH OPTIMIZATIONS
+16 -4
View File
@@ -9,10 +9,22 @@
# - Safe allocation buffers based on traffic stability # - Safe allocation buffers based on traffic stability
################################################################################ ################################################################################
# Dependencies # Source guard - prevent re-sourcing
_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" if [ -n "${_PHP_CALCULATOR_LOADED:-}" ]; then
source "$_LIB_DIR/php-detector.sh" 2>/dev/null || { echo "ERROR: php-detector.sh not found"; return 1; } return 0
source "$_LIB_DIR/system-detect.sh" 2>/dev/null || { echo "ERROR: system-detect.sh not found"; return 1; } 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 # HELPER FUNCTION - Extract field from pipe-delimited string