@@ -55,6 +55,6 @@ |
||
55 | 55 | $output = new StreamOutput($this->stream); |
56 | 56 | $output->writeln('foo'); |
57 | 57 | rewind($output->getStream()); |
58 | - $this->assertEquals('foo'.PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream'); |
|
58 | + $this->assertEquals('foo' . PHP_EOL, stream_get_contents($output->getStream()), '->doWrite() writes to the stream'); |
|
59 | 59 | } |
60 | 60 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $this->application->setAutoExit(false); |
27 | 27 | $this->application->register('foo') |
28 | 28 | ->addArgument('foo') |
29 | - ->setCode(function ($input, $output) { $output->writeln('foo'); }) |
|
29 | + ->setCode(function($input, $output) { $output->writeln('foo'); }) |
|
30 | 30 | ; |
31 | 31 | |
32 | 32 | $this->tester = new ApplicationTester($this->application); |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | public function testGetOutput() |
55 | 55 | { |
56 | 56 | rewind($this->tester->getOutput()->getStream()); |
57 | - $this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance'); |
|
57 | + $this->assertEquals('foo' . PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public function testGetDisplay() |
61 | 61 | { |
62 | - $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution'); |
|
62 | + $this->assertEquals('foo' . PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution'); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | public function testGetStatusCode() |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | $this->command = new Command('foo'); |
27 | 27 | $this->command->addArgument('command'); |
28 | 28 | $this->command->addArgument('foo'); |
29 | - $this->command->setCode(function ($input, $output) { $output->writeln('foo'); }); |
|
29 | + $this->command->setCode(function($input, $output) { $output->writeln('foo'); }); |
|
30 | 30 | |
31 | 31 | $this->tester = new CommandTester($this->command); |
32 | 32 | $this->tester->execute(array('foo' => 'bar'), array('interactive' => false, 'decorated' => false, 'verbosity' => Output::VERBOSITY_VERBOSE)); |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | public function testGetOutput() |
54 | 54 | { |
55 | 55 | rewind($this->tester->getOutput()->getStream()); |
56 | - $this->assertEquals('foo'.PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance'); |
|
56 | + $this->assertEquals('foo' . PHP_EOL, stream_get_contents($this->tester->getOutput()->getStream()), '->getOutput() returns the current output instance'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function testGetDisplay() |
60 | 60 | { |
61 | - $this->assertEquals('foo'.PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution'); |
|
61 | + $this->assertEquals('foo' . PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution'); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | public function testGetStatusCode() |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $application->setAutoExit(false); |
73 | 73 | |
74 | 74 | $command = new Command('foo'); |
75 | - $command->setCode(function ($input, $output) { $output->writeln('foo'); }); |
|
75 | + $command->setCode(function($input, $output) { $output->writeln('foo'); }); |
|
76 | 76 | |
77 | 77 | $application->add($command); |
78 | 78 |
@@ -18,6 +18,9 @@ |
||
18 | 18 | return $results[0]; |
19 | 19 | } |
20 | 20 | |
21 | + /** |
|
22 | + * @param string $field |
|
23 | + */ |
|
21 | 24 | public static function where($field, $value) { |
22 | 25 | $obj = null; |
23 | 26 | self::getConnection(); |
@@ -8,23 +8,23 @@ discard block |
||
8 | 8 | self::getConnection(); |
9 | 9 | } |
10 | 10 | |
11 | - private static function getConnection (){ |
|
11 | + private static function getConnection() { |
|
12 | 12 | require_once('Database.php'); |
13 | 13 | self::$database = Database::getConnection(DB_PROVIDER, DB_HOST, DB_USER, DB_PASSWORD, DB_DB); |
14 | 14 | } |
15 | 15 | |
16 | 16 | public static function find($id) { |
17 | - $results = self::where('id',$id); |
|
17 | + $results = self::where('id', $id); |
|
18 | 18 | return $results[0]; |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function where($field, $value) { |
22 | 22 | $obj = null; |
23 | 23 | self::getConnection(); |
24 | - $query = "SELECT * FROM ".static::$table." WHERE ".$field." = ?"; |
|
25 | - $results = self::$database->execute($query,null,array($value)); |
|
24 | + $query = "SELECT * FROM " . static::$table . " WHERE " . $field . " = ?"; |
|
25 | + $results = self::$database->execute($query, null, array($value)); |
|
26 | 26 | |
27 | - if ($results){ |
|
27 | + if ($results) { |
|
28 | 28 | $class = get_called_class(); |
29 | 29 | for ($i = 0; $i < sizeof($results); $i++) { |
30 | 30 | $obj[] = new $class($results[$i]); |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | $objs = null; |
39 | 39 | self::getConnection(); |
40 | 40 | |
41 | - $query = "SELECT * FROM ".static::$table; |
|
41 | + $query = "SELECT * FROM " . static::$table; |
|
42 | 42 | |
43 | - if ($order){ |
|
43 | + if ($order) { |
|
44 | 44 | $query .= $order; |
45 | 45 | } |
46 | 46 | |
47 | - $results = self::$database->execute($query,null, null); |
|
47 | + $results = self::$database->execute($query, null, null); |
|
48 | 48 | |
49 | - if ($results){ |
|
49 | + if ($results) { |
|
50 | 50 | $class = get_called_class(); |
51 | - foreach ($results as $index => $obj){ |
|
51 | + foreach ($results as $index => $obj) { |
|
52 | 52 | $objs[] = new $class($obj); |
53 | 53 | } |
54 | 54 | } |
@@ -56,33 +56,33 @@ discard block |
||
56 | 56 | return $objs; |
57 | 57 | } |
58 | 58 | |
59 | - public function save(){ |
|
59 | + public function save() { |
|
60 | 60 | $values = get_object_vars($this); |
61 | 61 | $filtered = null; |
62 | 62 | |
63 | - foreach ($values as $key => $value){ |
|
64 | - if ($value !== null && $value !== '' && strpos($key,'obj_') === false |
|
65 | - && $key !== 'id'){ |
|
63 | + foreach ($values as $key => $value) { |
|
64 | + if ($value !== null && $value !== '' && strpos($key, 'obj_') === false |
|
65 | + && $key !== 'id') { |
|
66 | 66 | if ($value === false) { $value = 0; } |
67 | 67 | $filtered[$key] = $value; |
68 | 68 | } |
69 | 69 | } |
70 | 70 | $columns = array_keys($filtered); |
71 | 71 | |
72 | - if ($this->id){ |
|
73 | - $columns = join (" = ?, ", $columns); |
|
72 | + if ($this->id) { |
|
73 | + $columns = join(" = ?, ", $columns); |
|
74 | 74 | $columns .= ' = ?'; |
75 | - $query = "UPDATE ".static::$table." SET $columns WHERE id =".$this->id; |
|
75 | + $query = "UPDATE " . static::$table . " SET $columns WHERE id =" . $this->id; |
|
76 | 76 | } |
77 | 77 | else { |
78 | 78 | $params = join(", ", array_fill(0, count($columns), "?")); |
79 | 79 | $columns = join(", ", $columns); |
80 | - $query = "INSERT INTO ".static::$table." ($columns) VALUES ($params)"; |
|
80 | + $query = "INSERT INTO " . static::$table . " ($columns) VALUES ($params)"; |
|
81 | 81 | } |
82 | 82 | |
83 | - $result = self::$database->execute($query,null,$filtered); |
|
83 | + $result = self::$database->execute($query, null, $filtered); |
|
84 | 84 | |
85 | - if ($result){ |
|
85 | + if ($result) { |
|
86 | 86 | $result = array('error' => false, 'message' => self::$database->getInsertedID()); |
87 | 87 | } |
88 | 88 | else { |
@@ -73,8 +73,7 @@ discard block |
||
73 | 73 | $columns = join (" = ?, ", $columns); |
74 | 74 | $columns .= ' = ?'; |
75 | 75 | $query = "UPDATE ".static::$table." SET $columns WHERE id =".$this->id; |
76 | - } |
|
77 | - else { |
|
76 | + } else { |
|
78 | 77 | $params = join(", ", array_fill(0, count($columns), "?")); |
79 | 78 | $columns = join(", ", $columns); |
80 | 79 | $query = "INSERT INTO ".static::$table." ($columns) VALUES ($params)"; |
@@ -84,8 +83,7 @@ discard block |
||
84 | 83 | |
85 | 84 | if ($result){ |
86 | 85 | $result = array('error' => false, 'message' => self::$database->getInsertedID()); |
87 | - } |
|
88 | - else { |
|
86 | + } else { |
|
89 | 87 | $result = array('error' => true, 'message' => self::$database->getError()); |
90 | 88 | } |
91 | 89 |
@@ -4,49 +4,49 @@ |
||
4 | 4 | |
5 | 5 | class MySqlProvider extends DatabaseProvider |
6 | 6 | { |
7 | - public function connect($host, $user, $pass, $dbname){ |
|
7 | + public function connect($host, $user, $pass, $dbname) { |
|
8 | 8 | $this->resource = new mysqli($host, $user, $pass, $dbname); |
9 | 9 | |
10 | - if ($this->resource->connect_errno){ // Connection fails |
|
10 | + if ($this->resource->connect_errno) { // Connection fails |
|
11 | 11 | error_log($this->resource->connect_error); |
12 | 12 | } |
13 | 13 | |
14 | 14 | return $this->resource; |
15 | 15 | } |
16 | - public function disconnect(){ |
|
16 | + public function disconnect() { |
|
17 | 17 | return $this->resource->close(); |
18 | 18 | } |
19 | - public function getErrorNo(){ |
|
19 | + public function getErrorNo() { |
|
20 | 20 | return $this->resource->errno; |
21 | 21 | } |
22 | - public function getError(){ |
|
22 | + public function getError() { |
|
23 | 23 | return $this->resource->error; |
24 | 24 | } |
25 | - public function query($q){ |
|
25 | + public function query($q) { |
|
26 | 26 | return $this->resource->query($q); |
27 | 27 | } |
28 | - public function numRows($resource){ |
|
28 | + public function numRows($resource) { |
|
29 | 29 | $num_rows = 0; |
30 | 30 | |
31 | - if ($resource){ |
|
31 | + if ($resource) { |
|
32 | 32 | $num_rows = $resource->num_rows; |
33 | 33 | } |
34 | 34 | |
35 | 35 | return $num_rows; |
36 | 36 | } |
37 | - public function fetchArray($result){ |
|
37 | + public function fetchArray($result) { |
|
38 | 38 | return $result->fetch_assoc(); |
39 | 39 | } |
40 | - public function isConnected(){ |
|
40 | + public function isConnected() { |
|
41 | 41 | return !is_null($this->resource); |
42 | 42 | } |
43 | - public function escape($var){ |
|
43 | + public function escape($var) { |
|
44 | 44 | return $this->resource->real_escape_string($var); |
45 | 45 | } |
46 | - public function getInsertedID(){ |
|
46 | + public function getInsertedID() { |
|
47 | 47 | return $this->resource->insert_id; |
48 | 48 | } |
49 | - public function changeDB ($database){ |
|
49 | + public function changeDB($database) { |
|
50 | 50 | return $this->resource->select_db($database); |
51 | 51 | } |
52 | 52 | public function setCharset($charset) { |
@@ -3,7 +3,7 @@ |
||
3 | 3 | { |
4 | 4 | protected $resource; |
5 | 5 | public abstract function connect($host, $user, $pass, $dbname); |
6 | - public abstract function disconnect (); |
|
6 | + public abstract function disconnect(); |
|
7 | 7 | public abstract function getErrorNo(); |
8 | 8 | public abstract function getError(); |
9 | 9 | public abstract function query($q); |
@@ -4,49 +4,49 @@ |
||
4 | 4 | |
5 | 5 | class MySqlProvider extends DatabaseProvider |
6 | 6 | { |
7 | - public function connect($host, $user, $pass, $dbname){ |
|
7 | + public function connect($host, $user, $pass, $dbname) { |
|
8 | 8 | $this->resource = new mysqli($host, $user, $pass, $dbname); |
9 | 9 | |
10 | - if ($this->resource->connect_errno){ // Connection fails |
|
10 | + if ($this->resource->connect_errno) { // Connection fails |
|
11 | 11 | error_log($this->resource->connect_error); |
12 | 12 | } |
13 | 13 | |
14 | 14 | return $this->resource; |
15 | 15 | } |
16 | - public function disconnect(){ |
|
16 | + public function disconnect() { |
|
17 | 17 | return $this->resource->close(); |
18 | 18 | } |
19 | - public function getErrorNo(){ |
|
19 | + public function getErrorNo() { |
|
20 | 20 | return $this->resource->errno; |
21 | 21 | } |
22 | - public function getError(){ |
|
22 | + public function getError() { |
|
23 | 23 | return $this->resource->error; |
24 | 24 | } |
25 | - public function query($q){ |
|
25 | + public function query($q) { |
|
26 | 26 | return $this->resource->query($q); |
27 | 27 | } |
28 | - public function numRows($resource){ |
|
28 | + public function numRows($resource) { |
|
29 | 29 | $num_rows = 0; |
30 | 30 | |
31 | - if ($resource){ |
|
31 | + if ($resource) { |
|
32 | 32 | $num_rows = $resource->num_rows; |
33 | 33 | } |
34 | 34 | |
35 | 35 | return $num_rows; |
36 | 36 | } |
37 | - public function fetchArray($result){ |
|
37 | + public function fetchArray($result) { |
|
38 | 38 | return $result->fetch_assoc(); |
39 | 39 | } |
40 | - public function isConnected(){ |
|
40 | + public function isConnected() { |
|
41 | 41 | return !is_null($this->resource); |
42 | 42 | } |
43 | - public function escape($var){ |
|
43 | + public function escape($var) { |
|
44 | 44 | return $this->resource->real_escape_string($var); |
45 | 45 | } |
46 | - public function getInsertedID(){ |
|
46 | + public function getInsertedID() { |
|
47 | 47 | return $this->resource->insert_id; |
48 | 48 | } |
49 | - public function changeDB ($database){ |
|
49 | + public function changeDB($database) { |
|
50 | 50 | return $this->resource->select_db($database); |
51 | 51 | } |
52 | 52 | public function setCharset($charset) { |
@@ -4,49 +4,49 @@ |
||
4 | 4 | |
5 | 5 | class MySqlProvider extends DatabaseProvider |
6 | 6 | { |
7 | - public function connect($host, $user, $pass, $dbname){ |
|
7 | + public function connect($host, $user, $pass, $dbname) { |
|
8 | 8 | $this->resource = new mysqli($host, $user, $pass, $dbname); |
9 | 9 | |
10 | - if ($this->resource->connect_errno){ // Connection fails |
|
10 | + if ($this->resource->connect_errno) { // Connection fails |
|
11 | 11 | error_log($this->resource->connect_error); |
12 | 12 | } |
13 | 13 | |
14 | 14 | return $this->resource; |
15 | 15 | } |
16 | - public function disconnect(){ |
|
16 | + public function disconnect() { |
|
17 | 17 | return $this->resource->close(); |
18 | 18 | } |
19 | - public function getErrorNo(){ |
|
19 | + public function getErrorNo() { |
|
20 | 20 | return $this->resource->errno; |
21 | 21 | } |
22 | - public function getError(){ |
|
22 | + public function getError() { |
|
23 | 23 | return $this->resource->error; |
24 | 24 | } |
25 | - public function query($q){ |
|
25 | + public function query($q) { |
|
26 | 26 | return $this->resource->query($q); |
27 | 27 | } |
28 | - public function numRows($resource){ |
|
28 | + public function numRows($resource) { |
|
29 | 29 | $num_rows = 0; |
30 | 30 | |
31 | - if ($resource){ |
|
31 | + if ($resource) { |
|
32 | 32 | $num_rows = $resource->num_rows; |
33 | 33 | } |
34 | 34 | |
35 | 35 | return $num_rows; |
36 | 36 | } |
37 | - public function fetchArray($result){ |
|
37 | + public function fetchArray($result) { |
|
38 | 38 | return $result->fetch_assoc(); |
39 | 39 | } |
40 | - public function isConnected(){ |
|
40 | + public function isConnected() { |
|
41 | 41 | return !is_null($this->resource); |
42 | 42 | } |
43 | - public function escape($var){ |
|
43 | + public function escape($var) { |
|
44 | 44 | return $this->resource->real_escape_string($var); |
45 | 45 | } |
46 | - public function getInsertedID(){ |
|
46 | + public function getInsertedID() { |
|
47 | 47 | return $this->resource->insert_id; |
48 | 48 | } |
49 | - public function changeDB ($database){ |
|
49 | + public function changeDB($database) { |
|
50 | 50 | return $this->resource->select_db($database); |
51 | 51 | } |
52 | 52 | public function setCharset($charset) { |