-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #232: Make fallback extension configurable, deprecate `ViewInterf…
…ace::withDefaultExtension()` and `ViewInterface::getDefaultExtension()` in favor of `withFallbackExtension()` and `getFallbackExtension()`, fix render templates that contain dots in their name
- Loading branch information
Showing
4 changed files
with
60 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ trait ViewTrait | |
private ?ViewContextInterface $context = null; | ||
private string $placeholderSignature; | ||
private string $sourceLocale = 'en'; | ||
private string $defaultExtension = 'php'; | ||
private string $fallbackExtension = self::PHP_EXTENSION; | ||
|
||
/** | ||
* @var array A list of available renderers indexed by their corresponding | ||
|
@@ -105,13 +105,25 @@ public function withSourceLocale(string $locale): static | |
/** | ||
* Returns a new instance with the specified default view file extension. | ||
* | ||
* @param string $defaultExtension The default view file extension. Default is "php". | ||
* @param string $defaultExtension The default view file extension. Default is {@see ViewInterface::PHP_EXTENSION}. | ||
* This will be appended to view file names if they don't have file extensions. | ||
* @deprecated Since 8.0.1 and will be removed in the next major version. Use {@see withFallbackExtension()} instead. | ||
*/ | ||
public function withDefaultExtension(string $defaultExtension): static | ||
{ | ||
return $this->withFallbackExtension($defaultExtension); | ||
} | ||
|
||
/** | ||
* Returns a new instance with the specified fallback view file extension. | ||
* | ||
* @param string $fallbackExtension The fallback view file extension. Default is {@see ViewInterface::PHP_EXTENSION}. | ||
* This will be appended to view file names if they don't exist. | ||
*/ | ||
public function withFallbackExtension(string $fallbackExtension): static | ||
{ | ||
$new = clone $this; | ||
$new->defaultExtension = $defaultExtension; | ||
$new->fallbackExtension = $fallbackExtension; | ||
return $new; | ||
} | ||
|
||
|
@@ -188,10 +200,21 @@ public function getBasePath(): string | |
* Gets the default view file extension. | ||
* | ||
* @return string The default view file extension. | ||
* @deprecated Since 8.0.1 and will be removed in the next major version. Use {@see getFallbackExtension()} instead. | ||
*/ | ||
public function getDefaultExtension(): string | ||
{ | ||
return $this->defaultExtension; | ||
return $this->getFallbackExtension(); | ||
} | ||
|
||
/** | ||
* Gets the fallback view file extension. | ||
* | ||
* @return string The fallback view file extension. | ||
*/ | ||
public function getFallbackExtension(): string | ||
Check warning on line 215 in src/ViewTrait.php GitHub Actions / mutation / PHP 8.1-ubuntu-latest
|
||
{ | ||
return $this->fallbackExtension; | ||
} | ||
|
||
/** | ||
|
@@ -600,17 +623,11 @@ private function findTemplateFile(string $view): string | |
throw new RuntimeException("Unable to resolve view file for view \"$view\": no active view context."); | ||
} | ||
|
||
if (pathinfo($file, PATHINFO_EXTENSION) !== '') { | ||
if (pathinfo($file, PATHINFO_EXTENSION) !== '' && is_file($file)) { | ||
return $file; | ||
} | ||
|
||
$path = $file . '.' . $this->defaultExtension; | ||
|
||
if ($this->defaultExtension !== 'php' && !is_file($path)) { | ||
$path = $file . '.php'; | ||
} | ||
|
||
return $path; | ||
return $file . '.' . $this->fallbackExtension; | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters