From fdb1d71e507bcf9b10ce74528f00e735006cdf11 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 24 Aug 2026 12:00:52 -0400 Subject: [PATCH 1/2] docs: add class-level PHPDoc for the framework-neutral Vite APIs. --- CHANGELOG.md | 1 + src/Asset/AssetCollection.php | 71 ++++++++++++--- src/Asset/InlineModule.php | 8 ++ src/Asset/ModulePreload.php | 13 +++ src/Asset/ModuleScript.php | 13 +++ src/Asset/Stylesheet.php | 13 +++ .../DevelopmentConfiguration.php | 23 ++++- src/Configuration/ProductionConfiguration.php | 23 +++-- .../InlineModuleProviderInterface.php | 12 +++ src/Exception/ConfigurationException.php | 3 + src/Exception/EntrypointNotFoundException.php | 3 + src/Exception/HtmlRenderingException.php | 3 + src/Exception/InvalidEntrypointException.php | 3 + src/Exception/InvalidManifestException.php | 3 + src/Exception/ManifestException.php | 3 + src/Exception/ManifestNotFoundException.php | 3 + src/Exception/ManifestReadException.php | 3 + src/Exception/Message.php | 19 ++-- src/Html/HtmlRenderOptions.php | 39 ++++++-- src/Html/HtmlRenderer.php | 58 +++++++++++- src/Manifest/Manifest.php | 13 ++- src/Manifest/ManifestChunk.php | 21 ++++- src/Manifest/ManifestLoader.php | 88 ++++++++++++++++++- src/Resolver/AssetResolverInterface.php | 15 +++- src/Resolver/DevelopmentAssetResolver.php | 20 +++++ src/Resolver/ManifestAssetResolver.php | 77 ++++++++++++++-- src/Support/EntrypointNormalizer.php | 16 +++- src/Support/Path.php | 30 +++++++ src/Support/Url.php | 80 +++++++++++++++++ src/Vite.php | 59 ++++++++++++- tests/AssetCollectionTest.php | 2 +- tests/ConfigurationTest.php | 2 +- .../CapturingInlineModuleProviderStub.php | 35 ++++++++ tests/Fixture/UnsupportedAssetStub.php | 14 +++ .../CapturingInlineModuleProviderStub.php | 20 ----- tests/Fixtures/UnsupportedAssetStub.php | 9 -- tests/HtmlRendererTest.php | 1 + tests/ManifestLoaderTest.php | 2 +- tests/Provider/ConfigurationProvider.php | 2 - tests/Provider/HtmlRendererProvider.php | 2 - tests/Provider/ManifestLoaderProvider.php | 3 - tests/Provider/UrlProvider.php | 2 - tests/ViteDevelopmentTest.php | 2 +- tests/ViteProductionTest.php | 14 ++- 44 files changed, 733 insertions(+), 113 deletions(-) create mode 100644 tests/Fixture/CapturingInlineModuleProviderStub.php create mode 100644 tests/Fixture/UnsupportedAssetStub.php delete mode 100644 tests/Fixtures/CapturingInlineModuleProviderStub.php delete mode 100644 tests/Fixtures/UnsupportedAssetStub.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b757f7..a270a05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,3 +8,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 0.1.0 Under development - feat: added a framework-agnostic Vite facade with explicit development and production configuration. +- docs: add class-level PHPDoc for the framework-neutral Vite APIs. diff --git a/src/Asset/AssetCollection.php b/src/Asset/AssetCollection.php index 34a5119..abde8a2 100644 --- a/src/Asset/AssetCollection.php +++ b/src/Asset/AssetCollection.php @@ -21,12 +21,15 @@ final readonly class AssetCollection implements Countable, IteratorAggregate { /** - * @var list + * @var list Accepted assets in insertion order, with per-type duplicates removed. */ private array $assets; /** - * @param iterable $assets + * @param iterable $assets Assets to collect. + * + * @throws ConfigurationException if a value does not implement {@see AssetInterface}, or implements it without + * being one of the four supported asset types. */ public function __construct(iterable $assets = []) { @@ -52,25 +55,45 @@ public function __construct(iterable $assets = []) } /** - * @return list + * Returns every collected asset in insertion order, regardless of type. + * + * @return list The collected assets. */ public function all(): array { return $this->assets; } - public function append(AssetInterface ...$assets): self + /** + * Returns a new collection with the supplied assets added after the current ones. + * + * The receiver is left untouched; deduplication is re-applied across the combined sequence. + * + * @param AssetInterface ...$assets Assets to add at the end. + * + * @throws ConfigurationException if an asset is not one of the four supported types. + * + * @return AssetCollection A new collection holding both sequences. + */ + public function append(AssetInterface ...$assets): AssetCollection { return new self([...$this->assets, ...$assets]); } + /** + * Counts the collected assets after deduplication. + * + * @return int<0, max> Number of assets in the collection. + */ public function count(): int { return count($this->assets); } /** - * @return Traversable + * Iterates over the collected assets in insertion order. + * + * @return Traversable Iterator over the collected assets. */ public function getIterator(): Traversable { @@ -78,7 +101,9 @@ public function getIterator(): Traversable } /** - * @return list + * Filters the collection down to its inline modules. + * + * @return list Inline modules in insertion order. */ public function inlineModules(): array { @@ -94,7 +119,9 @@ public function inlineModules(): array } /** - * @return list + * Filters the collection down to its module-preload hints. + * + * @return list Module preloads in insertion order. */ public function modulePreloads(): array { @@ -110,7 +137,9 @@ public function modulePreloads(): array } /** - * @return list + * Filters the collection down to its module scripts. + * + * @return list Module scripts in insertion order. */ public function moduleScripts(): array { @@ -125,13 +154,26 @@ public function moduleScripts(): array return $assets; } - public function prepend(AssetInterface ...$assets): self + /** + * Returns a new collection with the supplied assets added before the current ones. + * + * The receiver is left untouched; deduplication is re-applied across the combined sequence. + * + * @param AssetInterface ...$assets Assets to add at the beginning. + * + * @throws ConfigurationException if an asset is not one of the four supported types. + * + * @return AssetCollection A new collection holding both sequences. + */ + public function prepend(AssetInterface ...$assets): AssetCollection { return new self([...$assets, ...$this->assets]); } /** - * @return list + * Filters the collection down to its stylesheets. + * + * @return list Stylesheets in insertion order. */ public function stylesheets(): array { @@ -147,7 +189,14 @@ public function stylesheets(): array } /** - * @return InlineModule|ModulePreload|ModuleScript|Stylesheet + * Narrows an arbitrary value to one of the four supported asset types. + * + * @param mixed $asset Value taken from the incoming iterable. + * + * @throws ConfigurationException if the value does not implement {@see AssetInterface}, or implements it without + * being a supported type. + * + * @return InlineModule|ModulePreload|ModuleScript|Stylesheet The narrowed asset. */ private function requireAsset(mixed $asset): AssetInterface { diff --git a/src/Asset/InlineModule.php b/src/Asset/InlineModule.php index 2baab0c..5c8437d 100644 --- a/src/Asset/InlineModule.php +++ b/src/Asset/InlineModule.php @@ -8,8 +8,16 @@ use function trim; +/** + * Represents validated inline JavaScript module source. + */ final readonly class InlineModule implements AssetInterface { + /** + * @param string $source JavaScript module source rendered inside a `