Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jplana-ubc authored Feb 13, 2021
1 parent 1da1705 commit e9738da
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Solutions/MakeViewVariableOptionalSolution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Facade\IgnitionContracts\RunnableSolution;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Str;

class MakeViewVariableOptionalSolution implements RunnableSolution
{
Expand Down Expand Up @@ -71,8 +72,24 @@ public function run(array $parameters = [])
}
}

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

return true;
}

public function makeOptional(array $parameters = [])
{
if (!$this->isSafePath($parameters['viewFile'])) {
return false;
}

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

Expand Down

0 comments on commit e9738da

Please sign in to comment.