Add 100+ automated unit tests from .expect file specifications Add session system test Add rsx:constants:regenerate command test Add rsx:logrotate command test Add rsx:clean command test Add rsx:manifest:stats command test Add model enum system test Add model mass assignment prevention test Add rsx:check command test Add migrate:status command test 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
93 lines
2.8 KiB
PHP
93 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\RSpade\Upstream;
|
|
|
|
/**
|
|
* Tracks framework refactoring operations for future migration to user projects
|
|
*
|
|
* When framework developers rename classes or methods in /app/RSpade, these operations
|
|
* are logged to refactor.list files. Future rsx:refactor:apply_upstream_refactors
|
|
* command will replay these on user projects when they update the framework.
|
|
*/
|
|
class RefactorLog
|
|
{
|
|
/**
|
|
* Log a refactor operation to the refactor.list file
|
|
*
|
|
* @param string $command The artisan command that was executed
|
|
* @param string $source_file The framework file that was refactored (relative to /var/www/html)
|
|
*/
|
|
public static function log_refactor(string $command, string $source_file): void
|
|
{
|
|
$base_path = base_path();
|
|
|
|
// Ensure source file is relative to base path
|
|
if (str_starts_with($source_file, $base_path)) {
|
|
$source_file = substr($source_file, strlen($base_path) + 1);
|
|
}
|
|
|
|
// Only log refactors for files in app/RSpade
|
|
if (!str_starts_with($source_file, 'app/RSpade/')) {
|
|
return;
|
|
}
|
|
|
|
// Get directory of the refactored file
|
|
$dir = dirname($base_path . '/' . $source_file);
|
|
$refactor_list_file = $dir . '/refactor.list';
|
|
|
|
// Create log entry with timestamp
|
|
$timestamp = date('Y-m-d H:i:s');
|
|
$log_entry = "[$timestamp] $command\n";
|
|
|
|
// Append to refactor.list file
|
|
file_put_contents($refactor_list_file, $log_entry, FILE_APPEND);
|
|
}
|
|
|
|
/**
|
|
* Check if a file has been tracked for refactoring
|
|
*
|
|
* @param string $file_path Path to check
|
|
* @return bool
|
|
*/
|
|
public static function has_refactor_log(string $file_path): bool
|
|
{
|
|
$dir = dirname($file_path);
|
|
return file_exists($dir . '/refactor.list');
|
|
}
|
|
|
|
/**
|
|
* Get all refactor operations for a directory
|
|
*
|
|
* @param string $directory_path Directory to check
|
|
* @return array Array of refactor commands
|
|
*/
|
|
public static function get_refactor_operations(string $directory_path): array
|
|
{
|
|
$refactor_list_file = rtrim($directory_path, '/') . '/refactor.list';
|
|
|
|
if (!file_exists($refactor_list_file)) {
|
|
return [];
|
|
}
|
|
|
|
$contents = file_get_contents($refactor_list_file);
|
|
$lines = explode("\n", trim($contents));
|
|
|
|
$operations = [];
|
|
foreach ($lines as $line) {
|
|
if (empty($line)) {
|
|
continue;
|
|
}
|
|
|
|
// Parse: [2025-10-07 02:00:00] command here
|
|
if (preg_match('/^\[(.*?)\]\s+(.+)$/', $line, $matches)) {
|
|
$operations[] = [
|
|
'timestamp' => $matches[1],
|
|
'command' => $matches[2],
|
|
];
|
|
}
|
|
}
|
|
|
|
return $operations;
|
|
}
|
|
}
|