Skip to content

Commit

Permalink
Fix named arguments when using facade (#1002)
Browse files Browse the repository at this point in the history
* Fix named arguments when using facade

* test multiple simultaneous pdf instances
  • Loading branch information
erikn69 authored Sep 28, 2023
1 parent 3dbe06b commit a8bd9d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
24 changes: 1 addition & 23 deletions src/Facade/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,6 @@ public static function __callStatic($method, $args)
{
$instance = static::$app->make(static::getFacadeAccessor());

switch (count($args)) {
case 0:
return $instance->$method();

case 1:
return $instance->$method($args[0]);

case 2:
return $instance->$method($args[0], $args[1]);

case 3:
return $instance->$method($args[0], $args[1], $args[2]);

case 4:
return $instance->$method($args[0], $args[1], $args[2], $args[3]);

default:
$callable = [$instance, $method];
if (! is_callable($callable)) {
throw new \UnexpectedValueException("Method PDF::{$method}() does not exist.");
}
return call_user_func_array($callable, $args);
}
return $instance->$method(...$args);
}
}
12 changes: 12 additions & 0 deletions tests/PdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,16 @@ public function testSave(): void
$this->assertNotEmpty($content);
$this->assertEquals($content, $pdf->output());
}

public function testMultipleInstances(): void
{
$pdf1 = Facade\Pdf::loadHtml('<h1>Test</h1>');
$pdf2 = Facade\Pdf::loadHtml('<h1>Test</h1>');

$pdf1->getDomPDF()->setBaseHost('host1');
$pdf2->getDomPDF()->setBaseHost('host2');

$this->assertEquals('host1', $pdf1->getDomPDF()->getBaseHost());
$this->assertEquals('host2', $pdf2->getDomPDF()->getBaseHost());
}
}

0 comments on commit a8bd9d9

Please sign in to comment.