mirror of
https://code.castopod.org/adaures/castopod
synced 2025-06-06 18:31:05 +00:00
refactor(componentrenderer): update locateView using a lookupModules property in config
This commit is contained in:
parent
a95de8bab0
commit
58c8839902
22
app/Config/ViewComponents.php
Normal file
22
app/Config/ViewComponents.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Config;
|
||||||
|
|
||||||
|
use ViewComponents\Config\ViewComponents as ViewComponentsConfig;
|
||||||
|
|
||||||
|
class ViewComponents extends ViewComponentsConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $lookupModules = [
|
||||||
|
APP_NAMESPACE => APPPATH,
|
||||||
|
'Modules\Admin' => ROOTPATH . 'modules/Admin/',
|
||||||
|
'Modules\Auth' => ROOTPATH . 'modules/Auth/',
|
||||||
|
'Modules\Analytics' => ROOTPATH . 'modules/Analytics/',
|
||||||
|
'Modules\Install' => ROOTPATH . 'modules/Install/',
|
||||||
|
'Modules\Fediverse' => ROOTPATH . 'modules/Fediverse/',
|
||||||
|
];
|
||||||
|
}
|
@ -137,12 +137,13 @@ class ComponentRenderer
|
|||||||
private function locateView(string $name): string
|
private function locateView(string $name): string
|
||||||
{
|
{
|
||||||
// TODO: Is there a better way to locate components local to current module?
|
// TODO: Is there a better way to locate components local to current module?
|
||||||
$modulesToDiscover = [APPPATH];
|
$modulesToDiscover = [];
|
||||||
foreach (config('Autoload')->psr4 as $namespace => $path) {
|
$lookupModules = $this->config->lookupModules;
|
||||||
if (str_starts_with($this->currentView, $namespace)) {
|
$modulesToDiscover = array_filter($lookupModules, function ($namespace): bool {
|
||||||
array_unshift($modulesToDiscover, $path);
|
return str_starts_with($this->currentView, $namespace);
|
||||||
}
|
}, ARRAY_FILTER_USE_KEY);
|
||||||
}
|
$modulesToDiscover = array_values($modulesToDiscover);
|
||||||
|
$modulesToDiscover[] = $this->config->defaultLookupPath;
|
||||||
|
|
||||||
$namePath = str_replace('.', '/', $name);
|
$namePath = str_replace('.', '/', $name);
|
||||||
|
|
||||||
|
@ -11,4 +11,14 @@ class ViewComponents extends BaseConfig
|
|||||||
public string $classComponentsPath = 'View/Components';
|
public string $classComponentsPath = 'View/Components';
|
||||||
|
|
||||||
public string $viewFileComponentsPath = 'Views/components';
|
public string $viewFileComponentsPath = 'Views/components';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules to look into for local components. Associative array with the module namespace as key and the module path
|
||||||
|
* as value.
|
||||||
|
*
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
public array $lookupModules = [];
|
||||||
|
|
||||||
|
public string $defaultLookupPath = APPPATH;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user