Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Extension/ExtendableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,13 @@ public static function extendableCallStatic($name, $params = null)

if (method_exists($extension, $name) && is_callable([$extension, $name])) {
$extension::$extendableStaticCalledClass = $className;
$result = forward_static_call_array(array($extension, $name), $params);
$extension::$extendableStaticCalledClass = null;
return $result;

try {
return forward_static_call_array(array($extension, $name), $params);
}
finally {
$extension::$extendableStaticCalledClass = null;
}
}
}

Expand Down
35 changes: 35 additions & 0 deletions tests/Extension/ExtendableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,41 @@ public function testGetExtensionParentClassOnExtendableTrait()
$this->assertEquals(Level1NonExtendable::class, $this->callProtectedMethod($level2NonExtendable, 'extensionGetParentClass')->getName());
$this->assertEquals(Level1NonExtendable::class, $this->callProtectedMethod($level3NonExtendable, 'extensionGetParentClass')->getName());
}

public function testStaticCalledClassIsClearedWhenAStaticExtensionMethodThrows()
{
try {
StaticThrowingHost::explode();
$this->fail('The exception from the extension should propagate.');
}
catch (\RuntimeException $ex) {
// Expected.
}

$this->assertNull(StaticThrowingExtension::$extendableStaticCalledClass);
}
}

class StaticThrowingHost
{
use ExtendableTrait;

public $implement = [StaticThrowingExtension::class];

public static function __callStatic($name, $params)
{
return self::extendableCallStatic($name, $params);
}
}

class StaticThrowingExtension
{
use \Winter\Storm\Extension\ExtensionTrait;

public static function explode()
{
throw new \RuntimeException('static extension failed');
}
}

class ExtendableRoot extends Extendable
Expand Down
Loading