8 function generate_categories(array $config)
10 $categories = Category::select('p.id, t1.title, t1.slug')
11 ->join(CategoryMetadata::class, 't1.category = p.id AND t1.language = "' . $config['language'] . '"')
12 ->where('p.parent is NULL')
13 ->fetch(\PDO::FETCH_ASSOC)
16 if (!$categories->isEmpty()) {
18 foreach ($categories->all() as $category) {
19 $sql[] = '(SELECT DISTINCT p.id, t2.title, t2.slug, p.parent FROM ' . Category::tableName() . ' as p JOIN ' . Product::tableName() . ' as t1 ON t1.category = p.id ' . (isset($config['platform']) ? ' AND t1.platform = ' . Product::PLATFORM[$config['platform']] : '') . ' JOIN ' . ProductMetadata::tableName() . ' as mt ON mt.product = t1.id AND mt.language = "' . $config['language'] . '" JOIN ' . CategoryMetadata::tableName() . ' as t2 ON t2.category = p.id AND t2.language = "' . $config['language'] . '" WHERE p.parent = ' . $category['id'] . ' LIMIT ' . ($config['subcat_limit'] ?? 10) . ')';
21 $sql = database()->prepare(join(' UNION ', $sql));
23 foreach ($sql->fetchAll(\PDO::FETCH_ASSOC) as $category) {
24 $categories->findAndPush(['id' => $category['parent']], ['subcategories' => $category]);
29 foreach ($categories->all() as $cat) {
30 if (!isset($cat['subcategories']) || (isset($cat['subcategories']) && empty($cat['subcategories']))) {
31 $empty_sql[] = '(SELECT p.category FROM ' . Product::tableName() . ' as p JOIN ' . ProductMetadata::tableName() . ' as mt ON mt.product = p.id AND mt.language = "' . $config['language'] . '" JOIN ' . CategoryMetadata::tableName() . ' as ct ON ct.category = p.category AND ct.language = "' . $config['language'] . '" WHERE p.category = ' . $cat['id'] . (isset($config['platform']) ? ' AND p.platform = ' . Product::PLATFORM[$config['platform']] : '') . ' LIMIT 1)';
376 // $product->incrementView();
378 return view('public.product', ['product' => $product, 'version' => $version]);
381 public function categories(string $language, $platform = null)
383 $this->set_lang($language);
384 guex()->set('platform', $platform);
387 return view('public.categories', ['platform' => $platform, 'language' => $language, 'categories' => generate_categories(['platform' => $platform, 'language' => $language, 'subcat_limit' => 1000])]);
390 public function CategoryProduct(string $language, string $platform, $slug = null)
392 if ($slug === null && !in_array($platform, array_keys(Product::PLATFORM))) {
397 if (!in_array($platform, array_keys(Product::PLATFORM))) {
44 return array_values($inputs);
47 protected function loadClass($callback, array $params = [])
49 if (is_array($callback) && !method_exists($callback[0], $callback[1])) {
50 throw new Exception('Method: ' . $callback[1] . ' does not exists in Class: ' . get_class($callback[0]));
53 return call_user_func($callback, ...$params);
56 protected function createClass(string $class, ...$args)
58 return new $class(...$args);
55 } elseif ($method === 'post') {
56 $callback[1] = 'store';
57 } elseif ($method === 'get' && isset($params[$action])) {
58 $callback[1] = 'show';
60 $callback[1] = 'index';
65 request()->setRoute($route);
67 return $this->loadClass($callback, $this->reflectParamiters($this->excapeParamiters($route->getParameters()), (is_array($callback) ? [$callback[0]::class, $callback[1]] : $callback)));
70 protected function callMiddlewares($middlewares): void
72 foreach ((array) $middlewares as $middleware) {
74 $class = $this->createClass($middleware);
76 if (!$class instanceof IMiddleware) {
77 throw new MiddlewareException($middleware . ' must be implement interface: ' . IMiddleware::class);
80 $this->loadClass([$class, 'handle'], $this->reflectParamiters([], [$middleware, 'handle']));
49 // call route middlewares
50 $this->callMiddlewares($route->getMiddlewares());
52 // utilize method required paramiters
53 $params = $this->utilizeRouteParam($matches, $route);
55 // set router paramiters
56 if (!empty($params)) {
57 $route->parameters($this->reflectParamiters($params, $route->getCallback()));
60 // dispatch route callback
61 return $this->dispatchRoute($route);
65 // not found any route for this path
66 // throw new NotFoundException('the route does not matched..');
70 public function route(string $name, $params = null): IRoute
72 foreach ($this->getRoutes() as $single_route) {
73 if (in_array($name, (array) $single_route->getName())) {
129 $this->triggerEvent(self::EVENT['created']);
132 public function run(): void
134 // Before Application Start Event
135 $this->triggerEvent(self::EVENT['beforeMount']);
137 // Start Application Route
138 echo $this->router->resolve();
140 // After Application Start Event
141 $this->triggerEvent(self::EVENT['mounted']);
144 public function getAuth(): Auth
146 if (!isset($this->auth)) {
147 $this->auth = new Auth;
29 // <div style="background:#000;color:#fff;padding:10px 20px;">
30 // <h3 style="font-size:25px;font-style: italic;color:blue;"></h3>
31 // <div style="border-bottom:1px solid rgba(255,255,255,0.25);padding:10px;margin-bottom:15px;">App Execution Has Started: {$started}</div>
32 // <div style="border-bottom:1px solid rgba(255,255,255,0.25);padding:10px;margin-bottom:15px;">App Execution Has End: {$end}</div>
33 // <div style="border-bottom:1px solid rgba(255,255,255,0.25);padding:10px;margin-bottom:15px;">App Total Execution: {$total}</div>
38 // run the application