mirror of
https://github.com/Karaka-Management/oms-Navigation.git
synced 2026-01-28 08:08:41 +00:00
Went through todos
This commit is contained in:
parent
d8f98ea8c4
commit
bd5c9ded95
|
|
@ -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<string, 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, '<?php return [];');
|
||||
}
|
||||
|
||||
if (!\is_file($destPath)) {
|
||||
throw new PathException($destPath); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if (!\is_writable($destPath)) {
|
||||
throw new PermissionException($destPath); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if (!isset(self::$nav[$destPath])) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
self::$nav[$destPath] = include $destPath;
|
||||
}
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
$language = include $srcPath;
|
||||
|
||||
self::$nav[$destPath] = \array_merge_recursive(self::$nav[$destPath], $language);
|
||||
|
||||
\file_put_contents($destPath, '<?php return ' . ArrayParser::serializeArray(self::$nav[$destPath]) . ';', \LOCK_EX);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use phpOMS\Account\PermissionType;
|
|||
use phpOMS\Router\RouteVerb;
|
||||
|
||||
return [
|
||||
'^:goto (\?.*$|$)' => [
|
||||
'^:goto (.+)$' => [
|
||||
[
|
||||
'dest' => '\Modules\Navigation\Controller\SearchController:searchGoto',
|
||||
'verb' => RouteVerb::ANY,
|
||||
|
|
|
|||
|
|
@ -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 [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user