Skip to content

Commit

Permalink
Don't resolve driver until needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed May 23, 2022
1 parent 6bdeb5c commit e6f93d8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All Notable changes to `pbmedia/laravel-ffmpeg` will be documented in this file

## 8.1.2 - 2022-05-23

- Don't resolve driver until needed.

## 8.1.1 - 2022-05-13

- Bugfix for parsing the average frame rate.
Expand Down
21 changes: 17 additions & 4 deletions src/Support/MediaOpenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@ class MediaOpenerFactory

private $defaultDisk;
private $driver;
private $driverResolver;

public function __construct(string $defaultDisk, PHPFFMpeg $driver)
public function __construct(string $defaultDisk, PHPFFMpeg $driver = null, callable $driverResolver = null)
{
$this->defaultDisk = $defaultDisk;
$this->driver = $driver;
$this->defaultDisk = $defaultDisk;
$this->driver = $driver;
$this->driverResolver = $driverResolver;
}

private function driver(): PHPFFMpeg
{
if ($this->driver) {
return $this->driver;
}

$resolver = $this->driverResolver;

return $this->driver = $resolver();
}

public function new(): MediaOpener
{
return new MediaOpener($this->defaultDisk, $this->driver);
return new MediaOpener($this->defaultDisk, $this->driver());
}

public function dynamicHLSPlaylist(): DynamicHLSPlaylist
Expand Down
3 changes: 2 additions & 1 deletion src/Support/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public function register()
$this->app->singleton('laravel-ffmpeg', function () {
return new MediaOpenerFactory(
$this->app['config']->get('filesystems.default'),
$this->app->make(PHPFFMpeg::class)
null,
fn () => $this->app->make(PHPFFMpeg::class)
);
});
}
Expand Down

0 comments on commit e6f93d8

Please sign in to comment.