From 788004106c91c7591b6f9d1012689e0a9fccaf62 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:16:49 +0200 Subject: [PATCH 001/328] Create spec.md --- spec.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 spec.md diff --git a/spec.md b/spec.md new file mode 100644 index 00000000000..531a8f21b68 --- /dev/null +++ b/spec.md @@ -0,0 +1,45 @@ +# Asset API Overview + +## Abstract + +In order to rework the Asset API, we need to analyze the current state of the API, to find what can be improved. + +## Current State + +### Asset Facade + +```php +Asset::cdnLink(string $file) // Gets remote URL to any file in /dist/ in the HydeFront version +Asset::mediaLink(string $file) // Returns Hyde::mediaLink but with a cache buster +Asset::hasMediaFile(string $file) // Returns file_exists(Hyde::mediaPath($file)) + +/** + * Real implementations of the facade methods: + * + * @see \Hyde\Framework\Services\AssetService::cdnLink + * @see \Hyde\Framework\Services\AssetService::mediaLink + * @see \Hyde\Framework\Services\AssetService::hasMediaFile + */ +``` + +### Hyde Facade + +```php +Hyde::mediaPath() // Get the absolute path to the media source directory, or a file within it. (Intended as a sibling to Hyde::path and Hyde::sitePath helpers, and the HydePage::path methods) +Hyde::mediaLink() // Gets a relative web link to the given file stored in the _site/media folder. (Intended as a sibling to Hyde::relativeLink, which is called by this) (A second $validate parameter will return throw an exception if the file does not exist) +Hyde::asset() // Gets a relative web link to the given image stored in the _site/media folder. (But leaves remote URLs alone) (A second $preferQualifiedUrl parameter will return a fully qualified URL if a site URL is set) + +/** + * Real implementations of the facade methods: + * + * @see \Hyde\Foundation\HydeKernel::mediaPath {@see \Hyde\Foundation\Kernel\Filesystem::mediaPath} + * @see \Hyde\Foundation\HydeKernel::mediaLink {@see \Hyde\Foundation\Kernel\Hyperlinks::mediaLink} + * @see \Hyde\Foundation\HydeKernel::asset {@see \Hyde\Foundation\Kernel\Hyperlinks::asset} + */ +``` + +### Helper Functions + +```php +asset() // Calls Hyde::asset +``` From a05d56076fd136b8dd38d794a75647f7bd9b55ab Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:24:57 +0200 Subject: [PATCH 002/328] Add AI context --- spec.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/spec.md b/spec.md index 531a8f21b68..6d20f397d73 100644 --- a/spec.md +++ b/spec.md @@ -43,3 +43,67 @@ Hyde::asset() // Gets a relative web link to the given image stored in the _site ```php asset() // Calls Hyde::asset ``` + +## AI Context + +Please provide feedback on how we can improve the Asset API. + +For context: This is for static site generator HydePHP, based on Laravel. + +Motto: "Simplicity first. Power when you need it. Quality always." +Tagline: Create static websites with the tools you already know and love with HydePHP. + +The Hyde Philosophy: +> Developing Hyde sites, and contributing to the framework should be a joy. Great Developer Experience (DX) is our top priority. +> Code should make sense and be intuitive, especially user-facing APIs. Convention over configuration, but not at the expense of flexibility. +> Making sites should not be boring and repetitive - Hyde is all about taking focus away from boilerplate, and letting users focus on the content. + +Considerations: While HydePHP targets developers, not all users necessarily are familiar with Laravel, or PHP. So while we want to provide a familiar interface for Laravel/PHP users, we also want to make sure that the API is intuitive and easy to use for all users. + +For additional context on the naming conventions, here is the entire Hyde facade methods: + + * @method static string path(string $path = '') + * @method static string vendorPath(string $path = '', string $package = 'framework') + * @method static string pathToAbsolute(string $path) + * @method static string pathToRelative(string $path) + * @method static string sitePath(string $path = '') + * @method static string mediaPath(string $path = '') + * @method static string siteMediaPath(string $path = '') + * @method static string formatLink(string $destination) + * @method static string relativeLink(string $destination) + * @method static string mediaLink(string $destination, bool $validate = false) + * @method static string asset(string $name, bool $preferQualifiedUrl = false) + * @method static string url(string $path = '') + * @method static Route|null route(string $key) + * @method static string makeTitle(string $value) + * @method static string normalizeNewlines(string $string) + * @method static string stripNewlines(string $string) + * @method static string trimSlashes(string $string) + * @method static HtmlString markdown(string $text, bool $stripIndentation = false) + * @method static string currentPage() + * @method static string currentRouteKey() + * @method static string getBasePath() + * @method static string getSourceRoot() + * @method static string getOutputDirectory() + * @method static string getMediaDirectory() + * @method static string getMediaOutputDirectory() + * @method static Features features() + * @method static Collection authors() + * @method static FileCollection files() + * @method static PageCollection pages() + * @method static RouteCollection routes() + * @method static Route|null currentRoute() + * @method static HydeKernel getInstance() + * @method static Filesystem filesystem() + * @method static array getRegisteredExtensions() + * @method static bool hasFeature(Feature $feature) + * @method static bool hasSiteUrl() + * @method static void setInstance(HydeKernel $instance) + * @method static void setBasePath(string $basePath) + * @method static void setOutputDirectory(string $outputDirectory) + * @method static void setMediaDirectory(string $mediaDirectory) + * @method static void setSourceRoot(string $sourceRoot) + * @method static void shareViewData(HydePage $page) + * @method static array toArray() + * @method static bool isBooted() + * @method static void boot() From 91e06e2cadd4d3d6776ba60319518243c5e37abb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:27:23 +0200 Subject: [PATCH 003/328] Update AI context --- spec.md | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/spec.md b/spec.md index 6d20f397d73..05db70ad84d 100644 --- a/spec.md +++ b/spec.md @@ -46,7 +46,7 @@ asset() // Calls Hyde::asset ## AI Context -Please provide feedback on how we can improve the Asset API. +Please provide feedback on how we for HydePHP v2 can improve the Asset API, designed to make it easy to interact with Asset files stored in the `_media` directory. For context: This is for static site generator HydePHP, based on Laravel. @@ -62,6 +62,7 @@ Considerations: While HydePHP targets developers, not all users necessarily are For additional context on the naming conventions, here is the entire Hyde facade methods: +```php * @method static string path(string $path = '') * @method static string vendorPath(string $path = '', string $package = 'framework') * @method static string pathToAbsolute(string $path) @@ -107,3 +108,78 @@ For additional context on the naming conventions, here is the entire Hyde facade * @method static array toArray() * @method static bool isBooted() * @method static void boot() +``` + +We also have a MediaFile class that looks like this: + +```php + +/** + * File abstraction for a project media file. + */ +class MediaFile extends ProjectFile +{ + /** @var array The default extensions for media types */ + final public const EXTENSIONS = ['png', 'svg', 'jpg', 'jpeg', 'gif', 'ico', 'css', 'js']; + + /** @return array The array keys are the filenames relative to the _media/ directory */ + public static function all(): array + { + return static::discoverMediaAssetFiles(); + } + + /** @return array Array of filenames relative to the _media/ directory */ + public static function files(): array + { + return array_keys(static::all()); + } + + public function getIdentifier(): string + { + return Str::after($this->getPath(), Hyde::getMediaDirectory().'/'); + } + + public function toArray(): array + { + return array_merge(parent::toArray(), [ + 'length' => $this->getContentLength(), + 'mimeType' => $this->getMimeType(), + ]); + } + + public function getContentLength(): int + { + if (! is_file($this->getAbsolutePath())) { + throw new FileNotFoundException($this->path); + } + + return filesize($this->getAbsolutePath()); + } + + public function getMimeType(): string + { + return mime_content_type($this->getAbsolutePath()); + } + + protected static function discoverMediaAssetFiles(): array + { + return collect(static::getMediaAssetFiles())->mapWithKeys(function (string $path): array { + $file = static::make($path); + + return [$file->getIdentifier() => $file]; + })->all(); + } + + protected static function getMediaAssetFiles(): array + { + return glob(Hyde::path(static::getMediaGlobPattern()), GLOB_BRACE) ?: []; + } + + protected static function getMediaGlobPattern(): string + { + return sprintf(Hyde::getMediaDirectory().'/{*,**/*,**/*/*}.{%s}', implode(',', + Config::getArray('hyde.media_extensions', self::EXTENSIONS) + )); + } +} +``` From 946b23974805f2c346fb0703e2a13cbee60f5881 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:28:13 +0200 Subject: [PATCH 004/328] Formatting --- spec.md | 1 - 1 file changed, 1 deletion(-) diff --git a/spec.md b/spec.md index 05db70ad84d..b36609db605 100644 --- a/spec.md +++ b/spec.md @@ -113,7 +113,6 @@ For additional context on the naming conventions, here is the entire Hyde facade We also have a MediaFile class that looks like this: ```php - /** * File abstraction for a project media file. */ From 7dfff263dc44e4eb3545cafd12b9b29877390f50 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:29:57 +0200 Subject: [PATCH 005/328] Fluent Asset API proposal --- spec.md | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/spec.md b/spec.md index b36609db605..efa9c8ba471 100644 --- a/spec.md +++ b/spec.md @@ -182,3 +182,138 @@ class MediaFile extends ProjectFile } } ``` + +## Proposals + +### Fluent Asset API + +Author: Claude 3.5 Sonnet + +Based on the provided information and the goals of HydePHP, here are some suggestions to improve the Asset API for version 2: + +1. Consolidate and simplify the API: + The current API is spread across multiple facades (Asset, Hyde) and helper functions. To improve clarity and ease of use, consider consolidating these into a single, intuitive API. + + + +```php +class Asset +{ + // Get the absolute path to a media file + public static function path(string $file = ''): string + { + // Implementation + } + + // Get a relative web link to a media file + public static function link(string $file, bool $validate = false): string + { + // Implementation + } + + // Get a CDN link for a file + public static function cdnLink(string $file): string + { + // Implementation + } + + // Check if a media file exists + public static function exists(string $file): bool + { + // Implementation + } + + // Get all media files + public static function all(): array + { + // Implementation using MediaFile::all() + } + + // Get a MediaFile instance + public static function file(string $file): MediaFile + { + // Implementation + } +} + +``` + +This consolidated API provides a cleaner, more intuitive interface for working with assets. It combines functionality from the current Asset and Hyde facades, making it easier for developers to find and use the methods they need. + +2. Improve method naming: + Some current method names like `cdnLink` and `mediaLink` might be confusing. Consider using more descriptive names that clearly indicate their purpose. + +3. Consistent return types: + Ensure that all methods have consistent return types. For example, always return strings for paths and links, and use type hinting to make the API more predictable. + +4. Fluent interface: + Consider implementing a fluent interface for chaining operations on assets. This can make the API more flexible and expressive. + + + +```php +class AssetFile +{ + protected $file; + + public function __construct(string $file) + { + $this->file = $file; + } + + public function path(): string + { + // Implementation + } + + public function link(bool $validate = false): string + { + // Implementation + } + + public function cdnLink(): string + { + // Implementation + } + + public function exists(): bool + { + // Implementation + } + + public function content(): string + { + // Implementation + } +} + +class Asset +{ + public static function file(string $file): AssetFile + { + return new AssetFile($file); + } + + // Other static methods... +} + +// Usage example +$assetUrl = Asset::file('image.jpg')->cdnLink(); +$assetContent = Asset::file('styles.css')->content(); + +``` + +5. Better integration with MediaFile: + Leverage the existing MediaFile class more prominently in the API. This can provide a richer set of operations on individual files. + +6. Consistent error handling: + Implement a consistent approach to error handling. Consider using custom exceptions that provide clear, actionable error messages. + +7. Caching: + Implement intelligent caching for asset operations to improve performance, especially for repeated operations. + +8. Configuration: + Provide a clear way to configure asset-related settings, such as CDN URLs or custom media directories, through a dedicated configuration file or section. + +These improvements aim to create a more intuitive, powerful, and flexible Asset API that aligns with HydePHP's philosophy and goals. The consolidated and fluent interfaces should make it easier for both Laravel-familiar and new users to work with assets effectively. + From 0e8e7e3fd9d14de8904bdc23c0515a9e62ae673d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:35:37 +0200 Subject: [PATCH 006/328] Add link --- spec.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spec.md b/spec.md index efa9c8ba471..953bc3a4cd3 100644 --- a/spec.md +++ b/spec.md @@ -188,6 +188,7 @@ class MediaFile extends ProjectFile ### Fluent Asset API Author: Claude 3.5 Sonnet +Link: https://claude.ai/chat/3b4529e1-79f5-48b9-ac8f-d35fa705a377 Based on the provided information and the goals of HydePHP, here are some suggestions to improve the Asset API for version 2: From 99462466208d08cf3f5c8cef6df787b5eec6524e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:38:22 +0200 Subject: [PATCH 007/328] Update line --- spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.md b/spec.md index 953bc3a4cd3..42effd5dd97 100644 --- a/spec.md +++ b/spec.md @@ -110,7 +110,7 @@ For additional context on the naming conventions, here is the entire Hyde facade * @method static void boot() ``` -We also have a MediaFile class that looks like this: +We also have a MediaFile class that looks like this, maybe we can unify this as well: ```php /** From a990c488ca7252e9ac71badbdd64b24d7dcf6cce Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:41:18 +0200 Subject: [PATCH 008/328] Refined Fluent Asset API proposal --- spec.md | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/spec.md b/spec.md index 42effd5dd97..f3a8d3592f6 100644 --- a/spec.md +++ b/spec.md @@ -318,3 +318,202 @@ $assetContent = Asset::file('styles.css')->content(); These improvements aim to create a more intuitive, powerful, and flexible Asset API that aligns with HydePHP's philosophy and goals. The consolidated and fluent interfaces should make it easier for both Laravel-familiar and new users to work with assets effectively. +### Fluent Asset API (Refined) + +Author: Claude 3.5 Sonnet +Link: https://claude.ai/chat/3b4529e1-79f5-48b9-ac8f-d35fa705a377 + +Thank you for providing those additional considerations and the detailed API reference. Let's refine the proposal based on this new information. We'll focus on merging with MediaFiles, adjusting for the limited CDN use case, and aligning with the existing Hyde page classes API structure. + + + +```php +abstract class Asset +{ + protected string $identifier; + protected string $sourceDirectory = '_media'; + protected string $outputDirectory = 'media'; + protected string $fileExtension; + + public function __construct(string $identifier) + { + $this->identifier = $identifier; + $this->fileExtension = pathinfo($identifier, PATHINFO_EXTENSION); + } + + public static function make(string $identifier): static + { + return new static($identifier); + } + + public static function isDiscoverable(): bool + { + return true; + } + + public static function get(string $identifier): static + { + if (!static::exists($identifier)) { + throw new FileNotFoundException("Asset not found: {$identifier}"); + } + return new static($identifier); + } + + public static function parse(string $identifier): static + { + return static::get($identifier); + } + + public static function files(): array + { + // Implementation to get all asset file identifiers + } + + public static function all(): AssetCollection + { + // Implementation to get all assets as a collection + } + + public static function sourceDirectory(): string + { + return (new static(''))->sourceDirectory; + } + + public static function outputDirectory(): string + { + return (new static(''))->outputDirectory; + } + + public static function setSourceDirectory(string $sourceDirectory): void + { + (new static(''))->sourceDirectory = $sourceDirectory; + } + + public static function setOutputDirectory(string $outputDirectory): void + { + (new static(''))->outputDirectory = $outputDirectory; + } + + public function sourcePath(): string + { + return Hyde::path($this->sourceDirectory . '/' . $this->identifier); + } + + public function outputPath(): string + { + return Hyde::sitePath($this->outputDirectory . '/' . $this->identifier); + } + + public static function exists(string $identifier): bool + { + return file_exists((new static($identifier))->sourcePath()); + } + + public function getIdentifier(): string + { + return $this->identifier; + } + + public function getLink(): string + { + return '/' . $this->outputDirectory . '/' . $this->identifier; + } + + public function getContents(): string + { + return file_get_contents($this->sourcePath()); + } + + public function getMimeType(): string + { + return mime_content_type($this->sourcePath()); + } + + public function getSize(): int + { + return filesize($this->sourcePath()); + } + + public function copy(): bool + { + return copy($this->sourcePath(), $this->outputPath()); + } + + // HydeFront specific method + public static function cdnLink(string $file): string + { + // Implementation for HydeFront CDN links + } + + public function toArray(): array + { + return [ + 'identifier' => $this->getIdentifier(), + 'sourcePath' => $this->sourcePath(), + 'outputPath' => $this->outputPath(), + 'link' => $this->getLink(), + 'mimeType' => $this->getMimeType(), + 'size' => $this->getSize(), + ]; + } +} + +class AssetCollection extends Collection +{ + // Implement any asset-specific collection methods here +} + +``` + +This refined Asset API proposal addresses the considerations you mentioned: + +1. Merging with MediaFiles: + The new `Asset` class incorporates functionality from both the current Asset facade and the MediaFile class. It provides methods for working with individual assets as well as collections of assets. + +2. CDN links: + The `cdnLink` method is retained but as a static method, reflecting its specific use for HydeFront files. This keeps the functionality available without overemphasizing its importance for general asset handling. + +3. Alignment with Hyde page classes: + The API structure closely follows the pattern established by the Hyde page classes. It includes similar static methods for file discovery and management, as well as instance methods for working with individual assets. + +Key improvements and features: + +1. Consistent API: + The new API provides a consistent interface for working with assets, following patterns familiar to users of other Hyde classes. + +2. Flexible file handling: + Methods like `sourcePath()`, `outputPath()`, `getLink()`, and `copy()` provide flexible ways to work with asset files throughout the build process. + +3. Asset information: + Methods like `getMimeType()`, `getSize()`, and `getContents()` provide easy access to important asset information. + +4. Collection support: + The `AssetCollection` class allows for easy management and manipulation of multiple assets. + +5. Extensibility: + As an abstract class, `Asset` can be extended for specific asset types if needed in the future. + +Usage examples: + +```php +// Get all assets +$assets = Asset::all(); + +// Get a specific asset +$logo = Asset::get('images/logo.png'); + +// Get the web-accessible link to an asset +$logoUrl = $logo->getLink(); + +// Copy an asset to the output directory +$logo->copy(); + +// Get asset information +$size = $logo->getSize(); +$mimeType = $logo->getMimeType(); + +// HydeFront CDN link (for app.js or app.css) +$appJsUrl = Asset::cdnLink('app.js'); +``` + +This API maintains the simplicity-first approach of Hyde while providing power when needed. It should be intuitive for both Laravel-familiar developers and those new to the framework, aligning well with Hyde's philosophy and goals. From 2296be6bdc4d1c4b326fce0fe2c3fba5ac8f0fdb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:42:45 +0200 Subject: [PATCH 009/328] Unified Asset API proposal --- spec.md | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) diff --git a/spec.md b/spec.md index f3a8d3592f6..9636e744d17 100644 --- a/spec.md +++ b/spec.md @@ -517,3 +517,264 @@ $appJsUrl = Asset::cdnLink('app.js'); ``` This API maintains the simplicity-first approach of Hyde while providing power when needed. It should be intuitive for both Laravel-familiar developers and those new to the framework, aligning well with Hyde's philosophy and goals. + +### Unified Asset API + +Author: Claude 3.5 Sonnet +Link: https://claude.ai/chat/9c1c98cc-db92-41cc-9a8e-1f51fd9a04d5 + +Certainly, I'd be happy to help you improve the Asset API for HydePHP v2. Based on your requirements and the HydePHP philosophy, I've come up with a proposal for a new, more unified Asset API. Here's the proposed new API and implementation plan: + +```php +validateExistence = $validateExistence; + } + + public function get(string $path, bool $absolute = false): string + { + if ($this->validateExistence && !$this->exists($path)) { + throw new AssetNotFoundException("Asset not found: {$path}"); + } + + return $absolute ? $this->getAbsolutePath($path) : $this->getRelativePath($path); + } + + public function url(string $path): string + { + if (filter_var($path, FILTER_VALIDATE_URL)) { + return $path; + } + + return Hyde::url($this->get($path)); + } + + public function exists(string $path): bool + { + return file_exists($this->getAbsolutePath($path)); + } + + public function size(string $path): int + { + return filesize($this->getAbsolutePath($path)); + } + + public function mime(string $path): string + { + return mime_content_type($this->getAbsolutePath($path)); + } + + public function hash(string $path): ?string + { + $file = $this->getAbsolutePath($path); + return file_exists($file) ? md5_file($file) : null; + } + + public function instance(string $path): AssetContract + { + return new Asset($path); + } + + protected function getAbsolutePath(string $path): string + { + return Hyde::mediaPath($path); + } + + protected function getRelativePath(string $path): string + { + return Hyde::mediaLink($path); + } +} + +// Asset.php (implements AssetContract) +class Asset implements AssetContract +{ + protected $path; + + public function __construct(string $path) + { + $this->path = $path; + } + + public function get(bool $absolute = false): string + { + return app(AssetService::class)->get($this->path, $absolute); + } + + public function url(): string + { + return app(AssetService::class)->url($this->path); + } + + public function exists(): bool + { + return app(AssetService::class)->exists($this->path); + } + + public function size(): int + { + return app(AssetService::class)->size($this->path); + } + + public function mime(): string + { + return app(AssetService::class)->mime($this->path); + } + + public function hash(): ?string + { + return app(AssetService::class)->hash($this->path); + } +} + +// Helper function +function asset(string $path, bool $absolute = false): string +{ + return Asset::get($path, $absolute); +} + +``` + +This new API proposal aims to simplify and unify the asset-related functions while maintaining flexibility and adhering to the HydePHP philosophy. Here's a breakdown of the changes and the implementation plan: + +1. Unified API: + - All asset-related functions are now under the `Asset` facade. + - The `get()` method replaces both `mediaLink()` and `asset()`, with an optional parameter for absolute paths. + - Added `url()` method to handle both local and remote URLs. + - Included utility methods like `exists()`, `size()`, `mime()`, and `hash()` for common operations. + +2. Validation: + - Instead of a parameter to validate, we've added a constructor parameter in the `AssetService` that can be set via configuration or environment variable. + +3. Flexibility: + - The `instance()` method allows for object-oriented usage when needed. + +Implementation Plan: + +1. Deprecation process in v1: + - Add deprecation notices to the existing methods in the `Asset` and `Hyde` facades. + - Introduce the new `Asset` facade with the proposed methods, marking them as `@since 1.x`. + - Update the documentation to recommend using the new `Asset` facade. + +2. Implementation in v2: + - Remove the deprecated methods from the `Asset` and `Hyde` facades. + - Fully implement the new `AssetService` and `Asset` classes. + - Update all internal usage to use the new API. + +3. Configuration: + - Add a new configuration option in `config/hyde.php`: + ```php + 'assets' => [ + 'validate_existence' => env('HYDE_VALIDATE_ASSETS', false), + ], + ``` + +4. Release Notes: + ```markdown + # HydePHP v2.0 Release Notes + + ## Asset API Overhaul + + We've completely revamped the Asset API to provide a more intuitive and unified interface for handling media files. Key changes include: + + - New `Asset` facade with streamlined methods + - Simplified asset retrieval with `Asset::get()` + - Built-in URL handling with `Asset::url()` + - Additional utility methods: `exists()`, `size()`, `mime()`, `hash()` + - Object-oriented usage available through `Asset::instance()` + - Global `asset()` helper function updated + + These changes aim to improve developer experience and make asset handling more straightforward and consistent. + ``` + +5. Upgrade Guide: + ```markdown + # Upgrading to HydePHP v2.0 + + ## Asset API Changes + + 1. Replace all usage of `Hyde::mediaLink()`, `Hyde::asset()`, and `Asset::mediaLink()` with `Asset::get()`: + + ```php + // Old + $path = Hyde::mediaLink('image.jpg'); + $path = Hyde::asset('image.jpg'); + $path = Asset::mediaLink('image.jpg'); + + // New + $path = Asset::get('image.jpg'); + ``` + + 2. For absolute paths, use the second parameter of `Asset::get()`: + + ```php + $absolutePath = Asset::get('image.jpg', true); + ``` + + 3. Use `Asset::url()` for handling both local and remote URLs: + + ```php + $url = Asset::url('image.jpg'); + $url = Asset::url('https://example.com/image.jpg'); + ``` + + 4. Take advantage of new utility methods: + + ```php + if (Asset::exists('image.jpg')) { + $size = Asset::size('image.jpg'); + $mime = Asset::mime('image.jpg'); + $hash = Asset::hash('image.jpg'); + } + ``` + + 5. For object-oriented usage, use `Asset::instance()`: + + ```php + $asset = Asset::instance('image.jpg'); + $path = $asset->get(); + $exists = $asset->exists(); + ``` + + 6. Update your configuration file to include the new asset validation option: + + ```php + // config/hyde.php + 'assets' => [ + 'validate_existence' => env('HYDE_VALIDATE_ASSETS', false), + ], + ``` + + These changes will ensure your project is compatible with HydePHP v2.0 and takes full advantage of the new Asset API. + ``` + +This proposal aims to simplify the Asset API while maintaining flexibility and power. It adheres to the HydePHP philosophy by providing an intuitive interface that should be easy to use for both Laravel developers and those less familiar with the framework. The implementation plan ensures a smooth transition from v1 to v2, with clear deprecation notices and comprehensive upgrade instructions. From 3bde4836b7e6000d0758af2603849a2d50945c60 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:43:28 +0200 Subject: [PATCH 010/328] Fix formatting --- spec.md | 1 - 1 file changed, 1 deletion(-) diff --git a/spec.md b/spec.md index 9636e744d17..e2f85013582 100644 --- a/spec.md +++ b/spec.md @@ -775,6 +775,5 @@ Implementation Plan: ``` These changes will ensure your project is compatible with HydePHP v2.0 and takes full advantage of the new Asset API. - ``` This proposal aims to simplify the Asset API while maintaining flexibility and power. It adheres to the HydePHP philosophy by providing an intuitive interface that should be easy to use for both Laravel developers and those less familiar with the framework. The implementation plan ensures a smooth transition from v1 to v2, with clear deprecation notices and comprehensive upgrade instructions. From bc78d745a977bd2884033c6f2bfafba9f807f983 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:47:01 +0200 Subject: [PATCH 011/328] Add Proposal Summary and Analysis --- spec.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/spec.md b/spec.md index e2f85013582..76ae89c8a98 100644 --- a/spec.md +++ b/spec.md @@ -777,3 +777,56 @@ Implementation Plan: These changes will ensure your project is compatible with HydePHP v2.0 and takes full advantage of the new Asset API. This proposal aims to simplify the Asset API while maintaining flexibility and power. It adheres to the HydePHP philosophy by providing an intuitive interface that should be easy to use for both Laravel developers and those less familiar with the framework. The implementation plan ensures a smooth transition from v1 to v2, with clear deprecation notices and comprehensive upgrade instructions. + +### Proposal Summary and Analysis + +Independent Claude 3.5 Sonnet executive summary of the three proposals for improving the Asset API in HydePHP v2: + +1. Fluent Asset API + +This proposal introduces a consolidated `Asset` class with both static and instance methods, integrating functionality from the current Asset and Hyde facades. It offers a fluent interface for chaining operations on assets. + +Benefits: +- Simplified, intuitive API +- Fluent interface for expressive chaining +- Consistent with Laravel patterns + +Drawbacks: +- Significant departure from current API, potentially high upgrade friction +- Increased complexity with new classes (AssetFile, AssetCollection) + +2. Fluent Asset API (Refined) + +This refined proposal merges functionality from the Asset facade and MediaFile class into an abstract `Asset` class. It aligns more closely with existing Hyde page classes and retains some current naming conventions. + +Benefits: +- Better alignment with existing Hyde patterns +- Comprehensive asset handling (discovery, manipulation, information) +- Extensibility through abstract class + +Drawbacks: +- Still represents a major change from current API +- Potential learning curve for users unfamiliar with Hyde patterns + +3. Unified Asset API + +This proposal focuses on unifying asset-related functions under a single `Asset` facade, with a backing `AssetService`. It aims for a balance between simplification and maintaining familiarity. + +Benefits: +- Maintains facade pattern, reducing upgrade friction +- Simplifies API while retaining familiar method names +- Includes a clear deprecation and upgrade path + +Drawbacks: +- Less dramatic improvement in DX compared to fluent proposals +- Retains some potential for confusion with multiple ways to access assets + +#### Final Recommendation: + +Based on the analysis, the Unified Asset API (Proposal 3) appears to be the most balanced approach. It offers significant improvements in developer experience and API consistency while minimizing upgrade friction and implementation complexity. The clear deprecation process and upgrade path will ease the transition for existing users. + +This proposal aligns well with HydePHP's philosophy of "Simplicity first. Power when you need it." It provides a more intuitive API without a complete overhaul, allowing for gradual adoption of new features. The retained facade pattern and familiar method names will help maintain accessibility for developers of varying experience levels. + +While the fluent API proposals offer more dramatic improvements in expressiveness, the associated increase in complexity and potential for confusion may outweigh these benefits. The Unified Asset API strikes a good balance between enhancing DX and maintaining continuity with the current system. + +Recommendation: Proceed with implementing the Unified Asset API (Proposal 3), ensuring thorough documentation and clear upgrade guides to support users through the transition. From 9788f7362661f30ef272efdbbdcc05073aa89366 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 21:55:24 +0200 Subject: [PATCH 012/328] Add obscure but relevant method --- spec.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec.md b/spec.md index 76ae89c8a98..12e1b45ea3e 100644 --- a/spec.md +++ b/spec.md @@ -28,6 +28,7 @@ Asset::hasMediaFile(string $file) // Returns file_exists(Hyde::mediaPath($file)) Hyde::mediaPath() // Get the absolute path to the media source directory, or a file within it. (Intended as a sibling to Hyde::path and Hyde::sitePath helpers, and the HydePage::path methods) Hyde::mediaLink() // Gets a relative web link to the given file stored in the _site/media folder. (Intended as a sibling to Hyde::relativeLink, which is called by this) (A second $validate parameter will return throw an exception if the file does not exist) Hyde::asset() // Gets a relative web link to the given image stored in the _site/media folder. (But leaves remote URLs alone) (A second $preferQualifiedUrl parameter will return a fully qualified URL if a site URL is set) +Hyde::siteMediaPath() // Get the absolute path to the compiled site's media directory, or a file within it. (Intended as a sibling to Hyde::sitePath) /** * Real implementations of the facade methods: @@ -35,6 +36,7 @@ Hyde::asset() // Gets a relative web link to the given image stored in the _site * @see \Hyde\Foundation\HydeKernel::mediaPath {@see \Hyde\Foundation\Kernel\Filesystem::mediaPath} * @see \Hyde\Foundation\HydeKernel::mediaLink {@see \Hyde\Foundation\Kernel\Hyperlinks::mediaLink} * @see \Hyde\Foundation\HydeKernel::asset {@see \Hyde\Foundation\Kernel\Hyperlinks::asset} + * @see \Hyde\Foundation\HydeKernel::siteMediaPath {@see \Hyde\Foundation\Kernel\Filesystem::siteMediaPath} */ ``` From 9731c8448cc67768f849e815f7244575c3e0fdf9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 22:02:18 +0200 Subject: [PATCH 013/328] Add background --- spec.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/spec.md b/spec.md index 12e1b45ea3e..bd834a652e2 100644 --- a/spec.md +++ b/spec.md @@ -4,6 +4,58 @@ In order to rework the Asset API, we need to analyze the current state of the API, to find what can be improved. +### Background + +Remember the original problem: The current system is confusing and unintuitive with multiple and inconsistent ways to access assets. + +Additionally, keep in mind that most ways users will commonly use this API is to link to assets in the `_media` directory, and to check if they exist. + +For example: Consider these Blade snippets from the default views, showing common usages that actual end users may use: + +```blade +{{-- The compiled Tailwind/App styles --}} +@if(config('hyde.load_app_styles_from_cdn', false)) + +@elseif(Asset::hasMediaFile('app.css')) + +@endif + +{{-- The compiled Laravel Mix scripts --}} +@if(Asset::hasMediaFile('app.js')) + +@endif + +@if (file_exists(Hyde::mediaPath('favicon.ico'))) + +@endif +``` + +Some other example usages could be things like: + +```blade +Logo +``` + +We also use the Asset API helpers in the internal codebase that actually powers the static site generator. These kinds of usages would usually only be used by us, package developers, and serious power users. They have an important, but secondary role in the API design. Here are some examples from our codebase: + +```php +// Code that transfers media assets from the source directory to the site output directory +$this->createDirectoryifItDoesNotExist(Hyde::siteMediaPath()); +$this->mapWithProgressBar(MediaFile::files(), function (string $identifier): void { + copy(Hyde::mediaPath($identifier), Hyde::siteMediaPath($identifier)); +}); + +// Helpers in the featured image class +public function getSource(): string { + return Hyde::mediaLink($this->source); +} + +protected function setSource(string $source): string { + // Normalize away any leading media path prefixes. + return Str::after($source, Hyde::getMediaDirectory().'/'); +} +``` + ## Current State ### Asset Facade From 0a0a4bdcabb1781c39410517c3e55105feb54e7a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 09:57:04 +0200 Subject: [PATCH 014/328] Add example AI prompt --- spec.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec.md b/spec.md index bd834a652e2..6d43377d19e 100644 --- a/spec.md +++ b/spec.md @@ -237,6 +237,15 @@ class MediaFile extends ProjectFile } ``` +### AI Example Prompt + +```markdown +Task: Split out the HydeFront related parts of the AssetService to a new facade class. +Motivation: We are simplifying the Asset API in https://github.com/hydephp/develop/pull/1904, and most users won't need the HydeFront related parts of the AssetService. Later, we will be able to merge the simplified AssetService into the other Asset helpers. +Implementation: Make the necessary changes to the code and tests. Also update the release notes to detail all breaking changes and the upgrade path. Make sure the release notes contains all necessary information, but is not too verbose and should not contain any fluff. Also write a brief pull request description. +Context: This is for v2 of static site generator HydePHP. +``` + ## Proposals ### Fluent Asset API From cca95dbc113645c819bff8c1753c8d931bb34715 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 09:59:07 +0200 Subject: [PATCH 015/328] Update context --- spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.md b/spec.md index 6d43377d19e..dd02d41f5c7 100644 --- a/spec.md +++ b/spec.md @@ -243,7 +243,7 @@ class MediaFile extends ProjectFile Task: Split out the HydeFront related parts of the AssetService to a new facade class. Motivation: We are simplifying the Asset API in https://github.com/hydephp/develop/pull/1904, and most users won't need the HydeFront related parts of the AssetService. Later, we will be able to merge the simplified AssetService into the other Asset helpers. Implementation: Make the necessary changes to the code and tests. Also update the release notes to detail all breaking changes and the upgrade path. Make sure the release notes contains all necessary information, but is not too verbose and should not contain any fluff. Also write a brief pull request description. -Context: This is for v2 of static site generator HydePHP. +Context: This is for v2 of static site generator HydePHP. Remember to match the code style of the existing codebase. ``` ## Proposals From 2f930e9be6fe1c3b5e77dae725c1e152109a4b1d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 10:20:38 +0200 Subject: [PATCH 016/328] Update context --- spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec.md b/spec.md index dd02d41f5c7..b404251e8ea 100644 --- a/spec.md +++ b/spec.md @@ -242,7 +242,7 @@ class MediaFile extends ProjectFile ```markdown Task: Split out the HydeFront related parts of the AssetService to a new facade class. Motivation: We are simplifying the Asset API in https://github.com/hydephp/develop/pull/1904, and most users won't need the HydeFront related parts of the AssetService. Later, we will be able to merge the simplified AssetService into the other Asset helpers. -Implementation: Make the necessary changes to the code and tests. Also update the release notes to detail all breaking changes and the upgrade path. Make sure the release notes contains all necessary information, but is not too verbose and should not contain any fluff. Also write a brief pull request description. +Implementation: Make the necessary changes to the code and tests. Also update the release notes to detail all breaking changes and the upgrade path. Make sure the release notes contains all necessary information, but is not too verbose and should not contain any fluff. Also write a brief pull request description detailing the changes made and why they were made. Context: This is for v2 of static site generator HydePHP. Remember to match the code style of the existing codebase. ``` From 67ae2114d1a3a48b94fd16e94b62003e2b1acfae Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 10:43:52 +0200 Subject: [PATCH 017/328] Remove the HydeFront version and CDN URL configuration options I can't see a good reason to want to change the version to load assets that are unlikely to work with the versions in the views in the project Hyde version. Changing the CDN URL could be useful if you want to change the host to another CDN provider, but this current system is way too convoluted for that. --- config/hyde.php | 5 --- docs/digging-deeper/customization.md | 14 ------- packages/framework/config/hyde.php | 5 --- .../src/Framework/Services/AssetService.php | 4 +- .../tests/Unit/AssetServiceUnitTest.php | 39 ------------------- 5 files changed, 2 insertions(+), 65 deletions(-) diff --git a/config/hyde.php b/config/hyde.php index 67c1da3b43b..87f5481d00e 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -470,11 +470,6 @@ // Where should the build manifest be saved? (Relative to project root, for example _site/build-manifest.json) 'build_manifest_path' => 'app/storage/framework/cache/build-manifest.json', - // Here you can specify HydeFront version and URL for when loading app.css from the CDN. - // Only change these if you know what you're doing as some versions may be incompatible with your Hyde version. - 'hydefront_version' => \Hyde\Framework\Services\AssetService::HYDEFRONT_VERSION, - 'hydefront_cdn_url' => \Hyde\Framework\Services\AssetService::HYDEFRONT_CDN_URL, - // Should the theme toggle buttons be displayed in the layouts? 'theme_toggle_buttons' => true, diff --git a/docs/digging-deeper/customization.md b/docs/digging-deeper/customization.md index f9c7a0f5682..95965376d78 100644 --- a/docs/digging-deeper/customization.md +++ b/docs/digging-deeper/customization.md @@ -342,20 +342,6 @@ Specifies the path where the build manifest should be saved, relative to the pro 'build_manifest_path' => 'app/storage/framework/cache/build-manifest.json', ``` -### `hydefront_version` and `hydefront_cdn_url` - -These options allow you to specify the HydeFront version and CDN URL when loading `app.css` from the CDN. - -Only change these if you know what you're doing as some versions may be incompatible with your Hyde version. - -```php -// filepath config/hyde.php -use \Hyde\Framework\Services\AssetService; - -'hydefront_version' => AssetService::HYDEFRONT_VERSION, -'hydefront_cdn_url' => AssetService::HYDEFRONT_CDN_URL, -``` - ### `theme_toggle_buttons` >info This feature was added in HydePHP v1.7.0 diff --git a/packages/framework/config/hyde.php b/packages/framework/config/hyde.php index 67c1da3b43b..87f5481d00e 100644 --- a/packages/framework/config/hyde.php +++ b/packages/framework/config/hyde.php @@ -470,11 +470,6 @@ // Where should the build manifest be saved? (Relative to project root, for example _site/build-manifest.json) 'build_manifest_path' => 'app/storage/framework/cache/build-manifest.json', - // Here you can specify HydeFront version and URL for when loading app.css from the CDN. - // Only change these if you know what you're doing as some versions may be incompatible with your Hyde version. - 'hydefront_version' => \Hyde\Framework\Services\AssetService::HYDEFRONT_VERSION, - 'hydefront_cdn_url' => \Hyde\Framework\Services\AssetService::HYDEFRONT_CDN_URL, - // Should the theme toggle buttons be displayed in the layouts? 'theme_toggle_buttons' => true, diff --git a/packages/framework/src/Framework/Services/AssetService.php b/packages/framework/src/Framework/Services/AssetService.php index 9373b676e10..d1f9bd54179 100644 --- a/packages/framework/src/Framework/Services/AssetService.php +++ b/packages/framework/src/Framework/Services/AssetService.php @@ -41,8 +41,8 @@ class AssetService public function __construct() { - $this->version = Config::getString('hyde.hydefront_version', self::HYDEFRONT_VERSION); - $this->cdnUrl = Config::getString('hyde.hydefront_url', self::HYDEFRONT_CDN_URL); + $this->version = self::HYDEFRONT_VERSION; + $this->cdnUrl = self::HYDEFRONT_CDN_URL; } public function version(): string diff --git a/packages/framework/tests/Unit/AssetServiceUnitTest.php b/packages/framework/tests/Unit/AssetServiceUnitTest.php index 9267b4715a6..352d8144101 100644 --- a/packages/framework/tests/Unit/AssetServiceUnitTest.php +++ b/packages/framework/tests/Unit/AssetServiceUnitTest.php @@ -36,50 +36,11 @@ public function testVersionStringDefaultsToConstant() $this->assertSame(AssetService::HYDEFRONT_VERSION, (new AssetService())->version()); } - public function testVersionCanBeSetInConfig() - { - self::mockConfig(['hyde.hydefront_version' => '1.0.0']); - $this->assertSame('1.0.0', (new AssetService())->version()); - } - public function testCdnPatternConstant() { $this->assertSame('https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}', AssetService::HYDEFRONT_CDN_URL); } - public function testCanSetCustomCdnUrlInConfig() - { - self::mockConfig(['hyde.hydefront_url' => 'https://example.com']); - $this->assertSame('https://example.com', (new AssetService())->cdnLink('')); - } - - public function testCanUseCustomCdnUrlWithVersion() - { - self::mockConfig(['hyde.hydefront_url' => '{{ $version }}']); - $this->assertSame('v3.4', (new AssetService())->cdnLink('')); - } - - public function testCanUseCustomCdnUrlWithFile() - { - self::mockConfig(['hyde.hydefront_url' => '{{ $file }}']); - $this->assertSame('styles.css', (new AssetService())->cdnLink('styles.css')); - } - - public function testCanUseCustomCdnUrlWithVersionAndFile() - { - self::mockConfig(['hyde.hydefront_url' => '{{ $version }}/{{ $file }}']); - $this->assertSame('v3.4/styles.css', (new AssetService())->cdnLink('styles.css')); - } - - public function testCanUseCustomCdnUrlWithCustomVersion() - { - self::mockConfig([ - 'hyde.hydefront_url' => '{{ $version }}', - 'hyde.hydefront_version' => '1.0.0', - ]); - $this->assertSame('1.0.0', (new AssetService())->cdnLink('')); - } - public function testCdnLinkHelper() { $this->assertSame( From 73cc657fb1fa3a6f8aae84e561e2ffecd2c889a8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 10:51:25 +0200 Subject: [PATCH 018/328] Draft Asset API change section --- RELEASE_NOTES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 86740ca0d9c..780688dfe65 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -239,6 +239,12 @@ The following methods in the `Features` class have been renamed to follow a more Note that this class was previously marked as internal in v1, but the change is logged here in case it was used in configuration files or custom code. +### Asset API Changes + +The overall asset API has been improved and cleaned up. Unfortunately, this means that there are some breaking changes to the API. + + + ## Low impact ### Navigation internal changes From d7c1a225b427dff2d59abfc06c710018ff743635 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 10:54:25 +0200 Subject: [PATCH 019/328] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 86740ca0d9c..3852a7188b6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -59,6 +59,7 @@ This serves two purposes: - Moved the sidebar documentation to the documentation pages section for better organization. - The build command now groups together all `InMemoryPage` instances under one progress bar group in https://github.com/hydephp/develop/pull/1897 - The `Markdown::render()` method will now always render Markdown using the custom HydePHP Markdown service (thus getting smart features like our Markdown processors) in https://github.com/hydephp/develop/pull/1900 +- The HydeFront asset version and CDN URL are now hardcoded in the `AssetService` class instead of being configurable in https://github.com/hydephp/develop/pull/1909 ### Deprecated - for soon-to-be removed features. @@ -66,6 +67,7 @@ This serves two purposes: ### Removed - Breaking: Removed the build task `\Hyde\Framework\Actions\PostBuildTasks\GenerateSearch` (see upgrade guide below) - Breaking: Removed the deprecated `\Hyde\Framework\Services\BuildService::transferMediaAssets()` method (see upgrade guide below) +- Breaking: Removed the `hydefront_version` and `hydefront_cdn_url` configuration options from the `hyde.php` config file in https://github.com/hydephp/develop/pull/1909 - Removed the deprecated global`unslash()` function, replaced with the namespaced `\Hyde\unslash()` function in https://github.com/hydephp/develop/pull/1754 - Removed the deprecated `BaseUrlNotSetException` class, with the `Hyde::url()` helper now throwing `BadMethodCallException` if no base URL is set in https://github.com/hydephp/develop/pull/1760 - Removed: The deprecated `PostAuthor::getName()` method is now removed (use `$author->name`) in https://github.com/hydephp/develop/pull/1782 @@ -239,6 +241,31 @@ The following methods in the `Features` class have been renamed to follow a more Note that this class was previously marked as internal in v1, but the change is logged here in case it was used in configuration files or custom code. +### Asset API Changes + +The overall asset API has been improved and cleaned up. Unfortunately, this means that there are some breaking changes to the API. + +#### Removal of HydeFront version and CDN URL configuration options + +The `hydefront_version` and `hydefront_cdn_url` configuration options have been removed from the `config/hyde.php` file. These options were previously used to specify the HydeFront version and CDN URL for loading assets. + +**Impact:** Low. This change will only affect users who have customized these options. + +**Upgrade steps:** + + + +1. Remove the following lines from your `config/hyde.php` file if they exist: + ```php + 'hydefront_version' => \Hyde\Framework\Services\AssetService::HYDEFRONT_VERSION, + 'hydefront_cdn_url' => \Hyde\Framework\Services\AssetService::HYDEFRONT_CDN_URL, + ``` +2. If you were using a custom CDN URL, you will need to implement your own solution for serving HydeFront assets from a different CDN. Consider copying the assets to your preferred CDN and updating your templates accordingly. + +**Rationale:** The ability to change the HydeFront version was removed because using a different version than the one bundled with your Hyde project could lead to compatibility issues. The CDN URL configuration was removed to simplify the asset loading process. + +If you need to use a different CDN for serving HydeFront assets, you should implement a custom solution tailored to your specific needs. You may also open a feature request if you believe this functionality should be added back in a future release. + ## Low impact ### Navigation internal changes From 1393a9c8a15afb8efd213b3e175d458b9b328aec Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 11:40:48 +0200 Subject: [PATCH 020/328] Remove useless constructor --- packages/framework/src/Framework/Services/AssetService.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/framework/src/Framework/Services/AssetService.php b/packages/framework/src/Framework/Services/AssetService.php index d1f9bd54179..718a8dd6f81 100644 --- a/packages/framework/src/Framework/Services/AssetService.php +++ b/packages/framework/src/Framework/Services/AssetService.php @@ -39,12 +39,6 @@ class AssetService protected string $version = self::HYDEFRONT_VERSION; protected string $cdnUrl = self::HYDEFRONT_CDN_URL; - public function __construct() - { - $this->version = self::HYDEFRONT_VERSION; - $this->cdnUrl = self::HYDEFRONT_CDN_URL; - } - public function version(): string { return $this->version; From 6e16df9aac7c3230bfcd54bbdc5ac3f4abfcc755 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 11:45:12 +0200 Subject: [PATCH 021/328] Breaking: Make the AssetService constants protected --- .../src/Framework/Services/AssetService.php | 4 ++-- .../framework/tests/Unit/AssetServiceUnitTest.php | 15 --------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/packages/framework/src/Framework/Services/AssetService.php b/packages/framework/src/Framework/Services/AssetService.php index 718a8dd6f81..c306f623a09 100644 --- a/packages/framework/src/Framework/Services/AssetService.php +++ b/packages/framework/src/Framework/Services/AssetService.php @@ -31,10 +31,10 @@ class AssetService { /** @var string The default HydeFront SemVer tag to load. This constant is set to match the styles used for the installed framework version. */ - final public const HYDEFRONT_VERSION = 'v3.4'; + final protected const HYDEFRONT_VERSION = 'v3.4'; /** @var string The default HydeFront CDN path pattern. The Blade-style placeholders are replaced with the proper values. */ - final public const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}'; + final protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}'; protected string $version = self::HYDEFRONT_VERSION; protected string $cdnUrl = self::HYDEFRONT_CDN_URL; diff --git a/packages/framework/tests/Unit/AssetServiceUnitTest.php b/packages/framework/tests/Unit/AssetServiceUnitTest.php index 352d8144101..02c33795d15 100644 --- a/packages/framework/tests/Unit/AssetServiceUnitTest.php +++ b/packages/framework/tests/Unit/AssetServiceUnitTest.php @@ -21,26 +21,11 @@ protected function setUp(): void self::mockConfig(); } - public function testVersionStringConstant() - { - $this->assertSame('v3.4', AssetService::HYDEFRONT_VERSION); - } - public function testServiceHasVersionString() { $this->assertIsString((new AssetService())->version()); } - public function testVersionStringDefaultsToConstant() - { - $this->assertSame(AssetService::HYDEFRONT_VERSION, (new AssetService())->version()); - } - - public function testCdnPatternConstant() - { - $this->assertSame('https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}', AssetService::HYDEFRONT_CDN_URL); - } - public function testCdnLinkHelper() { $this->assertSame( From 95a7955f82064df13d0d3ed5be14d5415f9833f5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:32:37 +0200 Subject: [PATCH 022/328] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 3852a7188b6..57e542a72f0 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -33,6 +33,7 @@ This serves two purposes: - **Breaking:** The `Author::get()` method now returns `null` if an author is not found, rather than creating a new instance. For more information, see below. - **Breaking:** The custom navigation item configuration now uses array inputs instead of the previous format. For more information, see the upgrade guide below. - **Breaking:** Renamed the `hyde.navigation.subdirectories` configuration option to `hyde.navigation.subdirectory_display`. +- **Breaking:** The `HYDEFRONT_VERSION` and `HYDEFRONT_CDN_URL` constants in the `AssetService` class have been changed from `public` to `protected`. This improves encapsulation but may affect code that directly accessed these constants. For more information, see below. - Medium: The `route` function will now throw a `RouteNotFoundException` if the route does not exist in https://github.com/hydephp/develop/pull/1741 - Minor: Navigation menu items are now no longer filtered by duplicates (meaning two items with the same label can now exist in the same menu) in https://github.com/hydephp/develop/pull/1573 - Minor: Due to changes in the navigation system, it is possible that existing configuration files will need to be adjusted in order for menus to look the same (in terms of ordering etc.) @@ -73,6 +74,7 @@ This serves two purposes: - Removed: The deprecated `PostAuthor::getName()` method is now removed (use `$author->name`) in https://github.com/hydephp/develop/pull/1782 - Internal: Removed the internal `DocumentationSearchPage::generate()` method as it was unused in https://github.com/hydephp/develop/pull/1569 - Removed the deprecated `FeaturedImage::isRemote()` method in https://github.com/hydephp/develop/pull/1883. Use `Hyperlinks::isRemote()` instead. +- The `HYDEFRONT_VERSION` and `HYDEFRONT_CDN_URL` constants in the `AssetService` class have been removed from the public API in https://github.com/hydephp/develop/pull/1910 ### Fixed - Added missing collection key types in Hyde facade method annotations in https://github.com/hydephp/develop/pull/1784 @@ -266,6 +268,33 @@ The `hydefront_version` and `hydefront_cdn_url` configuration options have been If you need to use a different CDN for serving HydeFront assets, you should implement a custom solution tailored to your specific needs. You may also open a feature request if you believe this functionality should be added back in a future release. +#### AssetService constants visibility changes + +The `HYDEFRONT_VERSION` and `HYDEFRONT_CDN_URL` constants in the `AssetService` class are now `protected` instead of `public`. This change improves encapsulation and reduces the public API surface. + +**Impact:** Low. This change will only affect users who directly accessed these constants in their custom code. + +**Upgrade steps:** + +1. If you were directly accessing `AssetService::HYDEFRONT_VERSION` or `AssetService::HYDEFRONT_CDN_URL` in your code, you will need to update your implementation. +2. Instead of using these constants directly, use the public methods provided by the `AssetService` class to interact with asset-related functionality. + +For example, if you were using: + +```php +$version = AssetService::HYDEFRONT_VERSION; +``` + +You should now use: + +```php +$version = (new AssetService())->version(); +``` + +If you need access to the CDN URL pattern, consider using the `cdnLink()` method of the `AssetService` class instead. + +These changes were implemented to improve the API design and encapsulation of the `AssetService` class. If you have any custom implementations that relied on these constants, please review and update your code accordingly. + ## Low impact ### Navigation internal changes From 97c7b5a05aef19bf9e34f44931cd72532bfee2fd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:36:04 +0200 Subject: [PATCH 023/328] Reset release note changes that may get out of date --- RELEASE_NOTES.md | 56 ------------------------------------------------ 1 file changed, 56 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 57e542a72f0..86740ca0d9c 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -33,7 +33,6 @@ This serves two purposes: - **Breaking:** The `Author::get()` method now returns `null` if an author is not found, rather than creating a new instance. For more information, see below. - **Breaking:** The custom navigation item configuration now uses array inputs instead of the previous format. For more information, see the upgrade guide below. - **Breaking:** Renamed the `hyde.navigation.subdirectories` configuration option to `hyde.navigation.subdirectory_display`. -- **Breaking:** The `HYDEFRONT_VERSION` and `HYDEFRONT_CDN_URL` constants in the `AssetService` class have been changed from `public` to `protected`. This improves encapsulation but may affect code that directly accessed these constants. For more information, see below. - Medium: The `route` function will now throw a `RouteNotFoundException` if the route does not exist in https://github.com/hydephp/develop/pull/1741 - Minor: Navigation menu items are now no longer filtered by duplicates (meaning two items with the same label can now exist in the same menu) in https://github.com/hydephp/develop/pull/1573 - Minor: Due to changes in the navigation system, it is possible that existing configuration files will need to be adjusted in order for menus to look the same (in terms of ordering etc.) @@ -60,7 +59,6 @@ This serves two purposes: - Moved the sidebar documentation to the documentation pages section for better organization. - The build command now groups together all `InMemoryPage` instances under one progress bar group in https://github.com/hydephp/develop/pull/1897 - The `Markdown::render()` method will now always render Markdown using the custom HydePHP Markdown service (thus getting smart features like our Markdown processors) in https://github.com/hydephp/develop/pull/1900 -- The HydeFront asset version and CDN URL are now hardcoded in the `AssetService` class instead of being configurable in https://github.com/hydephp/develop/pull/1909 ### Deprecated - for soon-to-be removed features. @@ -68,13 +66,11 @@ This serves two purposes: ### Removed - Breaking: Removed the build task `\Hyde\Framework\Actions\PostBuildTasks\GenerateSearch` (see upgrade guide below) - Breaking: Removed the deprecated `\Hyde\Framework\Services\BuildService::transferMediaAssets()` method (see upgrade guide below) -- Breaking: Removed the `hydefront_version` and `hydefront_cdn_url` configuration options from the `hyde.php` config file in https://github.com/hydephp/develop/pull/1909 - Removed the deprecated global`unslash()` function, replaced with the namespaced `\Hyde\unslash()` function in https://github.com/hydephp/develop/pull/1754 - Removed the deprecated `BaseUrlNotSetException` class, with the `Hyde::url()` helper now throwing `BadMethodCallException` if no base URL is set in https://github.com/hydephp/develop/pull/1760 - Removed: The deprecated `PostAuthor::getName()` method is now removed (use `$author->name`) in https://github.com/hydephp/develop/pull/1782 - Internal: Removed the internal `DocumentationSearchPage::generate()` method as it was unused in https://github.com/hydephp/develop/pull/1569 - Removed the deprecated `FeaturedImage::isRemote()` method in https://github.com/hydephp/develop/pull/1883. Use `Hyperlinks::isRemote()` instead. -- The `HYDEFRONT_VERSION` and `HYDEFRONT_CDN_URL` constants in the `AssetService` class have been removed from the public API in https://github.com/hydephp/develop/pull/1910 ### Fixed - Added missing collection key types in Hyde facade method annotations in https://github.com/hydephp/develop/pull/1784 @@ -243,58 +239,6 @@ The following methods in the `Features` class have been renamed to follow a more Note that this class was previously marked as internal in v1, but the change is logged here in case it was used in configuration files or custom code. -### Asset API Changes - -The overall asset API has been improved and cleaned up. Unfortunately, this means that there are some breaking changes to the API. - -#### Removal of HydeFront version and CDN URL configuration options - -The `hydefront_version` and `hydefront_cdn_url` configuration options have been removed from the `config/hyde.php` file. These options were previously used to specify the HydeFront version and CDN URL for loading assets. - -**Impact:** Low. This change will only affect users who have customized these options. - -**Upgrade steps:** - - - -1. Remove the following lines from your `config/hyde.php` file if they exist: - ```php - 'hydefront_version' => \Hyde\Framework\Services\AssetService::HYDEFRONT_VERSION, - 'hydefront_cdn_url' => \Hyde\Framework\Services\AssetService::HYDEFRONT_CDN_URL, - ``` -2. If you were using a custom CDN URL, you will need to implement your own solution for serving HydeFront assets from a different CDN. Consider copying the assets to your preferred CDN and updating your templates accordingly. - -**Rationale:** The ability to change the HydeFront version was removed because using a different version than the one bundled with your Hyde project could lead to compatibility issues. The CDN URL configuration was removed to simplify the asset loading process. - -If you need to use a different CDN for serving HydeFront assets, you should implement a custom solution tailored to your specific needs. You may also open a feature request if you believe this functionality should be added back in a future release. - -#### AssetService constants visibility changes - -The `HYDEFRONT_VERSION` and `HYDEFRONT_CDN_URL` constants in the `AssetService` class are now `protected` instead of `public`. This change improves encapsulation and reduces the public API surface. - -**Impact:** Low. This change will only affect users who directly accessed these constants in their custom code. - -**Upgrade steps:** - -1. If you were directly accessing `AssetService::HYDEFRONT_VERSION` or `AssetService::HYDEFRONT_CDN_URL` in your code, you will need to update your implementation. -2. Instead of using these constants directly, use the public methods provided by the `AssetService` class to interact with asset-related functionality. - -For example, if you were using: - -```php -$version = AssetService::HYDEFRONT_VERSION; -``` - -You should now use: - -```php -$version = (new AssetService())->version(); -``` - -If you need access to the CDN URL pattern, consider using the `cdnLink()` method of the `AssetService` class instead. - -These changes were implemented to improve the API design and encapsulation of the `AssetService` class. If you have any custom implementations that relied on these constants, please review and update your code accordingly. - ## Low impact ### Navigation internal changes From 4959e3b8356f594068e8daf41a8b605635d07b54 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:38:22 +0200 Subject: [PATCH 024/328] Deprecate the AssetService class --- packages/framework/src/Framework/Services/AssetService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Framework/Services/AssetService.php b/packages/framework/src/Framework/Services/AssetService.php index c306f623a09..82804bb6920 100644 --- a/packages/framework/src/Framework/Services/AssetService.php +++ b/packages/framework/src/Framework/Services/AssetService.php @@ -21,6 +21,8 @@ /** * Handles the retrieval of core asset files. Commonly used through the Asset facade. * + * @deprecated Will be merged into the Asset facade. + * * This class is loaded into the service container, making it easy to access and modify. * * The class also provides helper methods for interacting with versioned files, From 7e2b51acc5ca2bc164d07a7ec41aa59b37d207e6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:46:06 +0200 Subject: [PATCH 025/328] Remove mixin for deprecated AssetService --- _ide_helper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/_ide_helper.php b/_ide_helper.php index 228893b3169..a838afac059 100644 --- a/_ide_helper.php +++ b/_ide_helper.php @@ -33,7 +33,6 @@ class Hyde extends \Hyde\Hyde {} class Site extends \Hyde\Facades\Site {} class Meta extends \Hyde\Facades\Meta {} -/** @mixin \Hyde\Framework\Services\AssetService */ class Asset extends \Hyde\Facades\Asset {} class Author extends \Hyde\Facades\Author {} class Features extends \Hyde\Facades\Features {} From 19c7d17b930a9aac8ae849e2b922ca5e2c81ac2c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:50:54 +0200 Subject: [PATCH 026/328] Remove kernel binding test for deprecated AssetService --- .../framework/tests/Feature/HydeServiceProviderTest.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/framework/tests/Feature/HydeServiceProviderTest.php b/packages/framework/tests/Feature/HydeServiceProviderTest.php index 6904c5b11d6..ee7d35ae140 100644 --- a/packages/framework/tests/Feature/HydeServiceProviderTest.php +++ b/packages/framework/tests/Feature/HydeServiceProviderTest.php @@ -9,7 +9,6 @@ use Illuminate\Contracts\Container\BindingResolutionException; use Hyde\Console\ConsoleServiceProvider; use Hyde\Framework\HydeServiceProvider; -use Hyde\Framework\Services\AssetService; use Hyde\Framework\Services\BuildTaskService; use Hyde\Foundation\HydeCoreExtension; use Hyde\Hyde; @@ -54,13 +53,6 @@ public function testProviderHasBootMethod() $this->assertTrue(method_exists($this->provider, 'boot')); } - public function testProviderRegistersAssetServiceAsSingleton() - { - $this->assertTrue($this->app->bound(AssetService::class)); - $this->assertInstanceOf(AssetService::class, $this->app->make(AssetService::class)); - $this->assertSame($this->app->make(AssetService::class), $this->app->make(AssetService::class)); - } - public function testProviderRegistersBuildTaskServiceAsSingleton() { $this->assertTrue($this->app->bound(BuildTaskService::class)); From 293234076c1c20558799f19bb82afbd6afaaa7f0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:51:42 +0200 Subject: [PATCH 027/328] Extend unit test case --- packages/framework/tests/Unit/Facades/AssetFacadeTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeTest.php index df8344a3771..5bc4f02d01a 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeTest.php @@ -6,12 +6,12 @@ use Hyde\Facades\Asset; use Hyde\Framework\Services\AssetService; -use Hyde\Testing\TestCase; +use Hyde\Testing\UnitTestCase; /** * @covers \Hyde\Facades\Asset */ -class AssetFacadeTest extends TestCase +class AssetFacadeTest extends UnitTestCase { public function testAssetFacadeReturnsTheAssetService() { From 730f17783fabd039c9d1c658d52d381498be2e3a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:52:04 +0200 Subject: [PATCH 028/328] Remove legacy facade implementation tests --- .../tests/Unit/Facades/AssetFacadeTest.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeTest.php index 5bc4f02d01a..8335c4c7159 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeTest.php @@ -5,7 +5,6 @@ namespace Hyde\Framework\Testing\Unit\Facades; use Hyde\Facades\Asset; -use Hyde\Framework\Services\AssetService; use Hyde\Testing\UnitTestCase; /** @@ -13,19 +12,5 @@ */ class AssetFacadeTest extends UnitTestCase { - public function testAssetFacadeReturnsTheAssetService() - { - $this->assertInstanceOf(AssetService::class, Asset::getFacadeRoot()); - } - - public function testFacadeReturnsSameInstanceAsBoundByTheContainer() - { - $this->assertSame(Asset::getFacadeRoot(), app(AssetService::class)); - } - - public function testAssetFacadeCanCallMethodsOnTheAssetService() - { - $service = new AssetService(); - $this->assertEquals($service->version(), Asset::version()); - } + // } From 3e4d02377139f8bdaeb51e79ae43ba26bfc92f8f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:52:59 +0200 Subject: [PATCH 029/328] Move unit tests to new code location --- .../tests/Unit/AssetServiceUnitTest.php | 50 +------------------ .../tests/Unit/Facades/AssetFacadeTest.php | 50 ++++++++++++++++++- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/packages/framework/tests/Unit/AssetServiceUnitTest.php b/packages/framework/tests/Unit/AssetServiceUnitTest.php index 02c33795d15..21f80004078 100644 --- a/packages/framework/tests/Unit/AssetServiceUnitTest.php +++ b/packages/framework/tests/Unit/AssetServiceUnitTest.php @@ -4,9 +4,7 @@ namespace Hyde\Framework\Testing\Unit; -use Hyde\Framework\Services\AssetService; use Hyde\Testing\UnitTestCase; -use Hyde\Hyde; /** * @covers \Hyde\Framework\Services\AssetService @@ -15,51 +13,5 @@ */ class AssetServiceUnitTest extends UnitTestCase { - protected function setUp(): void - { - self::needsKernel(); - self::mockConfig(); - } - - public function testServiceHasVersionString() - { - $this->assertIsString((new AssetService())->version()); - } - - public function testCdnLinkHelper() - { - $this->assertSame( - 'https://cdn.jsdelivr.net/npm/hydefront@v3.4/dist/styles.css', - (new AssetService())->cdnLink('styles.css') - ); - } - - public function testHasMediaFileHelper() - { - $this->assertFalse((new AssetService())->hasMediaFile('styles.css')); - } - - public function testHasMediaFileHelperReturnsTrueForExistingFile() - { - $this->assertTrue((new AssetService())->hasMediaFile('app.css')); - } - - public function testInjectTailwindConfigReturnsExtractedTailwindConfig() - { - $service = new AssetService(); - $this->assertIsString($config = $service->injectTailwindConfig()); - $this->assertStringContainsString("darkMode: 'class'", $config); - $this->assertStringContainsString('theme: {', $config); - $this->assertStringContainsString('extend: {', $config); - $this->assertStringContainsString('typography: {', $config); - $this->assertStringNotContainsString('plugins', $config); - } - - public function testInjectTailwindConfigHandlesMissingConfigFileGracefully() - { - rename(Hyde::path('tailwind.config.js'), Hyde::path('tailwind.config.js.bak')); - $this->assertIsString((new AssetService())->injectTailwindConfig()); - $this->assertSame('', (new AssetService())->injectTailwindConfig()); - rename(Hyde::path('tailwind.config.js.bak'), Hyde::path('tailwind.config.js')); - } + // } diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeTest.php index 8335c4c7159..7d65f59d626 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeTest.php @@ -4,13 +4,61 @@ namespace Hyde\Framework\Testing\Unit\Facades; +use Hyde\Hyde; use Hyde\Facades\Asset; use Hyde\Testing\UnitTestCase; +use Hyde\Framework\Services\AssetService; /** * @covers \Hyde\Facades\Asset */ class AssetFacadeTest extends UnitTestCase { - // + protected function setUp(): void + { + self::needsKernel(); + self::mockConfig(); + } + + public function testServiceHasVersionString() + { + $this->assertIsString((new AssetService())->version()); + } + + public function testCdnLinkHelper() + { + $this->assertSame( + 'https://cdn.jsdelivr.net/npm/hydefront@v3.4/dist/styles.css', + (new AssetService())->cdnLink('styles.css') + ); + } + + public function testHasMediaFileHelper() + { + $this->assertFalse((new AssetService())->hasMediaFile('styles.css')); + } + + public function testHasMediaFileHelperReturnsTrueForExistingFile() + { + $this->assertTrue((new AssetService())->hasMediaFile('app.css')); + } + + public function testInjectTailwindConfigReturnsExtractedTailwindConfig() + { + $service = new AssetService(); + $this->assertIsString($config = $service->injectTailwindConfig()); + $this->assertStringContainsString("darkMode: 'class'", $config); + $this->assertStringContainsString('theme: {', $config); + $this->assertStringContainsString('extend: {', $config); + $this->assertStringContainsString('typography: {', $config); + $this->assertStringNotContainsString('plugins', $config); + } + + public function testInjectTailwindConfigHandlesMissingConfigFileGracefully() + { + rename(Hyde::path('tailwind.config.js'), Hyde::path('tailwind.config.js.bak')); + $this->assertIsString((new AssetService())->injectTailwindConfig()); + $this->assertSame('', (new AssetService())->injectTailwindConfig()); + rename(Hyde::path('tailwind.config.js.bak'), Hyde::path('tailwind.config.js')); + } } From e8d9939ad2724f6234a4031268eb04aca0dd1f86 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:56:26 +0200 Subject: [PATCH 030/328] Add temporary test interoperability --- packages/framework/tests/Unit/Facades/AssetFacadeTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeTest.php index 7d65f59d626..a2dae835e85 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeTest.php @@ -18,6 +18,9 @@ protected function setUp(): void { self::needsKernel(); self::mockConfig(); + + // Temporary interoperability with the old AssetService + Asset::swap(new AssetService()); } public function testServiceHasVersionString() From 422e96612c16947a11da0c15330659e0ffd8ff8e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:57:16 +0200 Subject: [PATCH 031/328] Call tests using the facade --- .../framework/tests/Unit/Facades/AssetFacadeTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeTest.php index a2dae835e85..a2e5ec2bf28 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeTest.php @@ -25,25 +25,25 @@ protected function setUp(): void public function testServiceHasVersionString() { - $this->assertIsString((new AssetService())->version()); + $this->assertIsString(Asset::version()); } public function testCdnLinkHelper() { $this->assertSame( 'https://cdn.jsdelivr.net/npm/hydefront@v3.4/dist/styles.css', - (new AssetService())->cdnLink('styles.css') + Asset::cdnLink('styles.css') ); } public function testHasMediaFileHelper() { - $this->assertFalse((new AssetService())->hasMediaFile('styles.css')); + $this->assertFalse(Asset::hasMediaFile('styles.css')); } public function testHasMediaFileHelperReturnsTrueForExistingFile() { - $this->assertTrue((new AssetService())->hasMediaFile('app.css')); + $this->assertTrue(Asset::hasMediaFile('app.css')); } public function testInjectTailwindConfigReturnsExtractedTailwindConfig() @@ -60,8 +60,8 @@ public function testInjectTailwindConfigReturnsExtractedTailwindConfig() public function testInjectTailwindConfigHandlesMissingConfigFileGracefully() { rename(Hyde::path('tailwind.config.js'), Hyde::path('tailwind.config.js.bak')); - $this->assertIsString((new AssetService())->injectTailwindConfig()); - $this->assertSame('', (new AssetService())->injectTailwindConfig()); + $this->assertIsString(Asset::injectTailwindConfig()); + $this->assertSame('', Asset::injectTailwindConfig()); rename(Hyde::path('tailwind.config.js.bak'), Hyde::path('tailwind.config.js')); } } From db2e12ecb18421ebf6cb0c8d843b866fae80d316 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:57:18 +0200 Subject: [PATCH 032/328] Delete AssetServiceUnitTest.php --- .../tests/Unit/AssetServiceUnitTest.php | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 packages/framework/tests/Unit/AssetServiceUnitTest.php diff --git a/packages/framework/tests/Unit/AssetServiceUnitTest.php b/packages/framework/tests/Unit/AssetServiceUnitTest.php deleted file mode 100644 index 21f80004078..00000000000 --- a/packages/framework/tests/Unit/AssetServiceUnitTest.php +++ /dev/null @@ -1,17 +0,0 @@ - Date: Fri, 26 Jul 2024 13:57:30 +0200 Subject: [PATCH 033/328] Rename test 'AssetFacadeTest' to 'AssetFacadeUnitTest' --- .../Facades/{AssetFacadeTest.php => AssetFacadeUnitTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/framework/tests/Unit/Facades/{AssetFacadeTest.php => AssetFacadeUnitTest.php} (97%) diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php similarity index 97% rename from packages/framework/tests/Unit/Facades/AssetFacadeTest.php rename to packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php index a2e5ec2bf28..724981cfea6 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php @@ -12,7 +12,7 @@ /** * @covers \Hyde\Facades\Asset */ -class AssetFacadeTest extends UnitTestCase +class AssetFacadeUnitTest extends UnitTestCase { protected function setUp(): void { From 9d393ab21f5b2311dea166a889c80cfcebe10044 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:58:17 +0200 Subject: [PATCH 034/328] Rename test 'AssetServiceTest' to 'AssetFacadeTest' --- .../tests/Feature/{AssetServiceTest.php => AssetFacadeTest.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/framework/tests/Feature/{AssetServiceTest.php => AssetFacadeTest.php} (97%) diff --git a/packages/framework/tests/Feature/AssetServiceTest.php b/packages/framework/tests/Feature/AssetFacadeTest.php similarity index 97% rename from packages/framework/tests/Feature/AssetServiceTest.php rename to packages/framework/tests/Feature/AssetFacadeTest.php index ae8661b8118..2b1bcfa2be2 100644 --- a/packages/framework/tests/Feature/AssetServiceTest.php +++ b/packages/framework/tests/Feature/AssetFacadeTest.php @@ -13,7 +13,7 @@ * * @see \Hyde\Framework\Testing\Unit\AssetServiceUnitTest */ -class AssetServiceTest extends TestCase +class AssetFacadeTest extends TestCase { public function testMediaLinkReturnsMediaPathWithCacheKey() { From 171c4ac22dff39182285ea2d4c191b41e215bbb7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:58:30 +0200 Subject: [PATCH 035/328] Update covers annotation --- packages/framework/tests/Feature/AssetFacadeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/AssetFacadeTest.php b/packages/framework/tests/Feature/AssetFacadeTest.php index 2b1bcfa2be2..eb61d40829a 100644 --- a/packages/framework/tests/Feature/AssetFacadeTest.php +++ b/packages/framework/tests/Feature/AssetFacadeTest.php @@ -9,7 +9,7 @@ use Hyde\Testing\TestCase; /** - * @covers \Hyde\Framework\Services\AssetService + * @covers \Hyde\Facades\Asset * * @see \Hyde\Framework\Testing\Unit\AssetServiceUnitTest */ From 5d5f14d53cf82321cff5b18eb8b2438c6ecfb9b2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:58:59 +0200 Subject: [PATCH 036/328] Update test crosslinks --- packages/framework/tests/Feature/AssetFacadeTest.php | 2 +- packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/AssetFacadeTest.php b/packages/framework/tests/Feature/AssetFacadeTest.php index eb61d40829a..20af8244fef 100644 --- a/packages/framework/tests/Feature/AssetFacadeTest.php +++ b/packages/framework/tests/Feature/AssetFacadeTest.php @@ -11,7 +11,7 @@ /** * @covers \Hyde\Facades\Asset * - * @see \Hyde\Framework\Testing\Unit\AssetServiceUnitTest + * @see \Hyde\Framework\Testing\Unit\Facades\AssetFacadeUnitTest */ class AssetFacadeTest extends TestCase { diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php index 724981cfea6..4d210b8e071 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php @@ -11,6 +11,8 @@ /** * @covers \Hyde\Facades\Asset + * + * @see \Hyde\Framework\Testing\Feature\AssetFacadeTest */ class AssetFacadeUnitTest extends UnitTestCase { From 69b8f39353d0cce0fcdb6c84125c319c800a604a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 13:59:50 +0200 Subject: [PATCH 037/328] Call tests using the facade --- packages/framework/tests/Feature/AssetFacadeTest.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/framework/tests/Feature/AssetFacadeTest.php b/packages/framework/tests/Feature/AssetFacadeTest.php index 20af8244fef..103230b296d 100644 --- a/packages/framework/tests/Feature/AssetFacadeTest.php +++ b/packages/framework/tests/Feature/AssetFacadeTest.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Testing\Feature; +use Hyde\Facades\Asset; use Hyde\Framework\Services\AssetService; use Hyde\Hyde; use Hyde\Testing\TestCase; @@ -17,9 +18,7 @@ class AssetFacadeTest extends TestCase { public function testMediaLinkReturnsMediaPathWithCacheKey() { - $service = new AssetService(); - - $this->assertIsString($path = $service->mediaLink('app.css')); + $this->assertIsString($path = Asset::mediaLink('app.css')); $this->assertSame('media/app.css?v='.md5_file(Hyde::path('_media/app.css')), $path); } @@ -27,8 +26,7 @@ public function testMediaLinkReturnsMediaPathWithoutCacheKeyIfCacheBustingIsDisa { config(['hyde.enable_cache_busting' => false]); - $service = new AssetService(); - $path = $service->mediaLink('app.css'); + $path = Asset::mediaLink('app.css'); $this->assertIsString($path); $this->assertSame('media/app.css', $path); @@ -41,8 +39,7 @@ public function testMediaLinkSupportsCustomMediaDirectories() Hyde::setMediaDirectory('_assets'); - $service = new AssetService(); - $path = $service->mediaLink('app.css'); + $path = Asset::mediaLink('app.css'); $this->assertIsString($path); $this->assertSame('assets/app.css?v='.md5_file(Hyde::path('_assets/app.css')), $path); From 5b48cef8bf7782b4bb4d4a5121dde41ed6163e95 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:03:12 +0200 Subject: [PATCH 038/328] Refactor class to be static --- .../src/Framework/Services/AssetService.php | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/framework/src/Framework/Services/AssetService.php b/packages/framework/src/Framework/Services/AssetService.php index 82804bb6920..7391d1bcfdb 100644 --- a/packages/framework/src/Framework/Services/AssetService.php +++ b/packages/framework/src/Framework/Services/AssetService.php @@ -23,9 +23,7 @@ * * @deprecated Will be merged into the Asset facade. * - * This class is loaded into the service container, making it easy to access and modify. - * - * The class also provides helper methods for interacting with versioned files, + * This class provides static methods for interacting with versioned files, * as well as the HydeFront CDN service and the media directories. * * @see \Hyde\Facades\Asset @@ -41,27 +39,27 @@ class AssetService protected string $version = self::HYDEFRONT_VERSION; protected string $cdnUrl = self::HYDEFRONT_CDN_URL; - public function version(): string + public static function version(): string { - return $this->version; + return static::HYDEFRONT_VERSION; } - public function cdnLink(string $file): string + public static function cdnLink(string $file): string { - return $this->constructCdnPath($file); + return static::constructCdnPath($file); } - public function mediaLink(string $file): string + public static function mediaLink(string $file): string { - return Hyde::mediaLink($file).$this->getCacheBustKey($file); + return Hyde::mediaLink($file).static::getCacheBustKey($file); } - public function hasMediaFile(string $file): bool + public static function hasMediaFile(string $file): bool { return file_exists(Hyde::mediaPath($file)); } - public function injectTailwindConfig(): string + public static function injectTailwindConfig(): string { if (! file_exists(Hyde::path('tailwind.config.js'))) { return ''; @@ -79,15 +77,15 @@ public function injectTailwindConfig(): string return preg_replace('/\s+/', ' ', "/* tailwind.config.js */ \n".rtrim($config, ",\n\r")); } - protected function constructCdnPath(string $file): string + protected static function constructCdnPath(string $file): string { return str_replace( - ['{{ $version }}', '{{ $file }}'], [$this->version(), $file], - $this->cdnUrl + ['{{ $version }}', '{{ $file }}'], [static::version(), $file], + static::HYDEFRONT_CDN_URL ); } - protected function getCacheBustKey(string $file): string + protected static function getCacheBustKey(string $file): string { return Config::getBool('hyde.enable_cache_busting', true) ? '?v='.md5_file(Hyde::mediaPath("$file")) From e4886a729ba7518dcbc542eede7fafc578aabcb3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:03:26 +0200 Subject: [PATCH 039/328] Remove now unused properties --- packages/framework/src/Framework/Services/AssetService.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/framework/src/Framework/Services/AssetService.php b/packages/framework/src/Framework/Services/AssetService.php index 7391d1bcfdb..6796f31a9d8 100644 --- a/packages/framework/src/Framework/Services/AssetService.php +++ b/packages/framework/src/Framework/Services/AssetService.php @@ -36,9 +36,6 @@ class AssetService /** @var string The default HydeFront CDN path pattern. The Blade-style placeholders are replaced with the proper values. */ final protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}'; - protected string $version = self::HYDEFRONT_VERSION; - protected string $cdnUrl = self::HYDEFRONT_CDN_URL; - public static function version(): string { return static::HYDEFRONT_VERSION; From 50600abebe5a3fcb4a92b830873f8b24f249b204 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:05:41 +0200 Subject: [PATCH 040/328] Call tests using the facade --- packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php index 4d210b8e071..b7545267e0f 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php @@ -50,8 +50,7 @@ public function testHasMediaFileHelperReturnsTrueForExistingFile() public function testInjectTailwindConfigReturnsExtractedTailwindConfig() { - $service = new AssetService(); - $this->assertIsString($config = $service->injectTailwindConfig()); + $this->assertIsString($config = Asset::injectTailwindConfig()); $this->assertStringContainsString("darkMode: 'class'", $config); $this->assertStringContainsString('theme: {', $config); $this->assertStringContainsString('extend: {', $config); From f801942c40ac6eb9651a84e0a52a23f7df523d42 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:05:53 +0200 Subject: [PATCH 041/328] Revert temporary test interoperability --- packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php index b7545267e0f..c300236bc8d 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php @@ -7,7 +7,6 @@ use Hyde\Hyde; use Hyde\Facades\Asset; use Hyde\Testing\UnitTestCase; -use Hyde\Framework\Services\AssetService; /** * @covers \Hyde\Facades\Asset @@ -20,9 +19,6 @@ protected function setUp(): void { self::needsKernel(); self::mockConfig(); - - // Temporary interoperability with the old AssetService - Asset::swap(new AssetService()); } public function testServiceHasVersionString() From 1675dd09a17443a86219210a29eb492eb2973765 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:06:33 +0200 Subject: [PATCH 042/328] Merge the AssetService into the Asset facade class --- packages/framework/src/Facades/Asset.php | 84 ++++++++++++++++--- .../src/Framework/Services/AssetService.php | 76 +---------------- 2 files changed, 72 insertions(+), 88 deletions(-) diff --git a/packages/framework/src/Facades/Asset.php b/packages/framework/src/Facades/Asset.php index f0bd3b6c651..49065d3b352 100644 --- a/packages/framework/src/Facades/Asset.php +++ b/packages/framework/src/Facades/Asset.php @@ -4,25 +4,83 @@ namespace Hyde\Facades; -use Hyde\Framework\Services\AssetService; -use Illuminate\Support\Facades\Facade; +use Hyde\Hyde; +use Illuminate\Support\Str; + +use function rtrim; +use function explode; +use function implode; +use function md5_file; +use function file_exists; +use function str_replace; +use function preg_replace; +use function str_contains; +use function file_get_contents; /** * Handles the retrieval of core asset files, either from the HydeFront CDN or from the local media folder. * - * @see \Hyde\Framework\Services\AssetService - * - * @method static string version() - * @method static string cdnLink(string $file) - * @method static string mediaLink(string $file) - * @method static bool hasMediaFile(string $file) - * @method static string injectTailwindConfig() + * This class provides static methods for interacting with versioned files, + * as well as the HydeFront CDN service and the media directories. */ -class Asset extends Facade +class Asset { - /** @psalm-return AssetService::class */ - protected static function getFacadeAccessor(): string + /** @var string The default HydeFront SemVer tag to load. This constant is set to match the styles used for the installed framework version. */ + final protected const HYDEFRONT_VERSION = 'v3.4'; + + /** @var string The default HydeFront CDN path pattern. The Blade-style placeholders are replaced with the proper values. */ + final protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}'; + + public static function version(): string + { + return static::HYDEFRONT_VERSION; + } + + public static function cdnLink(string $file): string + { + return static::constructCdnPath($file); + } + + public static function mediaLink(string $file): string + { + return Hyde::mediaLink($file).static::getCacheBustKey($file); + } + + public static function hasMediaFile(string $file): bool + { + return file_exists(Hyde::mediaPath($file)); + } + + public static function injectTailwindConfig(): string + { + if (! file_exists(Hyde::path('tailwind.config.js'))) { + return ''; + } + + $config = Str::between(file_get_contents(Hyde::path('tailwind.config.js')), '{', '}'); + + // Remove the plugins array, as it is not used in the frontend. + if (str_contains($config, 'plugins: [')) { + $tokens = explode('plugins: [', $config, 2); + $tokens[1] = Str::after($tokens[1], ']'); + $config = implode('', $tokens); + } + + return preg_replace('/\s+/', ' ', "/* tailwind.config.js */ \n".rtrim($config, ",\n\r")); + } + + protected static function constructCdnPath(string $file): string + { + return str_replace( + ['{{ $version }}', '{{ $file }}'], [static::version(), $file], + static::HYDEFRONT_CDN_URL + ); + } + + protected static function getCacheBustKey(string $file): string { - return AssetService::class; + return Config::getBool('hyde.enable_cache_busting', true) + ? '?v='.md5_file(Hyde::mediaPath("$file")) + : ''; } } diff --git a/packages/framework/src/Framework/Services/AssetService.php b/packages/framework/src/Framework/Services/AssetService.php index 6796f31a9d8..d6159d32535 100644 --- a/packages/framework/src/Framework/Services/AssetService.php +++ b/packages/framework/src/Framework/Services/AssetService.php @@ -4,88 +4,14 @@ namespace Hyde\Framework\Services; -use Hyde\Hyde; -use Hyde\Facades\Config; -use Illuminate\Support\Str; - -use function rtrim; -use function explode; -use function implode; -use function md5_file; -use function file_exists; -use function str_replace; -use function preg_replace; -use function str_contains; -use function file_get_contents; - /** * Handles the retrieval of core asset files. Commonly used through the Asset facade. * * @deprecated Will be merged into the Asset facade. * - * This class provides static methods for interacting with versioned files, - * as well as the HydeFront CDN service and the media directories. - * * @see \Hyde\Facades\Asset */ class AssetService { - /** @var string The default HydeFront SemVer tag to load. This constant is set to match the styles used for the installed framework version. */ - final protected const HYDEFRONT_VERSION = 'v3.4'; - - /** @var string The default HydeFront CDN path pattern. The Blade-style placeholders are replaced with the proper values. */ - final protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}'; - - public static function version(): string - { - return static::HYDEFRONT_VERSION; - } - - public static function cdnLink(string $file): string - { - return static::constructCdnPath($file); - } - - public static function mediaLink(string $file): string - { - return Hyde::mediaLink($file).static::getCacheBustKey($file); - } - - public static function hasMediaFile(string $file): bool - { - return file_exists(Hyde::mediaPath($file)); - } - - public static function injectTailwindConfig(): string - { - if (! file_exists(Hyde::path('tailwind.config.js'))) { - return ''; - } - - $config = Str::between(file_get_contents(Hyde::path('tailwind.config.js')), '{', '}'); - - // Remove the plugins array, as it is not used in the frontend. - if (str_contains($config, 'plugins: [')) { - $tokens = explode('plugins: [', $config, 2); - $tokens[1] = Str::after($tokens[1], ']'); - $config = implode('', $tokens); - } - - return preg_replace('/\s+/', ' ', "/* tailwind.config.js */ \n".rtrim($config, ",\n\r")); - } - - protected static function constructCdnPath(string $file): string - { - return str_replace( - ['{{ $version }}', '{{ $file }}'], [static::version(), $file], - static::HYDEFRONT_CDN_URL - ); - } - - protected static function getCacheBustKey(string $file): string - { - return Config::getBool('hyde.enable_cache_busting', true) - ? '?v='.md5_file(Hyde::mediaPath("$file")) - : ''; - } + // } From fb0e40c4c22eb82aac6f08411360d960a25161be Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:06:46 +0200 Subject: [PATCH 043/328] Delete AssetService.php --- .../src/Framework/Services/AssetService.php | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 packages/framework/src/Framework/Services/AssetService.php diff --git a/packages/framework/src/Framework/Services/AssetService.php b/packages/framework/src/Framework/Services/AssetService.php deleted file mode 100644 index d6159d32535..00000000000 --- a/packages/framework/src/Framework/Services/AssetService.php +++ /dev/null @@ -1,17 +0,0 @@ - Date: Fri, 26 Jul 2024 14:08:04 +0200 Subject: [PATCH 044/328] Remove unused import --- packages/framework/tests/Feature/AssetFacadeTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/framework/tests/Feature/AssetFacadeTest.php b/packages/framework/tests/Feature/AssetFacadeTest.php index 103230b296d..3e934eab38b 100644 --- a/packages/framework/tests/Feature/AssetFacadeTest.php +++ b/packages/framework/tests/Feature/AssetFacadeTest.php @@ -5,7 +5,6 @@ namespace Hyde\Framework\Testing\Feature; use Hyde\Facades\Asset; -use Hyde\Framework\Services\AssetService; use Hyde\Hyde; use Hyde\Testing\TestCase; From f0192f58f34404aa0d19406e0ab2707fa237e660 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:08:15 +0200 Subject: [PATCH 045/328] Remove AssetService container binding --- packages/framework/src/Framework/HydeServiceProvider.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/framework/src/Framework/HydeServiceProvider.php b/packages/framework/src/Framework/HydeServiceProvider.php index c2896efdc9b..e3dbd7eb5ea 100644 --- a/packages/framework/src/Framework/HydeServiceProvider.php +++ b/packages/framework/src/Framework/HydeServiceProvider.php @@ -10,7 +10,6 @@ use Hyde\Pages\MarkdownPost; use Hyde\Foundation\HydeKernel; use Hyde\Pages\DocumentationPage; -use Hyde\Framework\Services\AssetService; use Hyde\Framework\Services\BuildTaskService; use Hyde\Framework\Concerns\RegistersFileLocations; use Illuminate\Support\ServiceProvider; @@ -29,7 +28,6 @@ public function register(): void { $this->kernel = HydeKernel::getInstance(); - $this->app->singleton(AssetService::class, AssetService::class); $this->app->singleton(BuildTaskService::class, BuildTaskService::class); $this->kernel->setSourceRoot(Config::getString('hyde.source_root', '')); From 83e69f8d43cec53483a341158306e67dfbf816b8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:12:35 +0200 Subject: [PATCH 046/328] Update internal docs for removed asset service --- monorepo/docs/hydefront.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monorepo/docs/hydefront.md b/monorepo/docs/hydefront.md index 377f920e6e0..cb7733eabcd 100644 --- a/monorepo/docs/hydefront.md +++ b/monorepo/docs/hydefront.md @@ -64,6 +64,6 @@ This will create commits in both the monorepo and submodule. Now follow the foll 9. Update the monorepo to use the new version. - [ ] `npm update hydefront` - **Note:** On major/minor version bumps, **remember to update** the `package.json` in the `packages/hyde` directory to use the new version! - - **Note:** On major version bumps, **remember to update the HydeFront version in the Asset Service!** + - **Note:** On major version bumps, **remember to update the HydeFront version in the Asset Facade!** 10. Amend the monorepo commit with the updated files (package-lock.json, _media/app.css, packages\hydefront, packages\hyde\package.json) - - [ ] `git add packages/hydefront && git add packages/hyde/package.json && git add package-lock.json && git add _media/app.css && git add packages/framework/src/Framework/Services/AssetService.php && git commit --amend --no-edit` + - [ ] `git add packages/hydefront && git add packages/hyde/package.json && git add package-lock.json && git add _media/app.css && git add packages/framework/src/Facades/Asset.php && git commit --amend --no-edit` From 251ed8bea4111d8effdffc137dcf9f46333ec3be Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:13:41 +0200 Subject: [PATCH 047/328] Clean up test --- packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php index c300236bc8d..ddfafe2ec72 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php @@ -46,7 +46,9 @@ public function testHasMediaFileHelperReturnsTrueForExistingFile() public function testInjectTailwindConfigReturnsExtractedTailwindConfig() { - $this->assertIsString($config = Asset::injectTailwindConfig()); + $config = Asset::injectTailwindConfig(); + + $this->assertIsString($config); $this->assertStringContainsString("darkMode: 'class'", $config); $this->assertStringContainsString('theme: {', $config); $this->assertStringContainsString('extend: {', $config); From 02dbc14b919b7c495d9d535d0e5f39248fdbbaff Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:25:19 +0200 Subject: [PATCH 048/328] Create HydeFront.php --- packages/framework/src/Facades/HydeFront.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 packages/framework/src/Facades/HydeFront.php diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php new file mode 100644 index 00000000000..5f5448313ee --- /dev/null +++ b/packages/framework/src/Facades/HydeFront.php @@ -0,0 +1,10 @@ + Date: Fri, 26 Jul 2024 14:26:32 +0200 Subject: [PATCH 049/328] Create HydeFrontFacadeTest.php --- .../tests/Unit/Facades/HydeFrontFacadeTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php diff --git a/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php b/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php new file mode 100644 index 00000000000..e4c6d9e192f --- /dev/null +++ b/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php @@ -0,0 +1,15 @@ + Date: Fri, 26 Jul 2024 14:26:53 +0200 Subject: [PATCH 050/328] Alias the HydeFront facade --- app/config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/config.php b/app/config.php index 143a4a6dda4..009c0f586b7 100644 --- a/app/config.php +++ b/app/config.php @@ -94,6 +94,7 @@ 'Meta' => \Hyde\Facades\Meta::class, 'Asset' => \Hyde\Facades\Asset::class, 'Author' => \Hyde\Facades\Author::class, + 'HydeFront' => \Hyde\Facades\HydeFront::class, 'Features' => \Hyde\Facades\Features::class, 'Config' => \Hyde\Facades\Config::class, 'Filesystem' => \Hyde\Facades\Filesystem::class, From ee69a0a9e0b44afa58d7fce5f326450673292157 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:48:20 +0200 Subject: [PATCH 051/328] Move HydeFront related methods to the new HydeFront facade --- packages/framework/src/Facades/Asset.php | 53 ++++++++----------- packages/framework/src/Facades/HydeFront.php | 27 +++++++++- .../Unit/Facades/AssetFacadeUnitTest.php | 13 ----- .../Unit/Facades/HydeFrontFacadeTest.php | 12 ++++- 4 files changed, 60 insertions(+), 45 deletions(-) diff --git a/packages/framework/src/Facades/Asset.php b/packages/framework/src/Facades/Asset.php index 49065d3b352..6d7a3afaeb3 100644 --- a/packages/framework/src/Facades/Asset.php +++ b/packages/framework/src/Facades/Asset.php @@ -6,15 +6,10 @@ use Hyde\Hyde; use Illuminate\Support\Str; +use JetBrains\PhpStorm\Deprecated; -use function rtrim; -use function explode; -use function implode; use function md5_file; use function file_exists; -use function str_replace; -use function preg_replace; -use function str_contains; use function file_get_contents; /** @@ -25,22 +20,6 @@ */ class Asset { - /** @var string The default HydeFront SemVer tag to load. This constant is set to match the styles used for the installed framework version. */ - final protected const HYDEFRONT_VERSION = 'v3.4'; - - /** @var string The default HydeFront CDN path pattern. The Blade-style placeholders are replaced with the proper values. */ - final protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}'; - - public static function version(): string - { - return static::HYDEFRONT_VERSION; - } - - public static function cdnLink(string $file): string - { - return static::constructCdnPath($file); - } - public static function mediaLink(string $file): string { return Hyde::mediaLink($file).static::getCacheBustKey($file); @@ -69,18 +48,32 @@ public static function injectTailwindConfig(): string return preg_replace('/\s+/', ' ', "/* tailwind.config.js */ \n".rtrim($config, ",\n\r")); } - protected static function constructCdnPath(string $file): string - { - return str_replace( - ['{{ $version }}', '{{ $file }}'], [static::version(), $file], - static::HYDEFRONT_CDN_URL - ); - } - protected static function getCacheBustKey(string $file): string { return Config::getBool('hyde.enable_cache_busting', true) ? '?v='.md5_file(Hyde::mediaPath("$file")) : ''; } + + /** + * @deprecated Use HydeFront::version() instead. + * + * @codeCoverageIgnore Deprecated method. + */ + #[Deprecated(reason: 'Use HydeFront::version() instead.', replacement: '\Hyde\Facades\HydeFront::version()')] + public static function version(): string + { + return HydeFront::version(); + } + + /** + * @deprecated Use HydeFront::cdnLink() instead. + * + * @codeCoverageIgnore Deprecated method. + */ + #[Deprecated(reason: 'Use HydeFront::cdnLink() instead.', replacement: '\Hyde\Facades\HydeFront::cdnLink()')] + public static function cdnLink(string $file): string + { + return HydeFront::cdnLink($file); + } } diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index 5f5448313ee..e3b5c76f606 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -4,7 +4,32 @@ namespace Hyde\Facades; +use function str_replace; + class HydeFront { - // + /** @var string The default HydeFront SemVer tag to load. This constant is set to match the styles used for the installed framework version. */ + final protected const HYDEFRONT_VERSION = 'v3.4'; + + /** @var string The default HydeFront CDN path pattern. The Blade-style placeholders are replaced with the proper values. */ + final protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}'; + + public static function version(): string + { + return static::HYDEFRONT_VERSION; + } + + public static function cdnLink(string $file): string + { + return static::constructCdnPath($file); + } + + protected static function constructCdnPath(string $file): string + { + return str_replace( + ['{{ $version }}', '{{ $file }}'], + [static::version(), $file], + static::HYDEFRONT_CDN_URL + ); + } } diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php index ddfafe2ec72..81cbfc029b4 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php @@ -21,19 +21,6 @@ protected function setUp(): void self::mockConfig(); } - public function testServiceHasVersionString() - { - $this->assertIsString(Asset::version()); - } - - public function testCdnLinkHelper() - { - $this->assertSame( - 'https://cdn.jsdelivr.net/npm/hydefront@v3.4/dist/styles.css', - Asset::cdnLink('styles.css') - ); - } - public function testHasMediaFileHelper() { $this->assertFalse(Asset::hasMediaFile('styles.css')); diff --git a/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php b/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php index e4c6d9e192f..37425127bf7 100644 --- a/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Testing\Unit\Facades; +use Hyde\Facades\HydeFront; use Hyde\Testing\UnitTestCase; /** @@ -11,5 +12,14 @@ */ class HydeFrontFacadeTest extends UnitTestCase { - // + public function testVersionReturnsString() + { + $this->assertIsString(HydeFront::version()); + } + + public function testCdnLinkReturnsCorrectUrl() + { + $expected = 'https://cdn.jsdelivr.net/npm/hydefront@v3.4/dist/styles.css'; + $this->assertSame($expected, HydeFront::cdnLink('styles.css')); + } } From 3db1b29adce5f88299de0fc990ce3b19ad3ecfd8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:54:25 +0200 Subject: [PATCH 052/328] Use the new HydeFront facade --- packages/framework/resources/views/layouts/styles.blade.php | 2 +- .../framework/tests/Unit/Views/StylesComponentViewTest.php | 4 ++-- spec.md | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/framework/resources/views/layouts/styles.blade.php b/packages/framework/resources/views/layouts/styles.blade.php index 497e524ae1b..2a345a4ce18 100644 --- a/packages/framework/resources/views/layouts/styles.blade.php +++ b/packages/framework/resources/views/layouts/styles.blade.php @@ -3,7 +3,7 @@ {{-- The compiled Tailwind/App styles --}} @if(config('hyde.load_app_styles_from_cdn', false)) - + @elseif(Asset::hasMediaFile('app.css')) @endif diff --git a/packages/framework/tests/Unit/Views/StylesComponentViewTest.php b/packages/framework/tests/Unit/Views/StylesComponentViewTest.php index bfe078d00f1..bb5358f9e08 100644 --- a/packages/framework/tests/Unit/Views/StylesComponentViewTest.php +++ b/packages/framework/tests/Unit/Views/StylesComponentViewTest.php @@ -5,7 +5,7 @@ namespace Hyde\Framework\Testing\Unit\Views; use Hyde\Facades\Filesystem; -use Hyde\Facades\Asset; +use Hyde\Facades\HydeFront; use Hyde\Hyde; use Hyde\Support\Facades\Render; use Hyde\Testing\TestCase; @@ -80,7 +80,7 @@ public function testComponentRendersTailwindPlayCdnLinkWhenEnabledInConfig() public function testComponentRendersAppCdnLinkWhenEnabledInConfig() { config(['hyde.load_app_styles_from_cdn' => true]); - $this->assertStringContainsString(Asset::cdnLink('app.css'), $this->renderTestView()); + $this->assertStringContainsString(HydeFront::cdnLink('app.css'), $this->renderTestView()); } public function testComponentDoesNotRenderLinkToLocalAppCssWhenCdnLinkIsEnabledInConfig() diff --git a/spec.md b/spec.md index b404251e8ea..a1ca493ac41 100644 --- a/spec.md +++ b/spec.md @@ -15,7 +15,7 @@ For example: Consider these Blade snippets from the default views, showing commo ```blade {{-- The compiled Tailwind/App styles --}} @if(config('hyde.load_app_styles_from_cdn', false)) - + @elseif(Asset::hasMediaFile('app.css')) @endif @@ -61,7 +61,7 @@ protected function setSource(string $source): string { ### Asset Facade ```php -Asset::cdnLink(string $file) // Gets remote URL to any file in /dist/ in the HydeFront version +HydeFront::cdnLink(string $file) // Gets remote URL to any file in /dist/ in the HydeFront version Asset::mediaLink(string $file) // Returns Hyde::mediaLink but with a cache buster Asset::hasMediaFile(string $file) // Returns file_exists(Hyde::mediaPath($file)) @@ -576,7 +576,7 @@ $size = $logo->getSize(); $mimeType = $logo->getMimeType(); // HydeFront CDN link (for app.js or app.css) -$appJsUrl = Asset::cdnLink('app.js'); +$appJsUrl = HydeFront::cdnLink('app.js'); ``` This API maintains the simplicity-first approach of Hyde while providing power when needed. It should be intuitive for both Laravel-familiar developers and those new to the framework, aligning well with Hyde's philosophy and goals. From f5b752610ac5d9f8027afcaa13428669215b8110 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:52:35 +0200 Subject: [PATCH 053/328] Remove deprecated Asset facade methods See https://github.com/hydephp/develop/pull/1904 for why we are skipping the normal deprecation process. --- packages/framework/src/Facades/Asset.php | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/packages/framework/src/Facades/Asset.php b/packages/framework/src/Facades/Asset.php index 6d7a3afaeb3..2300dd6dc72 100644 --- a/packages/framework/src/Facades/Asset.php +++ b/packages/framework/src/Facades/Asset.php @@ -6,7 +6,6 @@ use Hyde\Hyde; use Illuminate\Support\Str; -use JetBrains\PhpStorm\Deprecated; use function md5_file; use function file_exists; @@ -54,26 +53,4 @@ protected static function getCacheBustKey(string $file): string ? '?v='.md5_file(Hyde::mediaPath("$file")) : ''; } - - /** - * @deprecated Use HydeFront::version() instead. - * - * @codeCoverageIgnore Deprecated method. - */ - #[Deprecated(reason: 'Use HydeFront::version() instead.', replacement: '\Hyde\Facades\HydeFront::version()')] - public static function version(): string - { - return HydeFront::version(); - } - - /** - * @deprecated Use HydeFront::cdnLink() instead. - * - * @codeCoverageIgnore Deprecated method. - */ - #[Deprecated(reason: 'Use HydeFront::cdnLink() instead.', replacement: '\Hyde\Facades\HydeFront::cdnLink()')] - public static function cdnLink(string $file): string - { - return HydeFront::cdnLink($file); - } } From 48a8a94aa8a54f85b3cbeab72594aae8189f3f2e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 14:58:06 +0200 Subject: [PATCH 054/328] Remove unnecessary final modifiers from protected constants --- packages/framework/src/Facades/HydeFront.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index e3b5c76f606..22a25793caa 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -9,10 +9,10 @@ class HydeFront { /** @var string The default HydeFront SemVer tag to load. This constant is set to match the styles used for the installed framework version. */ - final protected const HYDEFRONT_VERSION = 'v3.4'; + protected const HYDEFRONT_VERSION = 'v3.4'; /** @var string The default HydeFront CDN path pattern. The Blade-style placeholders are replaced with the proper values. */ - final protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}'; + protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}'; public static function version(): string { From 57835e62662f90e7eae97d630b992e0f93d1f209 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:00:14 +0200 Subject: [PATCH 055/328] Inline helper method --- packages/framework/src/Facades/HydeFront.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index 22a25793caa..aa45b7cfc3a 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -20,11 +20,6 @@ public static function version(): string } public static function cdnLink(string $file): string - { - return static::constructCdnPath($file); - } - - protected static function constructCdnPath(string $file): string { return str_replace( ['{{ $version }}', '{{ $file }}'], From 84a686456893f91fcf56ffed0e1fa6422af6fbda Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:00:37 +0200 Subject: [PATCH 056/328] Clean up helper method --- packages/framework/src/Facades/HydeFront.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index aa45b7cfc3a..b2a43426e92 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -22,8 +22,7 @@ public static function version(): string public static function cdnLink(string $file): string { return str_replace( - ['{{ $version }}', '{{ $file }}'], - [static::version(), $file], + ['{{ $version }}', '{{ $file }}'], [static::version(), $file], static::HYDEFRONT_CDN_URL ); } From 324b316ab148ed325df19391a220b28378f9e62d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:03:14 +0200 Subject: [PATCH 057/328] Simplify helper method implementation With the private API we can now use a more specific and cleaner implementation --- packages/framework/src/Facades/HydeFront.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index b2a43426e92..13892a380e1 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -4,15 +4,15 @@ namespace Hyde\Facades; -use function str_replace; +use function sprintf; class HydeFront { /** @var string The default HydeFront SemVer tag to load. This constant is set to match the styles used for the installed framework version. */ protected const HYDEFRONT_VERSION = 'v3.4'; - /** @var string The default HydeFront CDN path pattern. The Blade-style placeholders are replaced with the proper values. */ - protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@{{ $version }}/dist/{{ $file }}'; + /** @var string The default HydeFront CDN path pattern. */ + protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@%s/dist/%s'; public static function version(): string { @@ -21,9 +21,6 @@ public static function version(): string public static function cdnLink(string $file): string { - return str_replace( - ['{{ $version }}', '{{ $file }}'], [static::version(), $file], - static::HYDEFRONT_CDN_URL - ); + return sprintf(static::HYDEFRONT_CDN_URL, static::version(), $file); } } From f2c63bcf3186a5d98973409e79fd39d38fe5f952 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:04:33 +0200 Subject: [PATCH 058/328] Add HydeFront facade class documentation --- packages/framework/src/Facades/HydeFront.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index 13892a380e1..5c9223b7c85 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -6,6 +6,11 @@ use function sprintf; +/** + * HydeFront is the NPM package that bundles the default precompiled CSS and JavaScript assets for HydePHP. + * + * This facade makes it easy to access these assets from the HydeFront CDN, automatically getting the correct version. + */ class HydeFront { /** @var string The default HydeFront SemVer tag to load. This constant is set to match the styles used for the installed framework version. */ From 24571037a9a2ba5eac12f03ffd60267756b9ca67 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:11:24 +0200 Subject: [PATCH 059/328] Add rich PHPDoc method annotations --- packages/framework/src/Facades/HydeFront.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index 5c9223b7c85..00f5a6ce543 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -19,11 +19,21 @@ class HydeFront /** @var string The default HydeFront CDN path pattern. */ protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@%s/dist/%s'; + /** + * Get the current version of the HydeFront package. + * + * @return string {@see HYDEFRONT_VERSION} + */ public static function version(): string { return static::HYDEFRONT_VERSION; } + /** + * Get the CDN link for a specific file. + * + * @param 'app.css'|'hyde.css'|'hyde.css.map' $file + */ public static function cdnLink(string $file): string { return sprintf(static::HYDEFRONT_CDN_URL, static::version(), $file); From e33c8213a700df0da06636fdb347674d4540117b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:13:03 +0200 Subject: [PATCH 060/328] Add more tests --- .../tests/Unit/Facades/HydeFrontFacadeTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php b/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php index 37425127bf7..4afe8ee9e36 100644 --- a/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php @@ -22,4 +22,16 @@ public function testCdnLinkReturnsCorrectUrl() $expected = 'https://cdn.jsdelivr.net/npm/hydefront@v3.4/dist/styles.css'; $this->assertSame($expected, HydeFront::cdnLink('styles.css')); } + + public function testCdnLinkReturnsCorrectUrlForHydeCss() + { + $expected = 'https://cdn.jsdelivr.net/npm/hydefront@v3.4/dist/hyde.css'; + $this->assertSame($expected, HydeFront::cdnLink('hyde.css')); + } + + public function testCdnLinkReturnsCorrectUrlForInvalidFile() + { + $expected = 'https://cdn.jsdelivr.net/npm/hydefront@v3.4/dist/invalid'; + $this->assertSame($expected, HydeFront::cdnLink('invalid')); + } } From f00db0771ef14e40b146f6a5cc359ba2953bfef4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:13:28 +0200 Subject: [PATCH 061/328] Update constant comment --- packages/framework/src/Facades/HydeFront.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index 00f5a6ce543..b566839b999 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -16,7 +16,7 @@ class HydeFront /** @var string The default HydeFront SemVer tag to load. This constant is set to match the styles used for the installed framework version. */ protected const HYDEFRONT_VERSION = 'v3.4'; - /** @var string The default HydeFront CDN path pattern. */ + /** @var string The default HydeFront CDN path pattern used to assemble CDN links. */ protected const HYDEFRONT_CDN_URL = 'https://cdn.jsdelivr.net/npm/hydefront@%s/dist/%s'; /** From dc129051b7831a23ebe81f41e37783d5f8a2fac7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:17:26 +0200 Subject: [PATCH 062/328] Add todo --- packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php b/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php index 4afe8ee9e36..fd4336eff3a 100644 --- a/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php @@ -12,6 +12,8 @@ */ class HydeFrontFacadeTest extends UnitTestCase { + // Todo: Check the version is correct? (When running in monorepo) + public function testVersionReturnsString() { $this->assertIsString(HydeFront::version()); From 397e19e3d0e622dad4267d219dc159326f903d9e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:52:48 +0200 Subject: [PATCH 063/328] Move Tailwind config injection to HydeFront facade This is more coupled to HydeFront than general Asset services --- .../resources/views/layouts/styles.blade.php | 2 +- packages/framework/src/Facades/Asset.php | 20 ---------------- packages/framework/src/Facades/HydeFront.php | 21 +++++++++++++++++ .../Unit/Facades/AssetFacadeUnitTest.php | 21 ----------------- .../Unit/Facades/HydeFrontFacadeTest.php | 23 +++++++++++++++++++ 5 files changed, 45 insertions(+), 42 deletions(-) diff --git a/packages/framework/resources/views/layouts/styles.blade.php b/packages/framework/resources/views/layouts/styles.blade.php index 2a345a4ce18..d1b374d73cf 100644 --- a/packages/framework/resources/views/layouts/styles.blade.php +++ b/packages/framework/resources/views/layouts/styles.blade.php @@ -11,7 +11,7 @@ {{-- Dynamic TailwindCSS Play CDN --}} @if(config('hyde.use_play_cdn', false)) - + @endif diff --git a/packages/framework/src/Facades/Asset.php b/packages/framework/src/Facades/Asset.php index 2300dd6dc72..9691a43c211 100644 --- a/packages/framework/src/Facades/Asset.php +++ b/packages/framework/src/Facades/Asset.php @@ -5,11 +5,9 @@ namespace Hyde\Facades; use Hyde\Hyde; -use Illuminate\Support\Str; use function md5_file; use function file_exists; -use function file_get_contents; /** * Handles the retrieval of core asset files, either from the HydeFront CDN or from the local media folder. @@ -29,24 +27,6 @@ public static function hasMediaFile(string $file): bool return file_exists(Hyde::mediaPath($file)); } - public static function injectTailwindConfig(): string - { - if (! file_exists(Hyde::path('tailwind.config.js'))) { - return ''; - } - - $config = Str::between(file_get_contents(Hyde::path('tailwind.config.js')), '{', '}'); - - // Remove the plugins array, as it is not used in the frontend. - if (str_contains($config, 'plugins: [')) { - $tokens = explode('plugins: [', $config, 2); - $tokens[1] = Str::after($tokens[1], ']'); - $config = implode('', $tokens); - } - - return preg_replace('/\s+/', ' ', "/* tailwind.config.js */ \n".rtrim($config, ",\n\r")); - } - protected static function getCacheBustKey(string $file): string { return Config::getBool('hyde.enable_cache_busting', true) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index b566839b999..546989442a8 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -4,6 +4,9 @@ namespace Hyde\Facades; +use Hyde\Hyde; +use Illuminate\Support\Str; + use function sprintf; /** @@ -38,4 +41,22 @@ public static function cdnLink(string $file): string { return sprintf(static::HYDEFRONT_CDN_URL, static::version(), $file); } + + public static function injectTailwindConfig(): string + { + if (! file_exists(Hyde::path('tailwind.config.js'))) { + return ''; + } + + $config = Str::between(file_get_contents(Hyde::path('tailwind.config.js')), '{', '}'); + + // Remove the plugins array, as it is not used in the frontend. + if (str_contains($config, 'plugins: [')) { + $tokens = explode('plugins: [', $config, 2); + $tokens[1] = Str::after($tokens[1], ']'); + $config = implode('', $tokens); + } + + return preg_replace('/\s+/', ' ', "/* tailwind.config.js */ \n".rtrim($config, ",\n\r")); + } } diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php index 81cbfc029b4..4c62090bbae 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php @@ -4,7 +4,6 @@ namespace Hyde\Framework\Testing\Unit\Facades; -use Hyde\Hyde; use Hyde\Facades\Asset; use Hyde\Testing\UnitTestCase; @@ -30,24 +29,4 @@ public function testHasMediaFileHelperReturnsTrueForExistingFile() { $this->assertTrue(Asset::hasMediaFile('app.css')); } - - public function testInjectTailwindConfigReturnsExtractedTailwindConfig() - { - $config = Asset::injectTailwindConfig(); - - $this->assertIsString($config); - $this->assertStringContainsString("darkMode: 'class'", $config); - $this->assertStringContainsString('theme: {', $config); - $this->assertStringContainsString('extend: {', $config); - $this->assertStringContainsString('typography: {', $config); - $this->assertStringNotContainsString('plugins', $config); - } - - public function testInjectTailwindConfigHandlesMissingConfigFileGracefully() - { - rename(Hyde::path('tailwind.config.js'), Hyde::path('tailwind.config.js.bak')); - $this->assertIsString(Asset::injectTailwindConfig()); - $this->assertSame('', Asset::injectTailwindConfig()); - rename(Hyde::path('tailwind.config.js.bak'), Hyde::path('tailwind.config.js')); - } } diff --git a/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php b/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php index fd4336eff3a..3bcdf3a096d 100644 --- a/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php +++ b/packages/framework/tests/Unit/Facades/HydeFrontFacadeTest.php @@ -4,6 +4,7 @@ namespace Hyde\Framework\Testing\Unit\Facades; +use Hyde\Hyde; use Hyde\Facades\HydeFront; use Hyde\Testing\UnitTestCase; @@ -12,6 +13,8 @@ */ class HydeFrontFacadeTest extends UnitTestCase { + protected static bool $needsKernel = true; + // Todo: Check the version is correct? (When running in monorepo) public function testVersionReturnsString() @@ -36,4 +39,24 @@ public function testCdnLinkReturnsCorrectUrlForInvalidFile() $expected = 'https://cdn.jsdelivr.net/npm/hydefront@v3.4/dist/invalid'; $this->assertSame($expected, HydeFront::cdnLink('invalid')); } + + public function testInjectTailwindConfigReturnsExtractedTailwindConfig() + { + $config = HydeFront::injectTailwindConfig(); + + $this->assertIsString($config); + $this->assertStringContainsString("darkMode: 'class'", $config); + $this->assertStringContainsString('theme: {', $config); + $this->assertStringContainsString('extend: {', $config); + $this->assertStringContainsString('typography: {', $config); + $this->assertStringNotContainsString('plugins', $config); + } + + public function testInjectTailwindConfigHandlesMissingConfigFileGracefully() + { + rename(Hyde::path('tailwind.config.js'), Hyde::path('tailwind.config.js.bak')); + $this->assertIsString(HydeFront::injectTailwindConfig()); + $this->assertSame('', HydeFront::injectTailwindConfig()); + rename(Hyde::path('tailwind.config.js.bak'), Hyde::path('tailwind.config.js')); + } } From eb5136a7e392c2edae6cbc6c5065a1b9b4864cff Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:55:21 +0200 Subject: [PATCH 064/328] Mark method as internal --- packages/framework/src/Facades/HydeFront.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index 546989442a8..2529d2c2d91 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -42,6 +42,9 @@ public static function cdnLink(string $file): string return sprintf(static::HYDEFRONT_CDN_URL, static::version(), $file); } + /** + * @internal This method is used to inject the Tailwind CSS configuration into the Play CDN integration. + */ public static function injectTailwindConfig(): string { if (! file_exists(Hyde::path('tailwind.config.js'))) { From bbd960b49b7843a6b5afb714f333f8326b8b5dfd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:55:24 +0200 Subject: [PATCH 065/328] Revert "Mark method as internal" This reverts commit eb5136a7e392c2edae6cbc6c5065a1b9b4864cff. --- packages/framework/src/Facades/HydeFront.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index 2529d2c2d91..546989442a8 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -42,9 +42,6 @@ public static function cdnLink(string $file): string return sprintf(static::HYDEFRONT_CDN_URL, static::version(), $file); } - /** - * @internal This method is used to inject the Tailwind CSS configuration into the Play CDN integration. - */ public static function injectTailwindConfig(): string { if (! file_exists(Hyde::path('tailwind.config.js'))) { From fc5b464287f3e840def2aa718fcb90720bb5c58f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:55:55 +0200 Subject: [PATCH 066/328] Document method --- packages/framework/src/Facades/HydeFront.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index 546989442a8..97cc2bdb091 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -42,6 +42,9 @@ public static function cdnLink(string $file): string return sprintf(static::HYDEFRONT_CDN_URL, static::version(), $file); } + /** + * This method is used to inject the Tailwind CSS configuration into the Play CDN integration. + */ public static function injectTailwindConfig(): string { if (! file_exists(Hyde::path('tailwind.config.js'))) { From 63b414a88724af984843ee2c77b95e586ae986a3 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 15:56:09 +0200 Subject: [PATCH 067/328] Compress comment formatting --- packages/framework/src/Facades/HydeFront.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/framework/src/Facades/HydeFront.php b/packages/framework/src/Facades/HydeFront.php index 97cc2bdb091..ed2def95db9 100644 --- a/packages/framework/src/Facades/HydeFront.php +++ b/packages/framework/src/Facades/HydeFront.php @@ -42,9 +42,7 @@ public static function cdnLink(string $file): string return sprintf(static::HYDEFRONT_CDN_URL, static::version(), $file); } - /** - * This method is used to inject the Tailwind CSS configuration into the Play CDN integration. - */ + /** This method is used to inject the Tailwind CSS configuration into the Play CDN integration. */ public static function injectTailwindConfig(): string { if (! file_exists(Hyde::path('tailwind.config.js'))) { From 9ba410a818c2c4875a65634d4cd6cf51fd67f58a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:00:24 +0200 Subject: [PATCH 068/328] Refactor to merge feature test into unit test --- .../tests/Feature/AssetFacadeTest.php | 46 ------------------- .../Unit/Facades/AssetFacadeUnitTest.php | 44 +++++++++++++++++- 2 files changed, 42 insertions(+), 48 deletions(-) delete mode 100644 packages/framework/tests/Feature/AssetFacadeTest.php diff --git a/packages/framework/tests/Feature/AssetFacadeTest.php b/packages/framework/tests/Feature/AssetFacadeTest.php deleted file mode 100644 index 3e934eab38b..00000000000 --- a/packages/framework/tests/Feature/AssetFacadeTest.php +++ /dev/null @@ -1,46 +0,0 @@ -assertIsString($path = Asset::mediaLink('app.css')); - $this->assertSame('media/app.css?v='.md5_file(Hyde::path('_media/app.css')), $path); - } - - public function testMediaLinkReturnsMediaPathWithoutCacheKeyIfCacheBustingIsDisabled() - { - config(['hyde.enable_cache_busting' => false]); - - $path = Asset::mediaLink('app.css'); - - $this->assertIsString($path); - $this->assertSame('media/app.css', $path); - } - - public function testMediaLinkSupportsCustomMediaDirectories() - { - $this->directory('_assets'); - $this->file('_assets/app.css'); - - Hyde::setMediaDirectory('_assets'); - - $path = Asset::mediaLink('app.css'); - - $this->assertIsString($path); - $this->assertSame('assets/app.css?v='.md5_file(Hyde::path('_assets/app.css')), $path); - } -} diff --git a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php index 4c62090bbae..a004e805399 100644 --- a/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php +++ b/packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php @@ -4,20 +4,31 @@ namespace Hyde\Framework\Testing\Unit\Facades; +use Hyde\Hyde; use Hyde\Facades\Asset; use Hyde\Testing\UnitTestCase; +use Hyde\Support\Facades\Render; +use Hyde\Support\Models\RenderData; +use Hyde\Testing\CreatesTemporaryFiles; /** * @covers \Hyde\Facades\Asset - * - * @see \Hyde\Framework\Testing\Feature\AssetFacadeTest */ class AssetFacadeUnitTest extends UnitTestCase { + use CreatesTemporaryFiles; + protected function setUp(): void { self::needsKernel(); self::mockConfig(); + + Render::swap(new RenderData()); + } + + protected function tearDown(): void + { + $this->cleanUpFilesystem(); } public function testHasMediaFileHelper() @@ -29,4 +40,33 @@ public function testHasMediaFileHelperReturnsTrueForExistingFile() { $this->assertTrue(Asset::hasMediaFile('app.css')); } + + public function testMediaLinkReturnsMediaPathWithCacheKey() + { + $this->assertIsString($path = Asset::mediaLink('app.css')); + $this->assertSame('media/app.css?v='.md5_file(Hyde::path('_media/app.css')), $path); + } + + public function testMediaLinkReturnsMediaPathWithoutCacheKeyIfCacheBustingIsDisabled() + { + self::mockConfig(['hyde.enable_cache_busting' => false]); + + $path = Asset::mediaLink('app.css'); + + $this->assertIsString($path); + $this->assertSame('media/app.css', $path); + } + + public function testMediaLinkSupportsCustomMediaDirectories() + { + $this->directory('_assets'); + $this->file('_assets/app.css'); + + Hyde::setMediaDirectory('_assets'); + + $path = Asset::mediaLink('app.css'); + + $this->assertIsString($path); + $this->assertSame('assets/app.css?v='.md5_file(Hyde::path('_assets/app.css')), $path); + } } From 9edfe944225a12e696f99183e305a98b0cb633cc Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:12:38 +0200 Subject: [PATCH 069/328] Refactor test to be a unit test --- .../{Feature => Unit}/Support/MediaFileTest.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) rename packages/framework/tests/{Feature => Unit}/Support/MediaFileTest.php (93%) diff --git a/packages/framework/tests/Feature/Support/MediaFileTest.php b/packages/framework/tests/Unit/Support/MediaFileTest.php similarity index 93% rename from packages/framework/tests/Feature/Support/MediaFileTest.php rename to packages/framework/tests/Unit/Support/MediaFileTest.php index 0782bfaf3bc..a4798f0db52 100644 --- a/packages/framework/tests/Feature/Support/MediaFileTest.php +++ b/packages/framework/tests/Unit/Support/MediaFileTest.php @@ -2,19 +2,30 @@ declare(strict_types=1); -namespace Hyde\Framework\Testing\Feature\Support; +namespace Hyde\Framework\Testing\Unit\Support; use Hyde\Facades\Filesystem; use Hyde\Framework\Exceptions\FileNotFoundException; use Hyde\Hyde; use Hyde\Support\Filesystem\MediaFile; -use Hyde\Testing\TestCase; +use Hyde\Testing\UnitTestCase; +use Hyde\Testing\CreatesTemporaryFiles; /** * @covers \Hyde\Support\Filesystem\MediaFile */ -class MediaFileTest extends TestCase +class MediaFileTest extends UnitTestCase { + use CreatesTemporaryFiles; + + protected static bool $needsKernel = true; + protected static bool $needsConfig = true; + + protected function tearDown(): void + { + $this->cleanUpFilesystem(); + } + public function testCanConstruct() { $file = new MediaFile('foo'); From b6eed88c1161093f44daee2b30a4c0474a113212 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:19:28 +0200 Subject: [PATCH 070/328] Draft new mediaPath helper --- packages/framework/src/Support/Filesystem/MediaFile.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/framework/src/Support/Filesystem/MediaFile.php b/packages/framework/src/Support/Filesystem/MediaFile.php index 45298a50694..e5f0fba95bf 100644 --- a/packages/framework/src/Support/Filesystem/MediaFile.php +++ b/packages/framework/src/Support/Filesystem/MediaFile.php @@ -41,6 +41,14 @@ public static function files(): array return array_keys(static::all()); } + /** + * Get the absolute path to the media source directory, or a file within it. + */ + public static function mediaPath(string $path = ''): string + { + return Hyde::mediaPath($path); + } + public function getIdentifier(): string { return Str::after($this->getPath(), Hyde::getMediaDirectory().'/'); From ccca1d773052be4e37f5204b774b1104983a3a76 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:20:01 +0200 Subject: [PATCH 071/328] Draft new siteMediaPath helper --- packages/framework/src/Support/Filesystem/MediaFile.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/framework/src/Support/Filesystem/MediaFile.php b/packages/framework/src/Support/Filesystem/MediaFile.php index e5f0fba95bf..418ea84e73c 100644 --- a/packages/framework/src/Support/Filesystem/MediaFile.php +++ b/packages/framework/src/Support/Filesystem/MediaFile.php @@ -49,6 +49,14 @@ public static function mediaPath(string $path = ''): string return Hyde::mediaPath($path); } + /** + * Get the absolute path to the compiled site's media directory, or a file within it. + */ + public static function siteMediaPath(string $path = ''): string + { + return Hyde::siteMediaPath($path); + } + public function getIdentifier(): string { return Str::after($this->getPath(), Hyde::getMediaDirectory().'/'); From b6a1269272b9f9391f0ceb7a08539b426b3e1dfd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:21:31 +0200 Subject: [PATCH 072/328] Inline kernel access --- packages/framework/src/Support/Filesystem/MediaFile.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Support/Filesystem/MediaFile.php b/packages/framework/src/Support/Filesystem/MediaFile.php index 418ea84e73c..539ac68f3fe 100644 --- a/packages/framework/src/Support/Filesystem/MediaFile.php +++ b/packages/framework/src/Support/Filesystem/MediaFile.php @@ -6,6 +6,7 @@ use Hyde\Hyde; use Hyde\Facades\Config; +use Hyde\Foundation\HydeKernel; use Hyde\Framework\Exceptions\FileNotFoundException; use Illuminate\Support\Str; @@ -46,7 +47,7 @@ public static function files(): array */ public static function mediaPath(string $path = ''): string { - return Hyde::mediaPath($path); + return HydeKernel::getInstance()->mediaPath($path); } /** @@ -54,7 +55,7 @@ public static function mediaPath(string $path = ''): string */ public static function siteMediaPath(string $path = ''): string { - return Hyde::siteMediaPath($path); + return HydeKernel::getInstance()->siteMediaPath($path); } public function getIdentifier(): string From ecd98dbd436cc29663d956fbb9b0ab94ab89c768 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:22:14 +0200 Subject: [PATCH 073/328] Rename added methods to match HydePage siblings --- packages/framework/src/Support/Filesystem/MediaFile.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Support/Filesystem/MediaFile.php b/packages/framework/src/Support/Filesystem/MediaFile.php index 539ac68f3fe..3b514361caf 100644 --- a/packages/framework/src/Support/Filesystem/MediaFile.php +++ b/packages/framework/src/Support/Filesystem/MediaFile.php @@ -45,7 +45,7 @@ public static function files(): array /** * Get the absolute path to the media source directory, or a file within it. */ - public static function mediaPath(string $path = ''): string + public static function sourcePath(string $path = ''): string { return HydeKernel::getInstance()->mediaPath($path); } @@ -53,7 +53,7 @@ public static function mediaPath(string $path = ''): string /** * Get the absolute path to the compiled site's media directory, or a file within it. */ - public static function siteMediaPath(string $path = ''): string + public static function outputPath(string $path = ''): string { return HydeKernel::getInstance()->siteMediaPath($path); } From beaf5114a3c086274430db9c2961a598c603062d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:23:27 +0200 Subject: [PATCH 074/328] Refactor base implementations to be class independent --- packages/framework/src/Foundation/Kernel/Filesystem.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index a8f36a32df1..cdd1685b295 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -97,10 +97,10 @@ public function pathToRelative(string $path): string public function mediaPath(string $path = ''): string { if (empty($path)) { - return $this->path(Hyde::getMediaDirectory()); + return Hyde::path(Hyde::getMediaDirectory()); } - return $this->path(path_join(Hyde::getMediaDirectory(), unslash($path))); + return Hyde::path(path_join(Hyde::getMediaDirectory(), unslash($path))); } /** @@ -121,12 +121,12 @@ public function sitePath(string $path = ''): string public function siteMediaPath(string $path = ''): string { if (empty($path)) { - return $this->sitePath(Hyde::getMediaOutputDirectory()); + return Hyde::sitePath(Hyde::getMediaOutputDirectory()); } $path = unslash($path); - return $this->sitePath(Hyde::getMediaOutputDirectory()."/$path"); + return Hyde::sitePath(Hyde::getMediaOutputDirectory()."/$path"); } /** From 9aa1f66db9d946cf41e7f1b16f0e5f04f8a0ceba Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:24:53 +0200 Subject: [PATCH 075/328] Move method logic to new code location --- .../src/Foundation/Kernel/Filesystem.php | 15 +++------------ .../src/Support/Filesystem/MediaFile.php | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index cdd1685b295..c637ed271b9 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -7,6 +7,7 @@ use Hyde\Hyde; use Hyde\Foundation\HydeKernel; use Hyde\Foundation\PharSupport; +use Hyde\Support\Filesystem\MediaFile; use Illuminate\Support\Collection; use function collect; @@ -96,11 +97,7 @@ public function pathToRelative(string $path): string */ public function mediaPath(string $path = ''): string { - if (empty($path)) { - return Hyde::path(Hyde::getMediaDirectory()); - } - - return Hyde::path(path_join(Hyde::getMediaDirectory(), unslash($path))); + return MediaFile::sourcePath($path); } /** @@ -120,13 +117,7 @@ public function sitePath(string $path = ''): string */ public function siteMediaPath(string $path = ''): string { - if (empty($path)) { - return Hyde::sitePath(Hyde::getMediaOutputDirectory()); - } - - $path = unslash($path); - - return Hyde::sitePath(Hyde::getMediaOutputDirectory()."/$path"); + return MediaFile::outputPath($path); } /** diff --git a/packages/framework/src/Support/Filesystem/MediaFile.php b/packages/framework/src/Support/Filesystem/MediaFile.php index 3b514361caf..fbf6f04ea9b 100644 --- a/packages/framework/src/Support/Filesystem/MediaFile.php +++ b/packages/framework/src/Support/Filesystem/MediaFile.php @@ -6,10 +6,11 @@ use Hyde\Hyde; use Hyde\Facades\Config; -use Hyde\Foundation\HydeKernel; use Hyde\Framework\Exceptions\FileNotFoundException; use Illuminate\Support\Str; +use function Hyde\unslash; +use function Hyde\path_join; use function extension_loaded; use function file_exists; use function array_merge; @@ -47,7 +48,11 @@ public static function files(): array */ public static function sourcePath(string $path = ''): string { - return HydeKernel::getInstance()->mediaPath($path); + if (empty($path)) { + return Hyde::path(Hyde::getMediaDirectory()); + } + + return Hyde::path(path_join(Hyde::getMediaDirectory(), unslash($path))); } /** @@ -55,7 +60,13 @@ public static function sourcePath(string $path = ''): string */ public static function outputPath(string $path = ''): string { - return HydeKernel::getInstance()->siteMediaPath($path); + if (empty($path)) { + return Hyde::sitePath(Hyde::getMediaOutputDirectory()); + } + + $path = unslash($path); + + return Hyde::sitePath(Hyde::getMediaOutputDirectory()."/$path"); } public function getIdentifier(): string From 5863d03613db465499d3f26e6344f66480c01b9b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:27:20 +0200 Subject: [PATCH 076/328] Reorder methods to match sibling order --- .../hyde-kernel-filesystem-methods.md | 10 +++++----- .../Foundation/Concerns/ForwardsFilesystem.php | 8 ++++---- .../src/Foundation/Kernel/Filesystem.php | 16 ++++++++-------- spec.md | 4 ++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/_data/partials/hyde-pages-api/hyde-kernel-filesystem-methods.md b/docs/_data/partials/hyde-pages-api/hyde-kernel-filesystem-methods.md index bdbe12dd34d..204bb419328 100644 --- a/docs/_data/partials/hyde-pages-api/hyde-kernel-filesystem-methods.md +++ b/docs/_data/partials/hyde-pages-api/hyde-kernel-filesystem-methods.md @@ -1,7 +1,7 @@
- + #### `filesystem()` @@ -35,20 +35,20 @@ No description provided. Hyde::mediaPath(string $path): string ``` -#### `sitePath()` +#### `siteMediaPath()` No description provided. ```php -Hyde::sitePath(string $path): string +Hyde::siteMediaPath(string $path): string ``` -#### `siteMediaPath()` +#### `sitePath()` No description provided. ```php -Hyde::siteMediaPath(string $path): string +Hyde::sitePath(string $path): string ``` #### `pathToAbsolute()` diff --git a/packages/framework/src/Foundation/Concerns/ForwardsFilesystem.php b/packages/framework/src/Foundation/Concerns/ForwardsFilesystem.php index 88e8aba452b..c0ac1518277 100644 --- a/packages/framework/src/Foundation/Concerns/ForwardsFilesystem.php +++ b/packages/framework/src/Foundation/Concerns/ForwardsFilesystem.php @@ -33,14 +33,14 @@ public function mediaPath(string $path = ''): string return $this->filesystem->mediaPath($path); } - public function sitePath(string $path = ''): string + public function siteMediaPath(string $path = ''): string { - return $this->filesystem->sitePath($path); + return $this->filesystem->siteMediaPath($path); } - public function siteMediaPath(string $path = ''): string + public function sitePath(string $path = ''): string { - return $this->filesystem->siteMediaPath($path); + return $this->filesystem->sitePath($path); } public function pathToAbsolute(string|array $path): string|array diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index c637ed271b9..f254440d3e8 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -100,6 +100,14 @@ public function mediaPath(string $path = ''): string return MediaFile::sourcePath($path); } + /** + * Get the absolute path to the compiled site's media directory, or a file within it. + */ + public function siteMediaPath(string $path = ''): string + { + return MediaFile::outputPath($path); + } + /** * Get the absolute path to the compiled site directory, or a file within it. */ @@ -112,14 +120,6 @@ public function sitePath(string $path = ''): string return $this->path(path_join(Hyde::getOutputDirectory(), unslash($path))); } - /** - * Get the absolute path to the compiled site's media directory, or a file within it. - */ - public function siteMediaPath(string $path = ''): string - { - return MediaFile::outputPath($path); - } - /** * Works similarly to the path() function, but returns a file in the Framework package. * diff --git a/spec.md b/spec.md index a1ca493ac41..cb78e76674c 100644 --- a/spec.md +++ b/spec.md @@ -78,17 +78,17 @@ Asset::hasMediaFile(string $file) // Returns file_exists(Hyde::mediaPath($file)) ```php Hyde::mediaPath() // Get the absolute path to the media source directory, or a file within it. (Intended as a sibling to Hyde::path and Hyde::sitePath helpers, and the HydePage::path methods) +Hyde::siteMediaPath() // Get the absolute path to the compiled site's media directory, or a file within it. (Intended as a sibling to Hyde::sitePath) Hyde::mediaLink() // Gets a relative web link to the given file stored in the _site/media folder. (Intended as a sibling to Hyde::relativeLink, which is called by this) (A second $validate parameter will return throw an exception if the file does not exist) Hyde::asset() // Gets a relative web link to the given image stored in the _site/media folder. (But leaves remote URLs alone) (A second $preferQualifiedUrl parameter will return a fully qualified URL if a site URL is set) -Hyde::siteMediaPath() // Get the absolute path to the compiled site's media directory, or a file within it. (Intended as a sibling to Hyde::sitePath) /** * Real implementations of the facade methods: * * @see \Hyde\Foundation\HydeKernel::mediaPath {@see \Hyde\Foundation\Kernel\Filesystem::mediaPath} + * @see \Hyde\Foundation\HydeKernel::siteMediaPath {@see \Hyde\Foundation\Kernel\Filesystem::siteMediaPath} * @see \Hyde\Foundation\HydeKernel::mediaLink {@see \Hyde\Foundation\Kernel\Hyperlinks::mediaLink} * @see \Hyde\Foundation\HydeKernel::asset {@see \Hyde\Foundation\Kernel\Hyperlinks::asset} - * @see \Hyde\Foundation\HydeKernel::siteMediaPath {@see \Hyde\Foundation\Kernel\Filesystem::siteMediaPath} */ ``` From a60e91b61659925ed17a370e37c5c69fc293bf5a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:37:07 +0200 Subject: [PATCH 077/328] Move tests to match new code locations --- .../Feature/Foundation/FilesystemTest.php | 25 +++++----------- .../tests/Unit/Support/MediaFileTest.php | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/packages/framework/tests/Feature/Foundation/FilesystemTest.php b/packages/framework/tests/Feature/Foundation/FilesystemTest.php index 6c2c2811cd8..0be01b45c22 100644 --- a/packages/framework/tests/Feature/Foundation/FilesystemTest.php +++ b/packages/framework/tests/Feature/Foundation/FilesystemTest.php @@ -13,6 +13,7 @@ use Hyde\Pages\HtmlPage; use Hyde\Pages\MarkdownPage; use Hyde\Pages\MarkdownPost; +use Hyde\Support\Filesystem\MediaFile; use Hyde\Testing\UnitTestCase; use function Hyde\normalize_slashes; @@ -263,31 +264,19 @@ public function testHelperForDocumentationPages() public function testHelperForMediaPath() { $this->assertSame(Hyde::path('_media'), Hyde::mediaPath()); - } - - public function testHelperForMediaPathReturnsPathToFileWithinTheDirectory() - { - $this->assertSame(Hyde::path('_media/foo.css'), Hyde::mediaPath('foo.css')); - } + $this->assertSame(MediaFile::sourcePath(), Hyde::mediaPath()); - public function testGetMediaPathReturnsAbsolutePath() - { - $this->assertSame(Hyde::path('_media'), Hyde::mediaPath()); + $this->assertSame(Hyde::path('_media/foo.png'), Hyde::mediaPath('foo.png')); + $this->assertSame(MediaFile::sourcePath('foo.png'), Hyde::mediaPath('foo.png')); } public function testHelperForMediaOutputPath() { $this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath()); - } - - public function testHelperForMediaOutputPathReturnsPathToFileWithinTheDirectory() - { - $this->assertSame(Hyde::path('_site/media/foo.css'), Hyde::siteMediaPath('foo.css')); - } + $this->assertSame(MediaFile::outputPath(), Hyde::siteMediaPath()); - public function testGetMediaOutputPathReturnsAbsolutePath() - { - $this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath()); + $this->assertSame(Hyde::path('_site/media/foo.png'), Hyde::siteMediaPath('foo.png')); + $this->assertSame(MediaFile::outputPath('foo.png'), Hyde::siteMediaPath('foo.png')); } public function testHelperForSiteOutputPath() diff --git a/packages/framework/tests/Unit/Support/MediaFileTest.php b/packages/framework/tests/Unit/Support/MediaFileTest.php index a4798f0db52..86969b4d3ab 100644 --- a/packages/framework/tests/Unit/Support/MediaFileTest.php +++ b/packages/framework/tests/Unit/Support/MediaFileTest.php @@ -211,4 +211,34 @@ public function testGetIdentifierWithSubdirectory() { $this->assertSame('foo/bar', MediaFile::make('foo/bar')->getIdentifier()); } + + public function testHelperForMediaPath() + { + $this->assertSame(Hyde::path('_media'), MediaFile::sourcePath()); + } + + public function testHelperForMediaPathReturnsPathToFileWithinTheDirectory() + { + $this->assertSame(Hyde::path('_media/foo.css'), MediaFile::sourcePath('foo.css')); + } + + public function testGetMediaPathReturnsAbsolutePath() + { + $this->assertSame(Hyde::path('_media'), MediaFile::sourcePath()); + } + + public function testHelperForMediaOutputPath() + { + $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); + } + + public function testHelperForMediaOutputPathReturnsPathToFileWithinTheDirectory() + { + $this->assertSame(Hyde::path('_site/media/foo.css'), MediaFile::outputPath('foo.css')); + } + + public function testGetMediaOutputPathReturnsAbsolutePath() + { + $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); + } } From 8cfe0cd6d471f8c81bf259e0d1bc5066a57765f6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:38:13 +0200 Subject: [PATCH 078/328] Add todos to move more tests to match new code locations --- packages/framework/tests/Feature/HydeKernelTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/framework/tests/Feature/HydeKernelTest.php b/packages/framework/tests/Feature/HydeKernelTest.php index 8c1470b4206..bd22206502d 100644 --- a/packages/framework/tests/Feature/HydeKernelTest.php +++ b/packages/framework/tests/Feature/HydeKernelTest.php @@ -393,17 +393,23 @@ public function testGetMediaOutputDirectoryNameUsesTrimmedVersionOfMediaSourceDi public function testCanGetSiteMediaOutputDirectory() { + // Todo: Move to MediaFileTest + $this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath()); } public function testGetSiteMediaOutputDirectoryUsesTrimmedVersionOfMediaSourceDirectory() { + // Todo: Move to MediaFileTest + Hyde::setMediaDirectory('_foo'); $this->assertSame(Hyde::path('_site/foo'), Hyde::siteMediaPath()); } public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory() { + // Todo: Move to MediaFileTest + Hyde::setOutputDirectory(Hyde::path('foo')); Hyde::setMediaDirectory('bar'); From 89d0e52d4693ced01185fb7766c2d96208b47828 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:44:01 +0200 Subject: [PATCH 079/328] Create new internal trait for transitioning to v2 --- packages/framework/src/Hyde.php | 3 +++ .../framework/src/Support/V1Compatibility.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 packages/framework/src/Support/V1Compatibility.php diff --git a/packages/framework/src/Hyde.php b/packages/framework/src/Hyde.php index cc309a3b21c..105b42de812 100644 --- a/packages/framework/src/Hyde.php +++ b/packages/framework/src/Hyde.php @@ -7,6 +7,7 @@ use Hyde\Enums\Feature; use Hyde\Facades\Features; use Hyde\Foundation\HydeKernel; +use Hyde\Support\V1Compatibility; use Illuminate\Support\Collection; use Hyde\Foundation\Kernel\FileCollection; use Hyde\Foundation\Kernel\Filesystem; @@ -79,6 +80,8 @@ */ class Hyde extends Facade { + use V1Compatibility; + public static function version(): string { return HydeKernel::version(); diff --git a/packages/framework/src/Support/V1Compatibility.php b/packages/framework/src/Support/V1Compatibility.php new file mode 100644 index 00000000000..ed03754713d --- /dev/null +++ b/packages/framework/src/Support/V1Compatibility.php @@ -0,0 +1,15 @@ + Date: Fri, 26 Jul 2024 16:46:05 +0200 Subject: [PATCH 080/328] Ignore class from code coverage --- packages/framework/src/Support/V1Compatibility.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Support/V1Compatibility.php b/packages/framework/src/Support/V1Compatibility.php index ed03754713d..d26d62cd504 100644 --- a/packages/framework/src/Support/V1Compatibility.php +++ b/packages/framework/src/Support/V1Compatibility.php @@ -8,6 +8,8 @@ * @internal Hyde Facade support to aid in the v1 to v2 transition. * * @deprecated All code here is deprecated, and exists to help you transition. + * + * @codeCoverageIgnore This class is ignored from code coverage. */ trait V1Compatibility { From 2004a4e67e8fd80b20ffb4f96d6dd177bf26b773 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:59:19 +0200 Subject: [PATCH 081/328] Revert "Ignore class from code coverage" This reverts commit 4091051785fcc5cba66b6b4eb76abe0c23008655. --- packages/framework/src/Support/V1Compatibility.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/framework/src/Support/V1Compatibility.php b/packages/framework/src/Support/V1Compatibility.php index d26d62cd504..ed03754713d 100644 --- a/packages/framework/src/Support/V1Compatibility.php +++ b/packages/framework/src/Support/V1Compatibility.php @@ -8,8 +8,6 @@ * @internal Hyde Facade support to aid in the v1 to v2 transition. * * @deprecated All code here is deprecated, and exists to help you transition. - * - * @codeCoverageIgnore This class is ignored from code coverage. */ trait V1Compatibility { From 650d5a7e815033bdbdc60c6eb0e6c4a7899883b2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 16:54:58 +0200 Subject: [PATCH 082/328] Manually proxy and deprecate legacy facade methods This is so we can get an overview of the outdated methods that are inconsistently named This means they are lost from the HydeKernel which could be a problem to review before merge. --- .../hyde-kernel-filesystem-methods.md | 18 +-------------- .../Concerns/ForwardsFilesystem.php | 10 -------- .../src/Foundation/Kernel/Filesystem.php | 17 -------------- packages/framework/src/Hyde.php | 2 -- .../framework/src/Support/V1Compatibility.php | 23 ++++++++++++++++++- 5 files changed, 23 insertions(+), 47 deletions(-) diff --git a/docs/_data/partials/hyde-pages-api/hyde-kernel-filesystem-methods.md b/docs/_data/partials/hyde-pages-api/hyde-kernel-filesystem-methods.md index 204bb419328..eb5983597e6 100644 --- a/docs/_data/partials/hyde-pages-api/hyde-kernel-filesystem-methods.md +++ b/docs/_data/partials/hyde-pages-api/hyde-kernel-filesystem-methods.md @@ -1,7 +1,7 @@
- + #### `filesystem()` @@ -27,22 +27,6 @@ No description provided. Hyde::vendorPath(string $path, string $package): string ``` -#### `mediaPath()` - -No description provided. - -```php -Hyde::mediaPath(string $path): string -``` - -#### `siteMediaPath()` - -No description provided. - -```php -Hyde::siteMediaPath(string $path): string -``` - #### `sitePath()` No description provided. diff --git a/packages/framework/src/Foundation/Concerns/ForwardsFilesystem.php b/packages/framework/src/Foundation/Concerns/ForwardsFilesystem.php index c0ac1518277..cea06f5bbc2 100644 --- a/packages/framework/src/Foundation/Concerns/ForwardsFilesystem.php +++ b/packages/framework/src/Foundation/Concerns/ForwardsFilesystem.php @@ -28,16 +28,6 @@ public function vendorPath(string $path = '', string $package = 'framework'): st return $this->filesystem->vendorPath($path, $package); } - public function mediaPath(string $path = ''): string - { - return $this->filesystem->mediaPath($path); - } - - public function siteMediaPath(string $path = ''): string - { - return $this->filesystem->siteMediaPath($path); - } - public function sitePath(string $path = ''): string { return $this->filesystem->sitePath($path); diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index f254440d3e8..8f3bb2fd2aa 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -7,7 +7,6 @@ use Hyde\Hyde; use Hyde\Foundation\HydeKernel; use Hyde\Foundation\PharSupport; -use Hyde\Support\Filesystem\MediaFile; use Illuminate\Support\Collection; use function collect; @@ -92,22 +91,6 @@ public function pathToRelative(string $path): string : $path); } - /** - * Get the absolute path to the media source directory, or a file within it. - */ - public function mediaPath(string $path = ''): string - { - return MediaFile::sourcePath($path); - } - - /** - * Get the absolute path to the compiled site's media directory, or a file within it. - */ - public function siteMediaPath(string $path = ''): string - { - return MediaFile::outputPath($path); - } - /** * Get the absolute path to the compiled site directory, or a file within it. */ diff --git a/packages/framework/src/Hyde.php b/packages/framework/src/Hyde.php index 105b42de812..9590fb6133a 100644 --- a/packages/framework/src/Hyde.php +++ b/packages/framework/src/Hyde.php @@ -34,8 +34,6 @@ * @method static string pathToAbsolute(string $path) * @method static string pathToRelative(string $path) * @method static string sitePath(string $path = '') - * @method static string mediaPath(string $path = '') - * @method static string siteMediaPath(string $path = '') * @method static string formatLink(string $destination) * @method static string relativeLink(string $destination) * @method static string mediaLink(string $destination, bool $validate = false) diff --git a/packages/framework/src/Support/V1Compatibility.php b/packages/framework/src/Support/V1Compatibility.php index ed03754713d..f6bd2de40c7 100644 --- a/packages/framework/src/Support/V1Compatibility.php +++ b/packages/framework/src/Support/V1Compatibility.php @@ -4,6 +4,9 @@ namespace Hyde\Support; +use JetBrains\PhpStorm\Deprecated; +use Hyde\Support\Filesystem\MediaFile; + /** * @internal Hyde Facade support to aid in the v1 to v2 transition. * @@ -11,5 +14,23 @@ */ trait V1Compatibility { - // + /** + * @deprecated Use MediaFile::sourcePath() instead. + * @see \Hyde\Support\Filesystem\MediaFile::sourcePath() + */ + #[Deprecated(reason: 'Use MediaFile::sourcePath() instead', replacement: '\Hyde\Support\Filesystem\MediaFile::sourcePath()')] + public static function mediaPath(string $path = ''): string + { + return MediaFile::sourcePath($path); + } + + /** + * @deprecated Use MediaFile::outputPath() instead. + * @see \Hyde\Support\Filesystem\MediaFile::outputPath() + */ + #[Deprecated(reason: 'Use MediaFile::outputPath() instead', replacement: '\Hyde\Support\Filesystem\MediaFile::outputPath()')] + public static function siteMediaPath(string $path = ''): string + { + return MediaFile::outputPath($path); + } } From 8228d7a474666aeaf63b9d6d072f48e63305782f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 17:04:58 +0200 Subject: [PATCH 083/328] Set the parameters list --- packages/framework/src/Support/V1Compatibility.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Support/V1Compatibility.php b/packages/framework/src/Support/V1Compatibility.php index f6bd2de40c7..863734b99cd 100644 --- a/packages/framework/src/Support/V1Compatibility.php +++ b/packages/framework/src/Support/V1Compatibility.php @@ -18,7 +18,7 @@ trait V1Compatibility * @deprecated Use MediaFile::sourcePath() instead. * @see \Hyde\Support\Filesystem\MediaFile::sourcePath() */ - #[Deprecated(reason: 'Use MediaFile::sourcePath() instead', replacement: '\Hyde\Support\Filesystem\MediaFile::sourcePath()')] + #[Deprecated(reason: 'Use MediaFile::sourcePath() instead', replacement: '\Hyde\Support\Filesystem\MediaFile::sourcePath(%parametersList%)')] public static function mediaPath(string $path = ''): string { return MediaFile::sourcePath($path); @@ -28,7 +28,7 @@ public static function mediaPath(string $path = ''): string * @deprecated Use MediaFile::outputPath() instead. * @see \Hyde\Support\Filesystem\MediaFile::outputPath() */ - #[Deprecated(reason: 'Use MediaFile::outputPath() instead', replacement: '\Hyde\Support\Filesystem\MediaFile::outputPath()')] + #[Deprecated(reason: 'Use MediaFile::outputPath() instead', replacement: '\Hyde\Support\Filesystem\MediaFile::outputPath(%parametersList%)')] public static function siteMediaPath(string $path = ''): string { return MediaFile::outputPath($path); From 2e96631d81859d470251c4e86706971ea969eb46 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 17:05:43 +0200 Subject: [PATCH 084/328] Alias the MediaFile class --- app/config.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/config.php b/app/config.php index 009c0f586b7..aed2519bbce 100644 --- a/app/config.php +++ b/app/config.php @@ -105,6 +105,7 @@ 'MarkdownPage' => \Hyde\Pages\MarkdownPage::class, 'MarkdownPost' => \Hyde\Pages\MarkdownPost::class, 'DocumentationPage' => \Hyde\Pages\DocumentationPage::class, + 'MediaFile' => \Hyde\Support\Filesystem\MediaFile::class, 'DataCollection' => \Hyde\Support\DataCollection::class, 'Includes' => \Hyde\Support\Includes::class, 'Feature' => \Hyde\Enums\Feature::class, From bbe66f46095bb275661de093239aa2acf9fbd824 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 17:09:33 +0200 Subject: [PATCH 085/328] Update deprecated method usages with new helpers --- .../resources/views/layouts/head.blade.php | 2 +- packages/framework/src/Facades/Asset.php | 5 +++-- .../Actions/PreBuildTasks/CleanSiteDirectory.php | 3 ++- .../PreBuildTasks/TransferMediaAssets.php | 7 +++---- .../Features/Blogging/Models/FeaturedImage.php | 3 ++- .../src/Framework/Services/ValidationService.php | 5 +++-- .../tests/Feature/Foundation/FilesystemTest.php | 16 ++++++++-------- .../framework/tests/Feature/HydeKernelTest.php | 11 ++++++----- 8 files changed, 28 insertions(+), 24 deletions(-) diff --git a/packages/framework/resources/views/layouts/head.blade.php b/packages/framework/resources/views/layouts/head.blade.php index 32ed4390d8b..111aced665b 100644 --- a/packages/framework/resources/views/layouts/head.blade.php +++ b/packages/framework/resources/views/layouts/head.blade.php @@ -2,7 +2,7 @@ {{ $page->title() }} -@if (file_exists(Hyde::mediaPath('favicon.ico'))) +@if (file_exists(MediaFile::sourcePath('favicon.ico'))) @endif diff --git a/packages/framework/src/Facades/Asset.php b/packages/framework/src/Facades/Asset.php index 9691a43c211..45e16a0a881 100644 --- a/packages/framework/src/Facades/Asset.php +++ b/packages/framework/src/Facades/Asset.php @@ -5,6 +5,7 @@ namespace Hyde\Facades; use Hyde\Hyde; +use Hyde\Support\Filesystem\MediaFile; use function md5_file; use function file_exists; @@ -24,13 +25,13 @@ public static function mediaLink(string $file): string public static function hasMediaFile(string $file): bool { - return file_exists(Hyde::mediaPath($file)); + return file_exists(MediaFile::sourcePath($file)); } protected static function getCacheBustKey(string $file): string { return Config::getBool('hyde.enable_cache_busting', true) - ? '?v='.md5_file(Hyde::mediaPath("$file")) + ? '?v='.md5_file(MediaFile::sourcePath("$file")) : ''; } } diff --git a/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php b/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php index 849f077b7cb..ba64f24ee76 100644 --- a/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php +++ b/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php @@ -7,6 +7,7 @@ use Hyde\Hyde; use Hyde\Facades\Config; use Hyde\Facades\Filesystem; +use Hyde\Support\Filesystem\MediaFile; use Hyde\Framework\Features\BuildTasks\PreBuildTask; use function basename; @@ -22,7 +23,7 @@ public function handle(): void { if ($this->isItSafeToCleanOutputDirectory()) { Filesystem::unlink(glob(Hyde::sitePath('*.{html,json}'), GLOB_BRACE)); - Filesystem::cleanDirectory(Hyde::siteMediaPath()); + Filesystem::cleanDirectory(MediaFile::outputPath()); } } diff --git a/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php b/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php index fdec03a75ff..3acb112ea9d 100644 --- a/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php +++ b/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php @@ -4,7 +4,6 @@ namespace Hyde\Framework\Actions\PreBuildTasks; -use Hyde\Hyde; use Hyde\Support\Filesystem\MediaFile; use Hyde\Framework\Features\BuildTasks\PreBuildTask; use Hyde\Framework\Concerns\InteractsWithDirectories; @@ -17,14 +16,14 @@ class TransferMediaAssets extends PreBuildTask public function handle(): void { - $this->needsDirectory(Hyde::siteMediaPath()); + $this->needsDirectory(MediaFile::outputPath()); $this->newLine(); $this->withProgressBar(MediaFile::files(), function (string $identifier): void { - $sitePath = Hyde::siteMediaPath($identifier); + $sitePath = MediaFile::outputPath($identifier); $this->needsParentDirectory($sitePath); - copy(Hyde::mediaPath($identifier), $sitePath); + copy(MediaFile::sourcePath($identifier), $sitePath); }); $this->newLine(); diff --git a/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php b/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php index 0f42f961c87..5c4acef1996 100644 --- a/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php +++ b/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php @@ -11,6 +11,7 @@ use Hyde\Support\BuildWarnings; use Illuminate\Support\Facades\Http; use Hyde\Foundation\Kernel\Hyperlinks; +use Hyde\Support\Filesystem\MediaFile; use Hyde\Framework\Exceptions\FileNotFoundException; use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\FeaturedImageSchema; @@ -213,7 +214,7 @@ protected function has(string $property): bool protected function getContentLengthForLocalImage(): int { - $storagePath = Hyde::mediaPath($this->source); + $storagePath = MediaFile::sourcePath($this->source); if (! file_exists($storagePath)) { throw new FileNotFoundException(customMessage: sprintf('Featured image [%s] not found.', Hyde::pathToRelative($storagePath))); diff --git a/packages/framework/src/Framework/Services/ValidationService.php b/packages/framework/src/Framework/Services/ValidationService.php index 88deee3496b..052486d4041 100644 --- a/packages/framework/src/Framework/Services/ValidationService.php +++ b/packages/framework/src/Framework/Services/ValidationService.php @@ -11,6 +11,7 @@ use Hyde\Pages\MarkdownPage; use Hyde\Pages\DocumentationPage; use Hyde\Enums\Feature; +use Hyde\Support\Filesystem\MediaFile; use Hyde\Support\Models\ValidationResult as Result; use function count; @@ -102,12 +103,12 @@ public function check_documentation_site_has_an_index_page(Result $result): Resu public function check_site_has_an_app_css_stylesheet(Result $result): Result { - if (file_exists(Hyde::siteMediaPath('/app.css')) || file_exists(Hyde::mediaPath('app.css'))) { + if (file_exists(MediaFile::outputPath('/app.css')) || file_exists(MediaFile::sourcePath('app.css'))) { return $result->pass('Your site has an app.css stylesheet'); } return $result->fail(sprintf('Could not find an app.css file in the %s or %s directory!', - Hyde::pathToRelative(Hyde::siteMediaPath()), Hyde::getMediaDirectory() + Hyde::pathToRelative(MediaFile::outputPath()), Hyde::getMediaDirectory() ))->withTip('You may need to run `npm run dev`.`'); } diff --git a/packages/framework/tests/Feature/Foundation/FilesystemTest.php b/packages/framework/tests/Feature/Foundation/FilesystemTest.php index 0be01b45c22..86bc2c76479 100644 --- a/packages/framework/tests/Feature/Foundation/FilesystemTest.php +++ b/packages/framework/tests/Feature/Foundation/FilesystemTest.php @@ -263,20 +263,20 @@ public function testHelperForDocumentationPages() public function testHelperForMediaPath() { - $this->assertSame(Hyde::path('_media'), Hyde::mediaPath()); - $this->assertSame(MediaFile::sourcePath(), Hyde::mediaPath()); + $this->assertSame(Hyde::path('_media'), MediaFile::sourcePath()); + $this->assertSame(MediaFile::sourcePath(), MediaFile::sourcePath()); - $this->assertSame(Hyde::path('_media/foo.png'), Hyde::mediaPath('foo.png')); - $this->assertSame(MediaFile::sourcePath('foo.png'), Hyde::mediaPath('foo.png')); + $this->assertSame(Hyde::path('_media/foo.png'), MediaFile::sourcePath('foo.png')); + $this->assertSame(MediaFile::sourcePath('foo.png'), MediaFile::sourcePath('foo.png')); } public function testHelperForMediaOutputPath() { - $this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath()); - $this->assertSame(MediaFile::outputPath(), Hyde::siteMediaPath()); + $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); + $this->assertSame(MediaFile::outputPath(), MediaFile::outputPath()); - $this->assertSame(Hyde::path('_site/media/foo.png'), Hyde::siteMediaPath('foo.png')); - $this->assertSame(MediaFile::outputPath('foo.png'), Hyde::siteMediaPath('foo.png')); + $this->assertSame(Hyde::path('_site/media/foo.png'), MediaFile::outputPath('foo.png')); + $this->assertSame(MediaFile::outputPath('foo.png'), MediaFile::outputPath('foo.png')); } public function testHelperForSiteOutputPath() diff --git a/packages/framework/tests/Feature/HydeKernelTest.php b/packages/framework/tests/Feature/HydeKernelTest.php index bd22206502d..9ff8799dd06 100644 --- a/packages/framework/tests/Feature/HydeKernelTest.php +++ b/packages/framework/tests/Feature/HydeKernelTest.php @@ -13,6 +13,7 @@ use Hyde\Foundation\HydeKernel; use Hyde\Enums\Feature; use Hyde\Foundation\Kernel\Filesystem; +use Hyde\Support\Filesystem\MediaFile; use Hyde\Framework\HydeServiceProvider; use Hyde\Hyde; use Hyde\Pages\BladePage; @@ -262,9 +263,9 @@ public function testFluentModelSourcePathHelpers() $this->assertSame(Hyde::path('_pages'), MarkdownPage::path()); $this->assertSame(Hyde::path('_docs'), DocumentationPage::path()); - $this->assertSame(Hyde::path('_media'), Hyde::mediaPath()); + $this->assertSame(Hyde::path('_media'), MediaFile::sourcePath()); + $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); $this->assertSame(Hyde::path('_site'), Hyde::sitePath()); - $this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath()); } public function testPathToRelativeHelperReturnsRelativePathForGivenPath() @@ -395,7 +396,7 @@ public function testCanGetSiteMediaOutputDirectory() { // Todo: Move to MediaFileTest - $this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath()); + $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); } public function testGetSiteMediaOutputDirectoryUsesTrimmedVersionOfMediaSourceDirectory() @@ -403,7 +404,7 @@ public function testGetSiteMediaOutputDirectoryUsesTrimmedVersionOfMediaSourceDi // Todo: Move to MediaFileTest Hyde::setMediaDirectory('_foo'); - $this->assertSame(Hyde::path('_site/foo'), Hyde::siteMediaPath()); + $this->assertSame(Hyde::path('_site/foo'), MediaFile::outputPath()); } public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory() @@ -413,7 +414,7 @@ public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory Hyde::setOutputDirectory(Hyde::path('foo')); Hyde::setMediaDirectory('bar'); - $this->assertSame(Hyde::path('foo/bar'), Hyde::siteMediaPath()); + $this->assertSame(Hyde::path('foo/bar'), MediaFile::outputPath()); } public function testMediaOutputDirectoryCanBeChangedInConfiguration() From 74059a5cd81546649f58859c38ed9d0d28e521a6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 17:10:58 +0200 Subject: [PATCH 086/328] Remove inconsistent infix from internal helper methods --- packages/framework/src/Support/Filesystem/MediaFile.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Support/Filesystem/MediaFile.php b/packages/framework/src/Support/Filesystem/MediaFile.php index fbf6f04ea9b..3ed834e7562 100644 --- a/packages/framework/src/Support/Filesystem/MediaFile.php +++ b/packages/framework/src/Support/Filesystem/MediaFile.php @@ -34,7 +34,7 @@ class MediaFile extends ProjectFile /** @return array The array keys are the filenames relative to the _media/ directory */ public static function all(): array { - return static::discoverMediaAssetFiles(); + return static::discoverMediaFiles(); } /** @return array Array of filenames relative to the _media/ directory */ @@ -123,16 +123,16 @@ public function getMimeType(): string return 'text/plain'; } - protected static function discoverMediaAssetFiles(): array + protected static function discoverMediaFiles(): array { - return collect(static::getMediaAssetFiles())->mapWithKeys(function (string $path): array { + return collect(static::getMediaFiles())->mapWithKeys(function (string $path): array { $file = static::make($path); return [$file->getIdentifier() => $file]; })->all(); } - protected static function getMediaAssetFiles(): array + protected static function getMediaFiles(): array { return glob(Hyde::path(static::getMediaGlobPattern()), GLOB_BRACE) ?: []; } From 678b6f75c1c4fd60d989d2642e4f34aecae97d07 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 17:12:30 +0200 Subject: [PATCH 087/328] Reapply "Ignore class from code coverage" This reverts commit 2004a4e67e8fd80b20ffb4f96d6dd177bf26b773. --- packages/framework/src/Support/V1Compatibility.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/framework/src/Support/V1Compatibility.php b/packages/framework/src/Support/V1Compatibility.php index 863734b99cd..3d8f5b5cd0c 100644 --- a/packages/framework/src/Support/V1Compatibility.php +++ b/packages/framework/src/Support/V1Compatibility.php @@ -11,6 +11,8 @@ * @internal Hyde Facade support to aid in the v1 to v2 transition. * * @deprecated All code here is deprecated, and exists to help you transition. + * + * @codeCoverageIgnore This class is ignored from code coverage. */ trait V1Compatibility { From 46473331102f32baf8d6b5d0b374c084c1b6dda5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 18:32:38 +0200 Subject: [PATCH 088/328] Move the tests to the new code location --- .../tests/Feature/HydeKernelTest.php | 25 ------------------- .../tests/Unit/Support/MediaFileTest.php | 19 ++++++++++++++ 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/packages/framework/tests/Feature/HydeKernelTest.php b/packages/framework/tests/Feature/HydeKernelTest.php index 9ff8799dd06..b12a5ea19bb 100644 --- a/packages/framework/tests/Feature/HydeKernelTest.php +++ b/packages/framework/tests/Feature/HydeKernelTest.php @@ -392,31 +392,6 @@ public function testGetMediaOutputDirectoryNameUsesTrimmedVersionOfMediaSourceDi $this->assertSame('foo', Hyde::getMediaOutputDirectory()); } - public function testCanGetSiteMediaOutputDirectory() - { - // Todo: Move to MediaFileTest - - $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); - } - - public function testGetSiteMediaOutputDirectoryUsesTrimmedVersionOfMediaSourceDirectory() - { - // Todo: Move to MediaFileTest - - Hyde::setMediaDirectory('_foo'); - $this->assertSame(Hyde::path('_site/foo'), MediaFile::outputPath()); - } - - public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory() - { - // Todo: Move to MediaFileTest - - Hyde::setOutputDirectory(Hyde::path('foo')); - Hyde::setMediaDirectory('bar'); - - $this->assertSame(Hyde::path('foo/bar'), MediaFile::outputPath()); - } - public function testMediaOutputDirectoryCanBeChangedInConfiguration() { $this->assertSame('_media', Hyde::getMediaDirectory()); diff --git a/packages/framework/tests/Unit/Support/MediaFileTest.php b/packages/framework/tests/Unit/Support/MediaFileTest.php index 86969b4d3ab..44ded0474c5 100644 --- a/packages/framework/tests/Unit/Support/MediaFileTest.php +++ b/packages/framework/tests/Unit/Support/MediaFileTest.php @@ -241,4 +241,23 @@ public function testGetMediaOutputPathReturnsAbsolutePath() { $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); } + + public function testCanGetSiteMediaOutputDirectory() + { + $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); + } + + public function testGetSiteMediaOutputDirectoryUsesTrimmedVersionOfMediaSourceDirectory() + { + Hyde::setMediaDirectory('_foo'); + $this->assertSame(Hyde::path('_site/foo'), MediaFile::outputPath()); + } + + public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory() + { + Hyde::setOutputDirectory(Hyde::path('foo')); + Hyde::setMediaDirectory('bar'); + + $this->assertSame(Hyde::path('foo/bar'), MediaFile::outputPath()); + } } From a130f0321f44f3df2870ae25e748a863a15db7f5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 18:55:14 +0200 Subject: [PATCH 089/328] Deprecate the `preferQualifiedUrl` parameter in the asset helper --- packages/framework/src/Foundation/Kernel/Hyperlinks.php | 3 ++- packages/framework/src/helpers.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Foundation/Kernel/Hyperlinks.php b/packages/framework/src/Foundation/Kernel/Hyperlinks.php index e127cdfaa82..ab6866a6600 100644 --- a/packages/framework/src/Foundation/Kernel/Hyperlinks.php +++ b/packages/framework/src/Foundation/Kernel/Hyperlinks.php @@ -8,6 +8,7 @@ use BadMethodCallException; use Hyde\Support\Models\Route; use Hyde\Foundation\HydeKernel; +use JetBrains\PhpStorm\Deprecated; use Hyde\Framework\Exceptions\FileNotFoundException; use Illuminate\Support\Str; @@ -109,7 +110,7 @@ public function mediaLink(string $destination, bool $validate = false): string * If true is passed as the second argument, and a base URL is set, * the image will be returned with a qualified absolute URL. */ - public function asset(string $name, bool $preferQualifiedUrl = false): string + public function asset(string $name, #[Deprecated(reason: 'This will be enabled automatically when a site URL is set')] bool $preferQualifiedUrl = false): string { if (static::isRemote($name)) { return $name; diff --git a/packages/framework/src/helpers.php b/packages/framework/src/helpers.php index 34e8f9da12b..54f689619d3 100644 --- a/packages/framework/src/helpers.php +++ b/packages/framework/src/helpers.php @@ -4,6 +4,7 @@ namespace { use Hyde\Foundation\HydeKernel; + use JetBrains\PhpStorm\Deprecated; if (! function_exists('hyde')) { /** @@ -22,7 +23,7 @@ function hyde(): HydeKernel /** * Get a relative link or URL to an asset in the media directory. */ - function asset(string $name, bool $preferQualifiedUrl = false): string + function asset(string $name, #[Deprecated(reason: 'This will be enabled automatically when a site URL is set')] bool $preferQualifiedUrl = false): string { return hyde()->asset($name, $preferQualifiedUrl); } From 54f8f0314aca05f27b5d83482318ff9a5ec0685c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 20:01:18 +0200 Subject: [PATCH 090/328] No longer use the `preferQualifiedUrl` parameter --- packages/framework/src/Foundation/Kernel/Hyperlinks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Foundation/Kernel/Hyperlinks.php b/packages/framework/src/Foundation/Kernel/Hyperlinks.php index ab6866a6600..04dedf77f6a 100644 --- a/packages/framework/src/Foundation/Kernel/Hyperlinks.php +++ b/packages/framework/src/Foundation/Kernel/Hyperlinks.php @@ -118,7 +118,7 @@ public function asset(string $name, #[Deprecated(reason: 'This will be enabled a $name = Str::start($name, "{$this->kernel->getMediaOutputDirectory()}/"); - if ($preferQualifiedUrl && $this->hasSiteUrl()) { + if ($this->hasSiteUrl()) { return $this->url($name); } From 7f773b30deefb8803c9c8e119a1a01d686adc00b Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 26 Jul 2024 18:11:31 +0000 Subject: [PATCH 091/328] Remove the `preferQualifiedUrl` parameter --- .../hyde-kernel-hyperlink-methods.md | 4 ++-- docs/architecture-concepts/the-hydekernel.md | 2 +- .../Concerns/ForwardsHyperlinks.php | 4 ++-- .../src/Foundation/Kernel/Hyperlinks.php | 6 ++---- packages/framework/src/Hyde.php | 2 +- packages/framework/src/helpers.php | 5 ++--- .../Feature/Foundation/HyperlinksTest.php | 20 +++++++++---------- .../framework/tests/Feature/HelpersTest.php | 18 ++++++++--------- 8 files changed, 29 insertions(+), 32 deletions(-) diff --git a/docs/_data/partials/hyde-pages-api/hyde-kernel-hyperlink-methods.md b/docs/_data/partials/hyde-pages-api/hyde-kernel-hyperlink-methods.md index 1dceb9c542d..bd8d609104b 100644 --- a/docs/_data/partials/hyde-pages-api/hyde-kernel-hyperlink-methods.md +++ b/docs/_data/partials/hyde-pages-api/hyde-kernel-hyperlink-methods.md @@ -1,7 +1,7 @@