@@ -58,7 +58,7 @@ |
||
58 | 58 | { |
59 | 59 | $table = new Table($model->getName()); |
60 | 60 | if ($this->db->isUsingUUID()) { |
61 | - $table->addColumn('id', 'string', ['length' => 36, 'notnull' => true,]); |
|
61 | + $table->addColumn('id', 'string', ['length' => 36, 'notnull' => true, ]); |
|
62 | 62 | } else { |
63 | 63 | $table->addColumn("id", "integer", array("unsigned" => true, "autoincrement" => true)); |
64 | 64 | } |
@@ -7,7 +7,7 @@ |
||
7 | 7 | private string $table; |
8 | 8 | private Database $db; |
9 | 9 | |
10 | - public function __construct(Database $db){ |
|
10 | + public function __construct(Database $db) { |
|
11 | 11 | $this->db = $db; |
12 | 12 | parent::__construct($this->db->connection); |
13 | 13 |
@@ -12,12 +12,12 @@ |
||
12 | 12 | * Create RecordManager |
13 | 13 | * @param \Scrawler\Arca\Database $db |
14 | 14 | */ |
15 | - public function __construct(Database $db){ |
|
15 | + public function __construct(Database $db) { |
|
16 | 16 | $this->db = $db; |
17 | 17 | } |
18 | 18 | |
19 | - public function create(string $name){ |
|
20 | - return new Model($name,$this->db); |
|
19 | + public function create(string $name) { |
|
20 | + return new Model($name, $this->db); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | } |
24 | 24 | \ No newline at end of file |
@@ -67,18 +67,18 @@ |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
70 | - * Get single record by id |
|
71 | - * |
|
72 | - * @param \Scrawler\Arca\Model $model |
|
73 | - * @return \Scrawler\Arca\Model |
|
74 | - */ |
|
70 | + * Get single record by id |
|
71 | + * |
|
72 | + * @param \Scrawler\Arca\Model $model |
|
73 | + * @return \Scrawler\Arca\Model |
|
74 | + */ |
|
75 | 75 | public function getById(Model $model, mixed $id): Model |
76 | 76 | { |
77 | 77 | $qb = new QueryBuilder($this->db); |
78 | 78 | $query = $qb |
79 | - ->select('*') |
|
80 | - ->from($model->getName(), 't') |
|
81 | - ->where("t.id = '".$id."'"); |
|
79 | + ->select('*') |
|
80 | + ->from($model->getName(), 't') |
|
81 | + ->where("t.id = '".$id."'"); |
|
82 | 82 | $result = $this->db->connection->executeQuery($query)->fetchAssociative(); |
83 | 83 | $result = $result ? $result : []; |
84 | 84 | $model->setProperties($result)->setLoaded(); |
@@ -75,7 +75,7 @@ |
||
75 | 75 | public function getById(Model $model, mixed $id): Model |
76 | 76 | { |
77 | 77 | $qb = new QueryBuilder($this->db); |
78 | - $query = $qb |
|
78 | + $query = $qb |
|
79 | 79 | ->select('*') |
80 | 80 | ->from($model->getName(), 't') |
81 | 81 | ->where("t.id = '".$id."'"); |
@@ -11,24 +11,24 @@ |
||
11 | 11 | class Database { |
12 | 12 | private static $database; |
13 | 13 | |
14 | - public static function connect(array $connectionParams){ |
|
14 | + public static function connect(array $connectionParams) { |
|
15 | 15 | |
16 | - if(self::$database == null) |
|
16 | + if (self::$database == null) |
|
17 | 17 | { |
18 | 18 | $connection = \Doctrine\DBAL\DriverManager::getConnection($connectionParams); |
19 | 19 | self::$database = new DB($connection); |
20 | - self::$database->setManagers(new TableManager(self::$database),new RecordManager(self::$database),new ModelManager(self::$database)); |
|
20 | + self::$database->setManagers(new TableManager(self::$database), new RecordManager(self::$database), new ModelManager(self::$database)); |
|
21 | 21 | return self::$database; |
22 | 22 | } |
23 | 23 | |
24 | 24 | return self::$database; |
25 | 25 | } |
26 | 26 | |
27 | - private static function getDB(){ |
|
27 | + private static function getDB() { |
|
28 | 28 | return self::$database; |
29 | 29 | } |
30 | 30 | |
31 | - public static function create($name){ |
|
31 | + public static function create($name) { |
|
32 | 32 | return getDB()->create($name); |
33 | 33 | } |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function __set(string $key, mixed $val): void |
34 | 34 | { |
35 | - $this->set($key,$val); |
|
35 | + $this->set($key,$val); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function set(string $key,mixed $val): void |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | public function __get(string $key): mixed |
72 | 72 | { |
73 | - return $this->get($key); |
|
73 | + return $this->get($key); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | public function get(string $key){ |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function __isset(string $key): bool |
128 | 128 | { |
129 | - return $this->isset($key); |
|
129 | + return $this->isset($key); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function __set(string $key, mixed $val): void |
34 | 34 | { |
35 | - $this->set($key,$val); |
|
35 | + $this->set($key, $val); |
|
36 | 36 | } |
37 | 37 | |
38 | - public function set(string $key,mixed $val): void |
|
38 | + public function set(string $key, mixed $val): void |
|
39 | 39 | { |
40 | 40 | //bug: fix issue with bool storage |
41 | 41 | if (gettype($val) == 'boolean') { |
@@ -73,23 +73,23 @@ discard block |
||
73 | 73 | return $this->get($key); |
74 | 74 | } |
75 | 75 | |
76 | - public function get(string $key){ |
|
76 | + public function get(string $key) { |
|
77 | 77 | |
78 | 78 | if (preg_match('/[A-Z]/', $key)) { |
79 | 79 | $parts = preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY); |
80 | 80 | if (strtolower($parts[0]) == 'own') { |
81 | - if (strtolower($parts[2]) == 'list') { |
|
82 | - return $this->db->find(strtolower($parts[1]))->where($this->getName() . '_id = "' . $this->_id.'"')->get(); |
|
81 | + if (strtolower($parts[2]) == 'list') { |
|
82 | + return $this->db->find(strtolower($parts[1]))->where($this->getName().'_id = "'.$this->_id.'"')->get(); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | if (strtolower($parts[0]) == 'shared') { |
86 | - if (strtolower($parts[2]) == 'list') { |
|
86 | + if (strtolower($parts[2]) == 'list') { |
|
87 | 87 | $rel_table = $this->db->getTableManager()->tableExists($this->table.'_'.strtolower($parts[1])) ? $this->table.'_'.strtolower($parts[1]) : strtolower($parts[1]).'_'.$this->table; |
88 | - $relations = $this->db->find($rel_table)->where($this->getName() . '_id = "' . $this->_id.'"')->get(); |
|
88 | + $relations = $this->db->find($rel_table)->where($this->getName().'_id = "'.$this->_id.'"')->get(); |
|
89 | 89 | $rel_ids = ''; |
90 | 90 | foreach ($relations as $relation) { |
91 | - $key = strtolower($parts[1]) . '_id'; |
|
92 | - $rel_ids .= "'".$relation->$key . "',"; |
|
91 | + $key = strtolower($parts[1]).'_id'; |
|
92 | + $rel_ids .= "'".$relation->$key."',"; |
|
93 | 93 | } |
94 | 94 | $rel_ids = substr($rel_ids, 0, -1); |
95 | 95 | return $this->db->find(strtolower($parts[1]))->where('id IN ('.$rel_ids.')')->get(); |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | } |
29 | 29 | |
30 | - public function setManagers(TableManager $tableManager, RecordManager $recordManager, ModelManager $modelManager){ |
|
30 | + public function setManagers(TableManager $tableManager, RecordManager $recordManager, ModelManager $modelManager) { |
|
31 | 31 | $this->tableManager = $tableManager; |
32 | 32 | $this->recordManager = $recordManager; |
33 | 33 | $this->modelManager = $modelManager; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param array $params |
42 | 42 | * @return integer |
43 | 43 | */ |
44 | - public function exec(string $sql, array $params=array()): int |
|
44 | + public function exec(string $sql, array $params = array()): int |
|
45 | 45 | { |
46 | 46 | return $this->connection->executeStatement($sql, $params); |
47 | 47 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param array $params |
54 | 54 | * @return array |
55 | 55 | */ |
56 | - public function getAll(string $sql, array $params=[]): array |
|
56 | + public function getAll(string $sql, array $params = []): array |
|
57 | 57 | { |
58 | 58 | return $this->connection->executeQuery($sql, $params)->fetchAllAssociative(); |
59 | 59 | } |
@@ -233,11 +233,11 @@ discard block |
||
233 | 233 | * @param mixed|null $id |
234 | 234 | * @return mixed |
235 | 235 | */ |
236 | - public function get(String $table,mixed $id = null) : Model|Collection |
|
236 | + public function get(String $table, mixed $id = null) : Model | Collection |
|
237 | 237 | { |
238 | 238 | // For backward compatibility reason |
239 | - if($id != null){ |
|
240 | - return $this->getOne($table,$id); |
|
239 | + if ($id != null) { |
|
240 | + return $this->getOne($table, $id); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | return $this->recordManager->getAll($table); |