-
-
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.
Browse files
Browse the repository at this point in the history
* Support multiple fallback extensions * Update src/ViewTrait.php * Update ViewTrait.php * Adjust changelog * Update src/ViewTrait.php Co-authored-by: Sergei Predvoditelev <[email protected]> --------- Co-authored-by: Alexander Makarov <[email protected]> Co-authored-by: Sergei Predvoditelev <[email protected]>
- Loading branch information
1 parent
0086712
commit 38e7351
Showing
3 changed files
with
67 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,10 @@ trait ViewTrait | |
private ?ViewContextInterface $context = null; | ||
private string $placeholderSignature; | ||
private string $sourceLocale = 'en'; | ||
private string $fallbackExtension = self::PHP_EXTENSION; | ||
/** | ||
* @var string[] | ||
*/ | ||
private array $fallbackExtensions = [self::PHP_EXTENSION]; | ||
|
||
/** | ||
* @var array A list of available renderers indexed by their corresponding | ||
|
@@ -120,10 +123,10 @@ public function withDefaultExtension(string $defaultExtension): static | |
* @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 | ||
public function withFallbackExtension(string $fallbackExtension, string ...$otherFallbacks): static | ||
{ | ||
$new = clone $this; | ||
$new->fallbackExtension = $fallbackExtension; | ||
$new->fallbackExtensions = [$fallbackExtension, ...array_values($otherFallbacks)]; | ||
Check warning on line 129 in src/ViewTrait.php GitHub Actions / mutation / PHP 8.1-ubuntu-latest
|
||
return $new; | ||
} | ||
|
||
|
@@ -200,21 +203,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. | ||
* @deprecated Since 8.0.1 and will be removed in the next major version. Use {@see getFallbackExtensions()} instead. | ||
*/ | ||
public function getDefaultExtension(): string | ||
{ | ||
return $this->getFallbackExtension(); | ||
return $this->getFallbackExtensions()[0]; | ||
} | ||
|
||
/** | ||
* Gets the fallback view file extension. | ||
* | ||
* @return string The fallback view file extension. | ||
* @return string[] The fallback view file extension. | ||
*/ | ||
public function getFallbackExtension(): string | ||
public function getFallbackExtensions(): array | ||
Check warning on line 218 in src/ViewTrait.php GitHub Actions / mutation / PHP 8.1-ubuntu-latest
|
||
{ | ||
return $this->fallbackExtension; | ||
return $this->fallbackExtensions; | ||
} | ||
|
||
/** | ||
|
@@ -627,7 +630,14 @@ private function findTemplateFile(string $view): string | |
return $file; | ||
} | ||
|
||
return $file . '.' . $this->fallbackExtension; | ||
foreach ($this->fallbackExtensions as $fallbackExtension) { | ||
$fileWithFallbackExtension = $file . '.' . $fallbackExtension; | ||
if (is_file($fileWithFallbackExtension)) { | ||
return $fileWithFallbackExtension; | ||
} | ||
} | ||
|
||
return $file . '.' . $this->fallbackExtensions[0]; | ||
} | ||
|
||
/** | ||
|
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