Mark PHP version compatibility fallback as legitimate in Php_Fixer

Add public directory asset support to bundle system
Fix PHP Fixer to replace ALL Rsx\ FQCNs with simple class names

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-10-30 17:18:10 +00:00
parent 6e41df0789
commit 8c8fb8e902
8 changed files with 720 additions and 121 deletions

View File

@@ -1383,7 +1383,34 @@ class Manifest
// Validate class names are unique.
static::__check_unique_base_class_names();
// Apply Php_Fixer to all PHP files in rsx/ and app/RSpade/ before parsing
// ==================================================================================
// PHP FIXER INTEGRATION POINT
// ==================================================================================
// This is where automatic code fixes are applied before Phase 2 parsing.
//
// WHAT PHP_FIXER DOES:
// 1. Fixes namespaces to match file paths
// 2. Removes/rebuilds use statements (strips Rsx\ and App\RSpade\ prefixes)
// 3. Replaces FQCNs like \Rsx\Models\User_Model with simple names User_Model
// 4. Adds #[Relationship] attributes to model ORM methods
// 5. Removes leading backslashes from attributes: #[\Route] → #[Route]
//
// SMART REBUILDING:
// - Tracks SHA1 hash of all class structures (ClassName:ParentClass)
// - If structure changed: Fixes ALL files (cascading updates needed)
// - If structure unchanged: Fixes ONLY $files_to_process (incremental)
//
// WHY BEFORE PHASE 2:
// - Phase 2 parses metadata from file content
// - If we fix AFTER parsing, manifest would have old/incorrect metadata
// - By fixing BEFORE, we parse the corrected content
//
// RE-PARSING LOOP BELOW:
// - If Php_Fixer modified files, we MUST re-parse them
// - This updates manifest with corrected namespace/class/FQCN data
// - Without this, manifest would reference old class locations
// ==================================================================================
$php_fixer_modified_files = [];
if (!app()->environment('production')) {
$php_fixer_modified_files = static::__run_php_fixer($files_to_process);
@@ -2282,6 +2309,29 @@ class Manifest
* Run Php_Fixer on all PHP files in rsx/ and app/RSpade/
* Called before Phase 2 parsing to ensure all files are fixed
*
* SMART REBUILD STRATEGY:
* This method implements an intelligent rebuild strategy to avoid unnecessary file writes:
*
* 1. STRUCTURE HASH: Creates SHA1 hash of "ClassName:ParentClass" for ALL classes
* - Detects when classes are added, removed, renamed, or inheritance changes
*
* 2. FULL REBUILD TRIGGERS:
* - New class added (may need new use statements elsewhere)
* - Class renamed (all references need updating)
* - Inheritance changed (may affect use statement resolution)
* When triggered: Fix ALL PHP files in rsx/ and app/RSpade/
*
* 3. INCREMENTAL REBUILD:
* - Structure hash unchanged (no new/renamed classes)
* - Only fixes files that actually changed on disk
* More efficient, avoids touching unchanged files
*
* WHY THIS MATTERS:
* - use statement management depends on knowing all available classes
* - FQCN replacement needs to check class name uniqueness
* - When class structure changes, files referencing those classes need updating
* - When structure stable, only changed files need processing
*
* @param array $changed_files List of changed files from Phase 1
* @return array List of files that were modified by Php_Fixer
*/
@@ -2289,7 +2339,14 @@ class Manifest
{
$modified_files = [];
// Build hash array of all PHP classes to detect structural changes
// ==================================================================================
// STEP 1: BUILD CLASS STRUCTURE HASH
// ==================================================================================
// Create a fingerprint of ALL classes in the codebase.
// Format: "path/to/file.php" => "ClassName:ParentClass"
// This lets us detect when the class structure itself changes (not just file contents)
// ==================================================================================
$class_structure_hash_data = [];
foreach (static::$data['data']['files'] as $file_path => $metadata) {
@@ -2311,12 +2368,24 @@ class Manifest
// Calculate hash of class structure
$new_class_structure_hash = sha1(json_encode($class_structure_hash_data));
// Check if class structure has changed
// ==================================================================================
// STEP 2: DECIDE REBUILD STRATEGY
// ==================================================================================
// Compare with previous hash to detect structural changes
// ==================================================================================
$previous_hash = static::$data['data']['php_fixer_hash'] ?? null;
$structure_changed = ($previous_hash !== $new_class_structure_hash);
if ($structure_changed) {
// Class structure changed - fix ALL PHP files in rsx/ and app/RSpade/
// ==================================================================================
// FULL REBUILD: Class structure changed
// ==================================================================================
// When class structure changes, we MUST fix ALL files because:
// - New classes may be referenced in existing files → need new use statements
// - Renamed classes need all references updated
// - Inheritance changes may affect use statement resolution
// ==================================================================================
$php_files_to_fix = [];
foreach (static::$data['data']['files'] as $file_path => $metadata) {
@@ -2340,10 +2409,19 @@ class Manifest
}
}
// Store updated hash
// Store updated hash for next rebuild comparison
static::$data['data']['php_fixer_hash'] = $new_class_structure_hash;
} else {
// Class structure unchanged - only fix changed PHP files with classes
// ==================================================================================
// INCREMENTAL REBUILD: Class structure unchanged
// ==================================================================================
// Only fix files that actually changed on disk.
// Safe because:
// - No new classes = no new use statements needed elsewhere
// - No renamed classes = no references to update
// - No inheritance changes = use statement resolution unchanged
// Result: Much faster, avoids touching 99% of files on typical edits
// ==================================================================================
$php_files_to_fix = [];
foreach ($changed_files as $file_path) {