From c4024d299d928f631ce8fa86639b1116fe3fe5af Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Wed, 22 Apr 2026 14:28:59 +0200 Subject: [PATCH 1/3] Backport CMS features --- src/PreloadManager.php | 8 ++- src/PreloadManagerInterface.php | 104 ++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 src/PreloadManagerInterface.php diff --git a/src/PreloadManager.php b/src/PreloadManager.php index 979efa9..1b89bf1 100644 --- a/src/PreloadManager.php +++ b/src/PreloadManager.php @@ -18,7 +18,7 @@ * * @since 2.0.0 */ -class PreloadManager +class PreloadManager implements PreloadManagerInterface { /** * The link provider @@ -57,13 +57,15 @@ public function getLinkProvider(): EvolvableLinkProviderInterface * * @param EvolvableLinkProviderInterface $linkProvider The link provider * - * @return void + * @return $this * * @since 2.0.0 */ - public function setLinkProvider(EvolvableLinkProviderInterface $linkProvider): void + public function setLinkProvider(EvolvableLinkProviderInterface $linkProvider): self { $this->linkProvider = $linkProvider; + + return $this; } /** diff --git a/src/PreloadManagerInterface.php b/src/PreloadManagerInterface.php new file mode 100644 index 0000000..46be892 --- /dev/null +++ b/src/PreloadManagerInterface.php @@ -0,0 +1,104 @@ + true)", "array('crossorigin' => 'use-credentials')") + * + * @return void + * + * @since 4.1.0 + */ + public function preload(string $uri, array $attributes = []); + + /** + * Resolves a resource origin as early as possible. + * + * @param string $uri A public path + * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") + * + * @return void + * + * @since 4.1.0 + */ + public function dnsPrefetch(string $uri, array $attributes = []); + + /** + * Initiates an early connection to a resource (DNS resolution, TCP handshake, TLS negotiation). + * + * @param string $uri A public path + * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") + * + * @return void + * + * @since 4.1.0 + */ + public function preconnect(string $uri, array $attributes = []); + + /** + * Indicates to the client that it should prefetch this resource. + * + * @param string $uri A public path + * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") + * + * @return void + * + * @since 4.1.0 + */ + public function prefetch(string $uri, array $attributes = []); + + /** + * Indicates to the client that it should prerender this resource. + * + * @param string $uri A public path + * @param array $attributes The attributes of this link (e.g. "array('as' => true)", "array('pr' => 0.5)") + * + * @return void + * + * @since 4.1.0 + */ + public function prerender(string $uri, array $attributes = []); +} From 64d81f56d5bd96e0351823870056ae79e24d4f92 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Wed, 22 Apr 2026 14:35:28 +0200 Subject: [PATCH 2/3] Reduce requirement for psr/link to 1.1/2.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 69a5c66..bdee0ef 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require": { "php": "^8.3.0", "fig/link-util": "^1.0", - "psr/link": "^2.0" + "psr/link": "^1.1|^2.0" }, "require-dev": { "joomla/application": "^4.0", From f99d2425eeefc351a8d3a624be06e44d21b24db3 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Wed, 22 Apr 2026 20:50:34 +0200 Subject: [PATCH 3/3] Some fixes --- src/PreloadManagerInterface.php | 4 ---- tests/EventListener/PreloadSubscriberTest.php | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PreloadManagerInterface.php b/src/PreloadManagerInterface.php index 46be892..db20a4d 100644 --- a/src/PreloadManagerInterface.php +++ b/src/PreloadManagerInterface.php @@ -11,10 +11,6 @@ use Psr\Link\EvolvableLinkProviderInterface; -// phpcs:disable PSR1.Files.SideEffects -\defined('_JEXEC') or die; -// phpcs:enable PSR1.Files.SideEffects - /** * Joomla! Preload Manager Interface * diff --git a/tests/EventListener/PreloadSubscriberTest.php b/tests/EventListener/PreloadSubscriberTest.php index 05003b3..8a63b34 100644 --- a/tests/EventListener/PreloadSubscriberTest.php +++ b/tests/EventListener/PreloadSubscriberTest.php @@ -12,6 +12,7 @@ use Joomla\Application\Event\ApplicationEvent; use Joomla\Preload\EventListener\PreloadSubscriber; use Joomla\Preload\PreloadManager; +use Laminas\Diactoros\Response; use PHPUnit\Framework\TestCase; use Psr\Link\EvolvableLinkProviderInterface; @@ -57,6 +58,9 @@ public function testAddHeaderToApplication() * @since 1.0 */ class TestAbstractWebApplication extends AbstractWebApplication { + public function __construct() { + $this->setResponse(new Response()); + } protected function doExecute() { // TODO: Implement doExecute() method.