diff --git a/src/Control/Director.php b/src/Control/Director.php index 8b85e1fee..51827f628 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -365,12 +365,13 @@ class Director implements TemplateGlobalProvider }; break; } - +$start = time(); // Call the handler with the configured middlewares $response = $this->callMiddleware($request, $handler); - +$end = time(); // Note that if a different request was previously registered, this will now be lost // In these cases it's better to use Kernel::nest() prior to kicking off a nested request + $elapsed = $end - $start; Injector::inst()->unregisterNamedObject(HTTPRequest::class); return $response; diff --git a/src/Control/Middleware/HTTPMiddlewareAware.php b/src/Control/Middleware/HTTPMiddlewareAware.php index e7e861898..36ff486c1 100644 --- a/src/Control/Middleware/HTTPMiddlewareAware.php +++ b/src/Control/Middleware/HTTPMiddlewareAware.php @@ -54,12 +54,21 @@ trait HTTPMiddlewareAware */ protected function callMiddleware(HTTPRequest $request, callable $last) { + $classes = array_map(function ($middle) { + return get_class($middle); + }, $this->getMiddlewares()); + + // Reverse middlewares $next = $last; /** @var HTTPMiddleware $middleware */ foreach (array_reverse($this->getMiddlewares()) as $middleware) { $next = function ($request) use ($middleware, $next) { - return $middleware->process($request, $next); + $start = time(); + $value = $middleware->process($request, $next); + $end = time(); + $elapsed = $end - $start; + return $value; }; } return $next($request); diff --git a/src/Core/Extensible.php b/src/Core/Extensible.php index 805aab2dd..b8e2c7fe7 100644 --- a/src/Core/Extensible.php +++ b/src/Core/Extensible.php @@ -388,8 +388,9 @@ trait Extensible if (!$strict && is_subclass_of($extension, $requiredExtension)) { return true; } - if (Injector::inst()->get($extension) instanceof $requiredExtension) { - return true; + $inst = Injector::inst()->get($extension); + if ($inst instanceof $requiredExtension) { + return $strict ? get_class($inst) === $requiredExtension : true; } } diff --git a/tests/php/Core/ObjectTest.php b/tests/php/Core/ObjectTest.php index 886a5cd0a..b3971e987 100644 --- a/tests/php/Core/ObjectTest.php +++ b/tests/php/Core/ObjectTest.php @@ -11,6 +11,7 @@ use SilverStripe\Core\Tests\ObjectTest\ExtendTest1; use SilverStripe\Core\Tests\ObjectTest\ExtendTest2; use SilverStripe\Core\Tests\ObjectTest\ExtendTest3; use SilverStripe\Core\Tests\ObjectTest\ExtendTest4; +use SilverStripe\Core\Tests\ObjectTest\ExtendTest5; use SilverStripe\Core\Tests\ObjectTest\ExtensionRemoveTest; use SilverStripe\Core\Tests\ObjectTest\ExtensionTest; use SilverStripe\Core\Tests\ObjectTest\ExtensionTest2; @@ -289,6 +290,13 @@ class ObjectTest extends SapphireTest $objectTest_ExtensionTest->hasExtension(ExtendTest3::class), "Extensions are detected with instance hasExtension() when added through add_extension()" ); + + // load in a custom implementation + Injector::inst()->registerService(new ExtendTest5(), ExtendTest4::class); + $this->assertTrue( + ExtensionTest3::has_extension(ExtendTest5::class), + "Injected sub-extensions are detected with static has_extension() when added through add_extension()" + ); // @todo At the moment, this does NOT remove the extension due to parameterized naming, // meaning the extension will remain added in further test cases diff --git a/tests/php/Core/ObjectTest/ExtendTest5.php b/tests/php/Core/ObjectTest/ExtendTest5.php new file mode 100644 index 000000000..814c192b7 --- /dev/null +++ b/tests/php/Core/ObjectTest/ExtendTest5.php @@ -0,0 +1,11 @@ +