Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a27847e

Browse files
change some comment and fix problem
1 parent 05f3b8a commit a27847e

File tree

9 files changed

+132
-94
lines changed

9 files changed

+132
-94
lines changed

‎System/Database/DB/PDO.php

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22

33
/**
44
*
5-
* This file is part of simple-mvc-rest-api for PHP.
5+
* This file is part of mvc-rest-api for PHP.
66
*
77
*/
88
namespace Database\DB;
99

1010
/**
11-
* Class PDO
11+
* Global Class PDO
1212
*/
1313
final class PDO {
14+
15+
/**
16+
* @var
17+
*/
1418
private $pdo = null;
19+
20+
/**
21+
* @var
22+
*/
1523
private $statement = null;
1624

25+
/**
26+
* Construct, create opject of PDO class
27+
*/
1728
public function __construct($hostname, $username, $password, $database, $port) {
1829
try {
1930
$this->pdo = new \PDO("mysql:host=" . $hostname . ";port=" . $port . ";dbname=" . $database, $username, $password, array(\PDO::ATTR_PERSISTENT => true));
@@ -22,56 +33,30 @@ public function __construct($hostname, $username, $password, $database, $port) {
2233
exit();
2334
}
2435

36+
// set default setting database
2537
$this->pdo->exec("SET NAMES 'utf8'");
2638
$this->pdo->exec("SET CHARACTER SET utf8");
2739
$this->pdo->exec("SET CHARACTER_SET_CONNECTION=utf8");
2840
$this->pdo->exec("SET SQL_MODE = ''");
2941

3042
}
31-
32-
public function prepare($sql) {
33-
$this->statement = $this->pdo->prepare($sql);
34-
}
35-
36-
public function bindParam($parameter, $variable, $data_type = \PDO::PARAM_STR, $length = 0) {
37-
if ($length) {
38-
$this->statement->bindParam($parameter, $variable, $data_type, $length);
39-
} else {
40-
$this->statement->bindParam($parameter, $variable, $data_type);
41-
}
42-
}
43-
44-
public function execute() {
45-
try {
46-
if ($this->statement && $this->statement->execute()) {
47-
$data = array();
48-
49-
while ($row = $this->statement->fetch(\PDO::FETCH_ASSOC)) {
50-
$data[] = $row;
51-
}
52-
53-
$result = new \stdClass();
54-
$result->row = (isset($data[0])) ? $data[0] : array();
55-
$result->rows = $data;
56-
$result->num_rows = $this->statement->rowCount();
57-
}
58-
} catch(\PDOException $e) {
59-
trigger_error('Error: ' . $e->getMessage() . ' Error Code : ' . $e->getCode());
60-
}
61-
}
62-
63-
public function query($sql, $params = array()) {
43+
44+
/**
45+
* exec query statement
46+
*/
47+
public function query($sql) {
6448
$this->statement = $this->pdo->prepare($sql);
6549
$result = false;
6650

6751
try {
68-
if ($this->statement && $this->statement->execute($params)) {
52+
if ($this->statement && $this->statement->execute()) {
6953
$data = array();
7054

7155
while ($row = $this->statement->fetch(\PDO::FETCH_ASSOC)) {
7256
$data[] = $row;
7357
}
7458

59+
// create std class
7560
$result = new \stdClass();
7661
$result->row = (isset($data[0]) ? $data[0] : array());
7762
$result->rows = $data;
@@ -93,12 +78,18 @@ public function query($sql, $params = array()) {
9378
}
9479
}
9580

81+
/**
82+
* claen data
83+
*/
9684
public function escape($value) {
9785
$search = array("\\", "0円", "\n", "\r", "\x1a", "'", '"');
9886
$replace = array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"');
9987
return str_replace($search, $replace, $value);
10088
}
10189

90+
/**
91+
* return last id insert
92+
*/
10293
public function getLastId() {
10394
return $this->pdo->lastInsertId();
10495
}

‎System/Database/DatabaseAdapter.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22

33
/**
44
*
5-
* This file is part of simple-mvc-rest-api for PHP.
5+
* This file is part of mvc-rest-api for PHP.
66
*
77
*/
88
namespace Database;
99

10+
/**
11+
* Class DatabaseAdapter for handel database query
12+
*
13+
* @author Mohammad Rahmani <rto1680@gmail.com>
14+
*
15+
* @package Database
16+
*/
1017
class DatabaseAdapter {
18+
1119
/**
1220
* Database Connection
1321
*

‎System/Http/Request.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
*
5-
* This file is part of simple-mvc-rest-api for PHP.
5+
* This file is part of mvc-rest-api for PHP.
66
*
77
*/
88
namespace Http;
@@ -56,11 +56,24 @@ public function get(String $key = '') {
5656
return $this->clean($_GET);
5757
}
5858

59+
/**
60+
* Get $_POST parameter
61+
*
62+
* @param String $key
63+
* @return string
64+
*/
65+
public function post(String $key = '') {
66+
if ($key != '')
67+
return isset($_POST[$key]) ? $this->clean($_POST[$key]) : null;
68+
69+
return $this->clean($_POST);
70+
}
71+
5972
/**
6073
* Get POST parameter
6174
*
6275
* @param String $key
63-
*
76+
* @return string
6477
*/
6578
public function input(String $key = '') {
6679
$postdata = file_get_contents("php://input");
@@ -72,19 +85,6 @@ public function input(String $key = '') {
7285

7386
return ($request);
7487
}
75-
76-
/**
77-
* Get $_POST parameter
78-
*
79-
* @param String $key
80-
*
81-
*/
82-
public function post(String $key = '') {
83-
if ($key != '')
84-
return isset($_POST[$key]) ? $this->clean($_POST[$key]) : null;
85-
86-
return $this->clean($_POST);
87-
}
8888

8989
/**
9090
* Get value for server super global var

‎System/Http/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
*
5-
* This file is part of simple-mvc-rest-api for PHP.
5+
* This file is part of mvc-rest-api for PHP.
66
*
77
*/
88
namespace Http;

‎System/MVC/Controller.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
/**
44
*
5-
* This file is part of simple-mvc-rest-api for PHP.
5+
* This file is part of mvc-rest-api for PHP.
66
*
77
*/
88
namespace MVC;
99

10+
/**
11+
* Class Controller, a port of MVC
12+
*
13+
* @author Mohammad Rahmani <rto1680@gmail.com>
14+
*
15+
* @package MVC
16+
*/
1017
class Controller {
1118

1219
/**
@@ -19,6 +26,9 @@ class Controller {
1926
*/
2027
public $response;
2128

29+
/**
30+
* Construct
31+
*/
2232
public function __construct() {
2333
$this->request = $GLOBALS['request'];
2434
$this->response = $GLOBALS['response'];
@@ -34,10 +44,12 @@ public function __construct() {
3444
public function model($model) {
3545
$file = MODELS . ucfirst($model) . '.php';
3646

47+
// check exists file
3748
if (file_exists($file)) {
3849
require_once $file;
3950

4051
$model = 'Models' . str_replace('/', '', ucwords($model, '/'));
52+
// check class exists
4153
if (class_exists($model))
4254
return new $model;
4355
else
@@ -47,6 +59,7 @@ public function model($model) {
4759
}
4860
}
4961

62+
// send response faster
5063
public function send($status = 200, $msg) {
5164
$this->response->setHeader(sprintf('HTTP/1.1 ' . $status . ' %s' , $this->response->getStatusCodeText($status)));
5265
$this->response->setContent($msg);

‎System/MVC/Model.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
/**
44
*
5-
* This file is part of simple-mvc-rest-api for PHP.
5+
* This file is part of mvc-rest-api for PHP.
66
*
77
*/
88
namespace MVC;
99

10+
/**
11+
* Class Model, a port of MVC
12+
*
13+
* @author Mohammad Rahmani <rto1680@gmail.com>
14+
*
15+
* @package MVC
16+
*/
1017
class Model {
1118

1219
/**
@@ -26,5 +33,7 @@ public function __construct() {
2633
DATABASE['Name'],
2734
DATABASE['Port']
2835
);
36+
37+
$this->pagination = $GLOBALS['pagination'];
2938
}
3039
}

‎System/Router/Route.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
/**
44
*
5-
* This file is part of simple-mvc-rest-api for PHP.
5+
* This file is part of mvc-rest-api for PHP.
66
*
77
*/
88
namespace Router;
99

10+
/**
11+
* Class Route For Save Route
12+
*
13+
* @author Mohammad Rahmani <rto1680@gmail.com>
14+
*
15+
* @package Router
16+
*/
1017
final class Route {
1118

1219
/**
@@ -50,7 +57,7 @@ public function __construct(String $method, String $pattern, $callback) {
5057
* check valid method
5158
*/
5259
private function validateMethod(string $method) {
53-
if (in_array($method, $this->list_method))
60+
if (in_array(strtoupper($method), $this->list_method))
5461
return $method;
5562

5663
throw new Exception('Invalid Method Name');

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /