403Webshell
Server IP : 35.80.110.71  /  Your IP : 216.73.216.221
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.3.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/client-portal-laravel/backup/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/client-portal-laravel/backup/scripts/migrate-casts.php
<?php

/**
 * Migrate models from protected $casts property to casts() method.
 *
 * Usage: php scripts/migrate-casts.php [--dry-run]
 */

$dryRun = in_array('--dry-run', $argv);
$modelsDir = __DIR__ . '/../app/Models';

$files = glob($modelsDir . '/*.php');
$converted = 0;
$skipped = 0;
$errors = [];

foreach ($files as $file) {
    $content = file_get_contents($file);
    $filename = basename($file);

    // Skip if already using casts() method
    if (preg_match('/protected\s+function\s+casts\s*\(\s*\)\s*:\s*array/', $content)) {
        echo "SKIP (already modern): $filename\n";
        $skipped++;
        continue;
    }

    // Skip if no $casts property
    if (!preg_match('/protected\s+\$casts\s*=/', $content)) {
        echo "SKIP (no casts): $filename\n";
        $skipped++;
        continue;
    }

    // Match the protected $casts property with its array contents
    // This handles multi-line arrays with various formatting
    $pattern = '/(?<indent>[ \t]*)protected\s+\$casts\s*=\s*\[(?<contents>[^\]]*)\];/s';

    if (preg_match($pattern, $content, $matches)) {
        $indent = $matches['indent'];
        $arrayContents = $matches['contents'];

        // Build the new casts() method
        $newMethod = "{$indent}protected function casts(): array\n";
        $newMethod .= "{$indent}{\n";
        $newMethod .= "{$indent}    return [{$arrayContents}];\n";
        $newMethod .= "{$indent}}";

        // Replace the old property with the new method
        $newContent = preg_replace($pattern, $newMethod, $content);

        if ($newContent !== $content) {
            if ($dryRun) {
                echo "WOULD CONVERT: $filename\n";
            } else {
                file_put_contents($file, $newContent);
                echo "CONVERTED: $filename\n";
            }
            $converted++;
        } else {
            $errors[] = "Failed to convert: $filename";
        }
    } else {
        $errors[] = "Pattern not matched: $filename";
    }
}

echo "\n";
echo "Summary:\n";
echo "  Converted: $converted\n";
echo "  Skipped: $skipped\n";
echo "  Errors: " . count($errors) . "\n";

if (!empty($errors)) {
    echo "\nErrors:\n";
    foreach ($errors as $error) {
        echo "  - $error\n";
    }
}

if ($dryRun) {
    echo "\n(Dry run - no files were modified)\n";
}

Youez - 2016 - github.com/yon3zu
LinuXploit