diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php index 1fb4536..65c4022 100755 --- a/Admin/Install/Navigation.php +++ b/Admin/Install/Navigation.php @@ -15,6 +15,9 @@ declare(strict_types=1); namespace Modules\Navigation\Admin\Install; use phpOMS\Application\ApplicationAbstract; +use phpOMS\System\File\PathException; +use phpOMS\System\File\PermissionException; +use phpOMS\Utils\Parser\Php\ArrayParser; /** * Navigation class. @@ -23,9 +26,20 @@ use phpOMS\Application\ApplicationAbstract; * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 + * + * @performance Create a navigation language file (same as routing files) during the installation process per language + * https://github.com/Karaka-Management/oms-Navigation/issues/8 */ class Navigation { + /** + * Nav languages. + * + * @var array + * @since 1.0.0 + */ + private static array $nav = []; + /** * Install navigation providing * @@ -40,4 +54,48 @@ class Navigation { \Modules\Navigation\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/Navigation.install.json']); } + + /** + * Install language files. + * + * @param string $destPath Destination language path + * @param string $srcPath Source language path + * + * @return void + * + * @throws PathException + * @throws PermissionException + * + * @since 1.0.0 + */ + protected static function installLanguageFiles(string $destPath, string $srcPath) : void + { + if (!\is_file($srcPath)) { + return; + } + + if (!\is_file($destPath)) { + \file_put_contents($destPath, ' [ + '^:goto (.+)$' => [ [ 'dest' => '\Modules\Navigation\Controller\SearchController:searchGoto', 'verb' => RouteVerb::ANY, diff --git a/Controller/SearchController.php b/Controller/SearchController.php index d787417..bf0d9ad 100755 --- a/Controller/SearchController.php +++ b/Controller/SearchController.php @@ -40,13 +40,17 @@ final class SearchController extends Controller * @param ResponseAbstract $response Response * @param array $data Generic data * - * @return void + * @return array * * @api * + * @performance Improve goto command to match + * Use some alternative match parameter (maybe data-name) + * https://github.com/Karaka-Management/oms-Navigation/issues/9 + * * @since 1.0.0 */ - public function searchGoto(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + public function searchGoto(RequestAbstract $request, ResponseAbstract $response, array $data = []) : array { $this->loadLanguage($request, $response, $request->getDataString('app') ?? $this->app->appName); @@ -83,16 +87,17 @@ final class SearchController extends Controller } } - $response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); - if ($found === null || $found->uri === null) { $this->fillJsonResponse($request, $response, NotificationLevel::WARNING, 'Command', 'Unknown command "' . $search . '"', $search); $response->header->status = RequestStatusCode::R_400; - return; + return []; } - $response->set($request->uri->__toString(), new Redirect(UriFactory::build($found->uri))); + $response->header->status = RequestStatusCode::R_303; + $response->header->set('Location', UriFactory::build('/' . $found->uri)); + + return []; } /** diff --git a/info.json b/info.json index 291132c..6c753fe 100755 --- a/info.json +++ b/info.json @@ -20,7 +20,8 @@ "Admin": "1.0.0" }, "providing": { - "Navigation": "*" + "Navigation": "*", + "Search": "*" }, "load": [ {