1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 16:36:47 +02:00

wip: add prependNamespace support

This commit is contained in:
David Wheatley
2021-12-12 01:29:35 +00:00
parent e3f7251073
commit 3a55bd502b

View File

@@ -45,6 +45,8 @@ class View implements ExtenderInterface, LifecycleInterface
/**
* Override an existing namespace of Laravel views.
*
* **If you're only replacing one or a few views, you probably want to `->prepend()` the new views instead.**
*
* Views are PHP files that use the Laravel Blade syntax for creation of server-side generated HTML.
* Flarum core uses them for error pages, the installer, HTML emails, and the skeletons for the forum and admin sites.
* To replace views, you will need to put them in a folder in your extension, and register that folder under an existing namespace.
@@ -61,12 +63,34 @@ class View implements ExtenderInterface, LifecycleInterface
return $this;
}
/**
* Extend an existing namespace of Laravel views.
*
* Views are PHP files that use the Laravel Blade syntax for creation of server-side generated HTML.
* Flarum core uses them for error pages, the installer, HTML emails, and the skeletons for the forum and admin sites.
* To replace views within a namespace, you will need to put them in a folder in your extension, and register that folder under an existing namespace.
*
* @param string $namespace: The name of the namespace.
* @param string|string[] $hints: This is a path (or an array of paths) to the folder(s)
* where view files are stored, relative to the extend.php file.
* @return self
*/
public function prepend(string $namespace, $hints): self
{
$this->prependNamespaces[$namespace] = $hints;
return $this;
}
public function extend(Container $container, Extension $extension = null)
{
$container->resolving(Factory::class, function (Factory $view) {
foreach ($this->namespaces as $namespace => $hints) {
$view->addNamespace($namespace, $hints);
}
foreach ($this->prependNamespaces as $namespace => $hints) {
$view->prependNamespace($namespace, $hints);
}
foreach ($this->replaceNamespaces as $namespace => $hints) {
$view->replaceNamespace($namespace, $hints);
}