179 if (isset($this->select_cond['limit'])) {
180 $command .= ' LIMIT ' . trim($this->select_cond['limit']);
183 $this->select_cond['statement'] = $this->prepare($command);
185 if (isset($this->select_cond['where']['bind_and_param'])) {
186 foreach ($this->select_cond['where']['bind_and_param'] ?? [] as $key => $value) {
187 $this->select_cond['statement']->bindValue(sprintf(":%s", str_replace('.', '', $key)), $value);
191 $this->select_cond['statement']->execute();
194 public function first()
196 $this->execute_select_command();
198 if (isset($this->select_cond['fetch']) && class_exists($this->select_cond['fetch'])) {
199 $result = $this->select_cond['statement']->fetchObject($this->select_cond['fetch']);
201 $result = $this->select_cond['statement']->fetch($this->select_cond['fetch'] ?? \PDO::FETCH_OBJ);
204 $this->reset_query();
185 if (isset($this->select_cond['where']['bind_and_param'])) {
186 foreach ($this->select_cond['where']['bind_and_param'] ?? [] as $key => $value) {
187 $this->select_cond['statement']->bindValue(sprintf(":%s", str_replace('.', '', $key)), $value);
191 $this->select_cond['statement']->execute();
194 public function first()
196 $this->execute_select_command();
198 if (isset($this->select_cond['fetch']) && class_exists($this->select_cond['fetch'])) {
199 $result = $this->select_cond['statement']->fetchObject($this->select_cond['fetch']);
201 $result = $this->select_cond['statement']->fetch($this->select_cond['fetch'] ?? \PDO::FETCH_OBJ);
204 $this->reset_query();
208 public function last()
19 public static function find($condition)
21 if (__is_int($condition)) {
22 $condition = [static::primaryKey() => $condition];
25 return static::select()->where($condition)->limit(1)->first();
28 public static function total($where = null): int
30 return static::query()->select('COUNT(1)')->where($where)->fetch(\PDO::FETCH_COLUMN)->first();
33 public static function paginate(int $limit)
35 return parent::select()->paginate($limit);
38 public function hasOne(string $class, ?string $foreignKey = null)
40 return $this->hasORM($class, $foreignKey)->limit(1)->first();
43 public function hasMany(string $class, ?string $foreign = null)
493 if ($type !== null) {
494 $where .= 'p.type = ' . $type;
497 if ($platform !== null) {
498 $where .= ' AND p.platform = ' . Product::PLATFORM[$platform];
501 $paginator = Paginator::create(Product::total($where));
502 $paginator->setData(Product::select('p.*, t1.content as metadata, t1.language')->join(ProductMetadata::class, "t1.product = p.id AND t1.language = '" . $language . "'")->where('p.' . $column . ' IS NOT NULL')->order('p.' . $column . ' DESC')->limit($paginator->offset(), $paginator->limit())->get()->all());
505 return view('public.hot', ['paginator' => $paginator, 'type' => $type, 'column' => $column, 'platform' => $platform, 'language' => $language]);
508 public function SinglePage(string $language, string $slug)
510 $this->set_lang($language);
512 $page = Page::select('p.*, t1.title, t1.slug, t1.content, t1.language, t1.updated_at')
513 ->join(PostMetadata::class, 't1.post = p.id AND t1.language = "' . $language . '"')
514 ->where(['t1.slug' => $slug, 'p.type' => Page::TYPES['page']])
444 public function TopDownloads(string $language, ?string $platform = null)
446 guex()->set('platform', $platform);
448 if ($platform !== null && !in_array($platform, array_keys(Product::PLATFORM))) {
452 $this->set_lang($language);
454 return $this->show_hot_products($language, $platform, null, 'downloads');
457 public function AllGame(string $language, ?string $platform = null)
459 $platform = $platform ?? 'windows';
460 if (!in_array($platform, array_keys(Product::PLATFORM))) {
463 $this->set_lang($language);
465 return $this->show_html_map($language, $platform, Product::TYPE['game']);
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