@@ -22,8 +22,8 @@ |
||
| 22 | 22 | $data = []; |
| 23 | 23 | //get the categories from database |
| 24 | 24 | $categories = $this->getResultSet('categories'); |
| 25 | - foreach ( $categories as $category) { |
|
| 26 | - $data +=[ |
|
| 25 | + foreach ($categories as $category) { |
|
| 26 | + $data += [ |
|
| 27 | 27 | $category['category_name'] => '/category/'.$category['idcategories'] |
| 28 | 28 | ]; |
| 29 | 29 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $specialNamespace = array_shift($url); |
| 68 | 68 | |
| 69 | 69 | //making sure we have a single backslash |
| 70 | - $specialNamespace = rtrim($specialNamespace, '\\') . '\\'; |
|
| 70 | + $specialNamespace = rtrim($specialNamespace, '\\').'\\'; |
|
| 71 | 71 | |
| 72 | 72 | //capitalize the special namespace |
| 73 | 73 | $specialNamespace = $this->convertToStudlyCaps($specialNamespace); |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | { |
| 135 | 135 | |
| 136 | 136 | //try to create the controller object |
| 137 | - $fullControllerName = $this->currentNamespace . $this->currentController; |
|
| 137 | + $fullControllerName = $this->currentNamespace.$this->currentController; |
|
| 138 | 138 | |
| 139 | 139 | //make sure the class exists before continuing |
| 140 | 140 | if (!class_exists($fullControllerName)) { |
@@ -3,7 +3,7 @@ |
||
| 3 | 3 | |
| 4 | 4 | |
| 5 | 5 | class Home extends \Core\Controller { |
| 6 | - public function index(){ |
|
| 6 | + public function index() { |
|
| 7 | 7 | $this->view->renderTemplate('Admin/Home.twig'); |
| 8 | 8 | } |
| 9 | 9 | } |
| 10 | 10 | \ No newline at end of file |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | protected function bind($param, $value, $type = null): void |
| 66 | 66 | { |
| 67 | - if($this->stmt == null){ |
|
| 67 | + if ($this->stmt == null) { |
|
| 68 | 68 | throw new \Exception("No query to bind to"); |
| 69 | 69 | } |
| 70 | 70 | if (is_null($type)) { //need a bind value, so just check it in code. that way we can just call bind(param,value) |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | protected function execute() |
| 89 | 89 | { |
| 90 | - if($this->stmt == null){ |
|
| 90 | + if ($this->stmt == null) { |
|
| 91 | 91 | throw new \Exception("No statement to execute"); |
| 92 | 92 | } |
| 93 | 93 | return $this->stmt->execute(); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | if ($table == null) { |
| 115 | 115 | $reflect = new \ReflectionClass(get_class($this)); |
| 116 | 116 | $table = $reflect->getShortName(); //this is to only get the model name, otherwise we get the full namespace |
| 117 | - $table = $table . 's'; //adding the s since the table should be plural. Might be some special case where the plural isn't just with an s |
|
| 117 | + $table = $table.'s'; //adding the s since the table should be plural. Might be some special case where the plural isn't just with an s |
|
| 118 | 118 | $table = strtolower($table); //the database names are in lowercase |
| 119 | 119 | } |
| 120 | 120 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | //if we are here, then table doesn't exist, check for view |
| 134 | - $view = 'v_' . $table; |
|
| 134 | + $view = 'v_'.$table; |
|
| 135 | 135 | $stmt->bindValue(':table', $view, PDO::PARAM_STR); |
| 136 | 136 | $stmt->execute(); |
| 137 | 137 | $exists = $stmt->rowCount() > 0; //will return 1 if table exists or 0 if non existant |
@@ -156,10 +156,10 @@ discard block |
||
| 156 | 156 | * @throws \Exception if debugging is on and no result |
| 157 | 157 | */ |
| 158 | 158 | private function returnArray($result):array{ |
| 159 | - if($result){ |
|
| 159 | + if ($result) { |
|
| 160 | 160 | return $result; |
| 161 | 161 | } |
| 162 | - if (\App\Config::SHOW_ERRORS){ |
|
| 162 | + if (\App\Config::SHOW_ERRORS) { |
|
| 163 | 163 | throw new \Exception("No results in database"); |
| 164 | 164 | } |
| 165 | 165 | return []; |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | * @return array the results from database |
| 188 | 188 | * @throws \ReflectionException |
| 189 | 189 | */ |
| 190 | - protected function getResultSetLimited($limit,$table = ''):array{ |
|
| 190 | + protected function getResultSetLimited($limit, $table = ''):array{ |
|
| 191 | 191 | $tableName = $this->getTable($table); |
| 192 | 192 | $sql = "SELECT * FROM $tableName LIMIT :limit"; |
| 193 | 193 | $this->query($sql); |
| 194 | - $this->bind(':limit',$limit); |
|
| 194 | + $this->bind(':limit', $limit); |
|
| 195 | 195 | $this->execute(); |
| 196 | 196 | $result = $this->stmt->fetchAll(); //returns an array or false if no results |
| 197 | 197 | return $this->returnArray($result); |
@@ -203,12 +203,12 @@ discard block |
||
| 203 | 203 | * @return array result or empty array |
| 204 | 204 | * @throws \ReflectionException (probably not, but will throw an exception if debugging is on and no results) |
| 205 | 205 | */ |
| 206 | - protected function getRowById($rowId, $table=''):array{ |
|
| 206 | + protected function getRowById($rowId, $table = ''):array{ |
|
| 207 | 207 | $tableName = $this->getTable($table); |
| 208 | 208 | $idName = 'id'.$tableName; |
| 209 | 209 | $sql = "SELECT * FROM $tableName WHERE $idName = :rowId"; |
| 210 | 210 | $this->query($sql); |
| 211 | - $this->bind(':rowId',$rowId); |
|
| 211 | + $this->bind(':rowId', $rowId); |
|
| 212 | 212 | $this->execute(); |
| 213 | 213 | $result = $this->stmt->fetch(); |
| 214 | 214 | return $this->returnArray($result); |
@@ -223,10 +223,10 @@ discard block |
||
| 223 | 223 | * @throws \ReflectionException (probably not, but will throw an exception if debugging is on and no results) |
| 224 | 224 | * @throws \Exception if the column name consists of other characters than lower case, numbers and underscore for security |
| 225 | 225 | */ |
| 226 | - protected function getRowByColumn($columnName,$value,$table=''):array{ |
|
| 226 | + protected function getRowByColumn($columnName, $value, $table = ''):array{ |
|
| 227 | 227 | $tableName = $this->getTable($table); |
| 228 | 228 | $columnNameOk = preg_match("/^[a-z0-9_]+$/i", $columnName); //testing if column name only has lower case, numbers and underscore |
| 229 | - if(!$columnNameOk){ |
|
| 229 | + if (!$columnNameOk) { |
|
| 230 | 230 | throw new \Exception("Syntax error : Column name \"$columnName\" is not legal"); |
| 231 | 231 | } |
| 232 | 232 | $sql = "SELECT * FROM $tableName WHERE $columnName = :value"; |
@@ -37,7 +37,6 @@ |
||
| 37 | 37 | * @throws \Twig_Error_Syntax |
| 38 | 38 | * |
| 39 | 39 | * @return void |
| 40 | - |
|
| 41 | 40 | */ |
| 42 | 41 | public static function exceptionHandler($exception): void |
| 43 | 42 | { |
@@ -57,17 +57,17 @@ |
||
| 57 | 57 | $viewData['showErrors'] = true; //sending the config option down to twig |
| 58 | 58 | $viewData['classException'] = get_class($exception); |
| 59 | 59 | $viewData['stackTrace'] = $exception->getTraceAsString(); |
| 60 | - $viewData['thrownIn'] = $exception->getFile() . " On line " . $exception->getLine(); |
|
| 60 | + $viewData['thrownIn'] = $exception->getFile()." On line ".$exception->getLine(); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $view = new Container(); |
| 64 | 64 | |
| 65 | 65 | //Making sure that the twig template renders correctly. |
| 66 | - try{ |
|
| 66 | + try { |
|
| 67 | 67 | $twig = $view->getTemplate(); |
| 68 | - echo $twig->render('ErrorPages/'.$code . '.twig', $viewData); |
|
| 68 | + echo $twig->render('ErrorPages/'.$code.'.twig', $viewData); |
|
| 69 | 69 | //$view->renderView('ErrorPages/'.$code . '.twig', $viewData); |
| 70 | - }catch (\Exception $e){ |
|
| 70 | + } catch (\Exception $e) { |
|
| 71 | 71 | echo 'Twig Error : '.htmlspecialchars($e->getMessage()); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | $twig = $view->getTemplate(); |
| 68 | 68 | echo $twig->render('ErrorPages/'.$code . '.twig', $viewData); |
| 69 | 69 | //$view->renderView('ErrorPages/'.$code . '.twig', $viewData); |
| 70 | - }catch (\Exception $e){ |
|
| 70 | + } catch (\Exception $e){ |
|
| 71 | 71 | echo 'Twig Error : '.htmlspecialchars($e->getMessage()); |
| 72 | 72 | } |
| 73 | 73 | |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use PDO; |
| 5 | 5 | |
| 6 | 6 | |
| 7 | -class Container{ |
|
| 7 | +class Container { |
|
| 8 | 8 | |
| 9 | 9 | //used for the model connection |
| 10 | 10 | private $dbh = null; |
@@ -12,15 +12,15 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public function getTemplate() |
| 14 | 14 | { |
| 15 | - $loader = new \Twig_Loader_Filesystem(dirname(__DIR__) . '/App/Views'); |
|
| 15 | + $loader = new \Twig_Loader_Filesystem(dirname(__DIR__).'/App/Views'); |
|
| 16 | 16 | $twig = new \Twig_Environment($loader); //need to add cache |
| 17 | 17 | |
| 18 | 18 | return $twig; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | //only set once |
| 22 | - public function setPdo(){ |
|
| 23 | - if ($this->dbh){ |
|
| 22 | + public function setPdo() { |
|
| 23 | + if ($this->dbh) { |
|
| 24 | 24 | return $this->dbh; |
| 25 | 25 | } |
| 26 | 26 | $dsn = "mysql:host=".Config::DB_HOST.";dbname=".Config::DB_NAME.";charset=utf8"; //Creating the Data Source name |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
| 30 | 30 | PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC |
| 31 | 31 | ]; |
| 32 | - $this->dbh = new PDO($dsn, Config::DB_USER, Config::DB_PASSWORD, $opt);; |
|
| 32 | + $this->dbh = new PDO($dsn, Config::DB_USER, Config::DB_PASSWORD, $opt); ; |
|
| 33 | 33 | return $this->dbh; |
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | echo $twig->render($template, $args); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function getContainer(){ |
|
| 41 | + public function getContainer() { |
|
| 42 | 42 | return $this->container; |
| 43 | 43 | } |
| 44 | 44 | |