Skip to content

Commit

Permalink
Fix facade::$app could be nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 committed Feb 29, 2024
1 parent 07ffb36 commit 30e1a46
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Facade/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Barryvdh\DomPDF\PDF as BasePDF;
use Illuminate\Support\Facades\Facade as IlluminateFacade;
use RuntimeException;

/**
* @method static BasePDF setBaseHost(string $baseHost)
Expand Down Expand Up @@ -43,14 +44,32 @@ protected static function getFacadeAccessor()
}

/**
* Resolve a new instance
* Get the application instance behind the facade.
*
* @return \Illuminate\Contracts\Foundation\Application|null
*/
public static function getFacadeApplication()
{
return static::$app;
}

/**
* Handle dynamic, static calls to the object.
*
* @param string $method
* @param array<mixed> $args
* @return mixed
*
* @throws \RuntimeException
*/
public static function __callStatic($method, $args)
{
$instance = static::$app->make(static::getFacadeAccessor());
$app = static::getFacadeApplication();
if (! $app) {
throw new RuntimeException('Facade application has not been set.');
}

$instance = $app->make(static::getFacadeAccessor());

return $instance->$method(...$args);
}
Expand Down

0 comments on commit 30e1a46

Please sign in to comment.