diff --git a/config/autoload.php b/config/autoload.php index 23ce0c6..5a375e5 100644 --- a/config/autoload.php +++ b/config/autoload.php @@ -23,9 +23,9 @@ $app_root = appDirSeparator(dirname(__DIR__)); foreach ($autoload as $src) { $folder = $app_root . '/' . $src; - $dirs = getSubDirectories($folder); + $directories = getSubDirectories($folder); $classFile = extractNamespace($class); - foreach ($dirs as $dir) { + foreach ($directories as $dir) { $file = $dir . '/' . checkFileExtension($classFile); if (is_file($file)) { require_once "$file"; diff --git a/config/init.php b/config/init.php index 1f1c73f..b91c51f 100644 --- a/config/init.php +++ b/config/init.php @@ -61,7 +61,7 @@ function serverDomain(): object * Project autoload register */ require_once $ROOT_DIR . '/config/autoload.php'; -require_once $ROOT_DIR . '/vendor/autoload.php'; +//require_once $ROOT_DIR . '/vendor/autoload.php'; /** * Project Utils */ diff --git a/src/Core/Orm/DBSelect.php b/src/Core/Orm/DBSelect.php index 007e790..1bcb15d 100644 --- a/src/Core/Orm/DBSelect.php +++ b/src/Core/Orm/DBSelect.php @@ -1,7 +1,12 @@ table = $table; $this->pdo = $pdo; @@ -79,8 +81,7 @@ public function __construct(\PDO $pdo, string $table, string $action = null) $this->_fields = ['keys' => '*']; $this->_limit = ''; $this->_offset = ''; - $this->_dsc = ''; - $this->_asc = ''; + $this->ascending = ''; $this->_between = ''; $this->include_object = []; } @@ -163,8 +164,7 @@ public function random(): DBSelect */ public function ASC(): DBSelect { - $this->_asc = ' ASC '; - $this->_dsc = ''; + $this->ascending = ' ASC '; return $this; } @@ -174,8 +174,7 @@ public function ASC(): DBSelect */ public function DESC(): DBSelect { - $this->_asc = ''; - $this->_dsc = ' DESC '; + $this->ascending = ' DESC '; return $this; } @@ -249,8 +248,12 @@ private function select() } $params = $this->where['value'] ?? []; // - $sql = "SELECT {$fields} FROM {$this->table} " . $WHERE . $this->groupBY . $this->orderBy . $this->_asc . $this->_dsc . $this->_limit . $this->_offset; - $this->query($sql, $params); + if ($this->orderBy == '' && $this->ascending != '') { + $this->result['exception'] = 'You should provide the order by which field name to which field you to apply the `' . $this->ascending . '`.'; + } else { + $sql = "SELECT {$fields} FROM {$this->table} " . $WHERE . $this->groupBY . $this->orderBy . $this->ascending . $this->_limit . $this->_offset; + $this->query($sql, $params); + } } /** @@ -292,7 +295,7 @@ protected function formatData(array $result): array } return $this->buildStructure($result, $parent_entity[0], $children_entity, $other_entity); - } catch (\Exception $ex) { + } catch (Exception $ex) { return ['exception' => $ex->getMessage()]; } } @@ -347,7 +350,7 @@ protected function buildStructure($result, string $parent_entity, array $childre $data_result[] = (object)$parent_table; } return $data_result; - } catch (\Exception $ex) { + } catch (Exception $ex) { return ['exception' => $ex->getMessage()]; } }