Skip to content

Commit

Permalink
Load routes by app
Browse files Browse the repository at this point in the history
  • Loading branch information
givanz committed Oct 18, 2024
1 parent 1b40950 commit 8a8e9f4
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 25 deletions.
7 changes: 7 additions & 0 deletions config/admin-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,13 @@
'module' => 'settings/email',
'action' => 'index',
],
'rest' => [
'name' => __('Rest Api'),
'icon' => 'la la-database',
'url' => $admin_path . '?module=settings/email',
'module' => 'settings/email',
'action' => 'index',
],
],
],
],
Expand Down
45 changes: 23 additions & 22 deletions config/routes.php → config/app-routes.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
'/user/wishlist/add/#product_id#' => ['module' => 'user/wishlist/add'],
'/user/wishlist/remove/#product_id#' => ['module' => 'user/wishlist/remove'],

//user digital assets
'/user/downloads/download/{customer_order_id}-{key}-{public}-#digital_asset_id#' => ['module' => 'user/downloads/download'],

'/user' => ['module' => 'user/index'],

//search
Expand All @@ -65,11 +68,6 @@
'/search/{search}/#page#' => ['module' => 'search'],
'/search/{search}/{type}/#page#' => ['module' => 'search'],

//rest api
'/rest/' => ['module' => 'rest'],
'/rest/{method}' => ['module' => 'rest'],
'/rest/{method}/{id}' => ['module' => 'rest'],

//ecommerce

//catalog
Expand All @@ -86,23 +84,24 @@
'/vendor/{slug}/#page#' => ['module' => 'product/vendor/index'],
'/vendor' => ['module' => 'product/vendor/index'],
'/vendor/#page#' => ['module' => 'product/vendor/index'],
'/product/{slug}' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&slug={slug}'],
//'/product/{slug}' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&slug={slug}'],
'/product/{slug}-#product_id#' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&product_id={product_id}'],

//compare
'/cart/compare' => ['module' => 'cart/compare/index'],
'/cart/compare/add/#product_id#' => ['module' => 'cart/compare/add'],
'/cart/compare/remove/#product_id#' => ['module' => 'cart/compare/remove'],

//multi language catalog - language code must be at least 2 characters
'/{language{2,5}}/shop' => ['module' => 'product/index'],
'/{language{2,5}}/shop/#page#' => ['module' => 'product/index'],
'/{language{2,5}}/shop/{slug}' => ['module' => 'product/category/index'],
'/{language{2,5}}/shop/{slug}/#page#' => ['module' => 'product/category/index'],
'/{language{2,5}}/shop/{slug}/#page#/filters-{filters}' => ['module' => 'product/category/index'],
'/{language{2,5}}/manufacturer/{slug}' => ['module' => 'product/manufacturer/index'],
'/{language{2,5}}/vendor/{slug}' => ['module' => 'product/vendor/index'],
'/{language{2,5}}/vendor/{slug}/#page#' => ['module' => 'product/vendor/index'],
'/{language{2,5}}/product/{slug}' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&slug={slug}'],
'/{language{2,5}}/shop' => ['module' => 'product/index'],
'/{language{2,5}}/shop/#page#' => ['module' => 'product/index'],
'/{language{2,5}}/shop/{slug}' => ['module' => 'product/category/index'],
'/{language{2,5}}/shop/{slug}/#page#' => ['module' => 'product/category/index'],
'/{language{2,5}}/shop/{slug}/#page#/filters-{filters}' => ['module' => 'product/category/index'],
'/{language{2,5}}/manufacturer/{slug}' => ['module' => 'product/manufacturer/index'],
'/{language{2,5}}/vendor/{slug}' => ['module' => 'product/vendor/index'],
'/{language{2,5}}/vendor/{slug}/#page#' => ['module' => 'product/vendor/index'],
'/{language{2,5}}/product/{slug}-#product_id#' => ['module' => 'product/product/index', 'edit'=>'?module=product/product&product_id={product_id}'],

//checkout
'/cart' => ['module' => 'cart/cart/index'],
Expand Down Expand Up @@ -142,21 +141,23 @@

//post
//'/#year{4,4}#-#month{1,2}#-#day#/{slug}' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&slug={slug}'],
'/{slug}' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&slug={slug}&type=post'],
//'/{slug}' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&slug={slug}&type=post'],
'/{slug}-#post_id#' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&post_id={post_id}&type=post'],
//page
//'/{slug}' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&slug={slug}'],
'/page/{slug}' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&slug={slug}&type=page'],
//'/page/{slug}' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&slug={slug}&type=page'],
'/page/{slug}-#post_id#' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&post_id={post_id}&type=page'],

//multi language content - language code must be at least 2 characters
'/{language{2,5}}/' => ['module' => 'index/index'],
//pagination for blog posts
'/{language{2,5}}/p/#page#' => ['module' => 'index/index'],
//content
'/{language{2,5}}/blog' => ['module' => 'content'],
'/{language{2,5}}/cat/{slug}' => ['module' => 'content/category/language'],
'/{language{2,5}}/tag/{slug}' => ['module' => 'content/tag/index'],
'/{language{2,5}}/{slug}' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&slug={slug}'],
'/{language{2,5}}/page/{slug}' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&slug={slug}'],
'/{language{2,5}}/blog' => ['module' => 'content'],
'/{language{2,5}}/cat/{slug}' => ['module' => 'content/category/language'],
'/{language{2,5}}/tag/{slug}' => ['module' => 'content/tag/index'],
'/{language{2,5}}/{slug}-#post_id#' => ['module' => 'content/post/index', 'edit'=>'?module=content/post&post_id={post_id}'],
'/{language{2,5}}/page/{slug}-#post_id#' => ['module' => 'content/page/index', 'edit'=>'?module=content/post&post_id={post_id}'],

'/{language{2,5}}/tag/{slug}' => ['module' => 'content/tag/index'],
'/{language{2,5}}/tag/{slug}/#page#' => ['module' => 'content/tag/index'],
Expand Down
104 changes: 104 additions & 0 deletions config/rest-routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

/**
* Vvveb
*
* Copyright (C) 2022 Ziadin Givan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

return [
'/rest/' => ['module' => 'index'],

//posts
'/rest/posts' => ['module' => 'posts'],
'/rest/posts/#post_id#' => ['module' => 'posts/post/index'],
'/rest/posts/{slug}' => ['module' => 'posts/post/index'],
//revisions
'/rest/posts/#post_id#/revisions' => ['module' => 'posts/revisions/index'],
'/rest/posts/#post_id#/revisions/{created_at}' => ['module' => 'posts/revision/index'],
//pages

//comments
'/rest/posts/#post_id#/comments' => ['module' => 'posts/comments/index'],
'/rest/posts/#post_id#/comments/{created_at}' => ['module' => 'posts/comment/index'],

//media
'/rest/media' => ['module' => 'media'],
'/rest/media/{file}' => ['module' => 'media/media/index'],

//menus
'/rest/menus' => ['module' => 'menus'],
'/rest/menus/{menu_id}' => ['module' => 'menus/v/index'],
//menu-items
'/rest/menu-items' => ['module' => 'menu-items'],
'/rest/menu-items/{menu_id}' => ['module' => 'menu-items/menu-items/index'],

//taxonomies
'/rest/taxonomies' => ['module' => 'taxonomies'],
'/rest/taxonomies/{menu_id}' => ['module' => 'taxonomies/taxonomies/index'],
//tags
//categories

//users
'/rest/users' => ['module' => 'users'],
'/rest/users/#user_id#' => ['module' => 'users/user/index'],

//search
'/rest/search' => ['module' => 'search'],

//settings
'/rest/settings' => ['module' => 'settings'],

//themes
'/rest/themes' => ['module' => 'settings'],
'/rest/themes/{slug}' => ['module' => 'themes/themes/index'],

//plugins
'/rest/plugins' => ['module' => 'plugins'],
'/rest/plugins/{slug}' => ['module' => 'plugins/plugins/index'],

//languages

//ecommerce

//products
'/rest/products' => ['module' => 'products'],
'/rest/products/#product_id#' => ['module' => 'products/product/index'],
'/rest/products/{slug}' => ['module' => 'products/products/index'],

//product attributes
//product reviews
//product questions
//taxonomies
//tags
//categories

//orders
//coupons
//tax rates
//tax classes
//tax types
//returns
//zones
//countries
//currencies

//payment methods
//shipping methods

//stats
];
1 change: 1 addition & 0 deletions config/sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
'state' => 'live',
'template' => '',
'id' => 1,
'site_id' => 1,
],
];
6 changes: 3 additions & 3 deletions system/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Routes {

private static $routes = [];

private static $urls = null;
private static $urls = [];

private static $modules = null;

Expand Down Expand Up @@ -102,8 +102,8 @@ public static function removeRoute($url) {
}
}

public static function init() {
self :: $routes += include DIR_ROOT . '/config/routes.php';
public static function init($app = 'app') {
self :: $routes += include DIR_ROOT . "/config/$app-routes.php";
list(self :: $routes) = Event::trigger(__CLASS__, __FUNCTION__ , self :: $routes);

foreach (self :: $routes as $url => $data) {
Expand Down

0 comments on commit 8a8e9f4

Please sign in to comment.