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", 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..db20a4d --- /dev/null +++ b/src/PreloadManagerInterface.php @@ -0,0 +1,100 @@ + 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 = []); +} 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.