| 1 | <?php |
||
| 2 | |||
| 3 | namespace Liberation; |
||
| 4 | |||
| 5 | use Illuminate\View\FileViewFinder; |
||
| 6 | use InvalidArgumentException; |
||
| 7 | |||
| 8 | class Liberation |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * callStatic |
||
| 12 | * |
||
| 13 | * @param $name |
||
| 14 | * @param $arguments |
||
| 15 | * @return string |
||
| 16 | * @throws \Illuminate\Contracts\Container\BindingResolutionException |
||
| 17 | */ |
||
| 18 | public static function __callStatic($name, $arguments) |
||
| 19 | { |
||
| 20 | $app = app(); |
||
| 21 | $view = view(); |
||
| 22 | |||
| 23 | if (count($arguments) === 0) { |
||
| 24 | throw new InvalidArgumentException(); |
||
| 25 | } |
||
| 26 | |||
| 27 | $fileName = $arguments[0]; |
||
| 28 | $params = $arguments[1] ?? []; |
||
| 29 | $orgFinder = $view->getFinder(); |
||
| 30 | $sqlPath = resource_path() . '/' . $name; |
||
| 31 | |||
| 32 | $newFinder = new FileViewFinder($app['files'], [$sqlPath]); |
||
| 33 | $view->setFinder($newFinder); |
||
| 34 | $view->addExtension($name, 'blade'); |
||
| 35 | $obj = $view->make($fileName, $params); |
||
| 36 | |||
| 37 | $result = $obj->render(); |
||
| 38 | $view->setFinder($orgFinder); |
||
| 39 | |||
| 40 | return $result; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 41 | } |
||
| 42 | } |
||
| 43 |