Skip to content

Commit

Permalink
Add view file creation solution
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRio committed Sep 1, 2019
1 parent 19a6bd9 commit f9ee08e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"facade/ignition-contracts": "^1.0",
"ext-json": "*",
"ext-mbstring": "*"
"symfony/filesystem": "^4.3",
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
Expand Down
6 changes: 4 additions & 2 deletions src/SolutionProviders/ViewNotFoundSolutionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Facade\IgnitionContracts\BaseSolution;
use Symfony\Component\Filesystem\Filesystem;
use Facade\Ignition\Exceptions\ViewException;
use Facade\Ignition\Support\StringComparator;
use Facade\Ignition\Solutions\CreateViewFileSolution;
use Facade\IgnitionContracts\HasSolutionsForThrowable;


class ViewNotFoundSolutionProvider implements HasSolutionsForThrowable
{
protected const REGEX = '/View \[(.*)\] not found/m';
Expand Down Expand Up @@ -42,8 +45,7 @@ public function getSolutions(Throwable $throwable): array
}

return [
BaseSolution::create("{$missingView} was not found.")
->setSolutionDescription('Are you sure the view exist and is a `.blade.php` file?'),
new CreateViewFileSolution($missingView)
];
}

Expand Down
62 changes: 62 additions & 0 deletions src/Solutions/CreateViewFileSolution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Facade\Ignition\Solutions;

use Illuminate\Support\Facades\Blade;
use Symfony\Component\Filesystem\Filesystem;
use Facade\IgnitionContracts\RunnableSolution;
use Illuminate\Support\Facades\View;

class CreateViewFileSolution implements RunnableSolution
{
private $viewFile;

public function __construct($viewName = null)
{
$this->viewName = $viewName;
}

public function getSolutionTitle(): string
{
return $this->viewName . ' was not found.';
}

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

public function getSolutionActionDescription(): string
{
return 'Are you sure the view exist and is a `.blade.php` file?';
}

public function getRunButtonText(): string
{
return 'Create file';
}

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

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

public function run(array $parameters = [])
{
$parts = explode('.', $parameters['viewName']);
$file = array_pop($parts);
$path = implode('/', $parts);
$fileViewFinder = View::getFinder();

$filesystem = new Filesystem();
$filesystem->mkdir($fileViewFinder->getPaths()[0] . '/' . $path . '/');
touch($fileViewFinder->getPaths()[0] . '/' . $path . '/' . $file . '.blade.php');
}
}

0 comments on commit f9ee08e

Please sign in to comment.