@@ -42,7 +42,7 @@ |
||
42 | 42 | } |
43 | 43 | foreach (self::$events[$eventname] as $key => $weight) { |
44 | 44 | foreach ($weight as $callback) { |
45 | - call_user_func_array($callback, $params); |
|
45 | + call_user_func_array($callback, $params); |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | { |
70 | 70 | $table = new Table($model->getName()); |
71 | 71 | if ($this->isUsingUUID) { |
72 | - $table->addColumn('id', 'string', ['length' => 36, 'notnull' => true,]); |
|
72 | + $table->addColumn('id', 'string', ['length' => 36, 'notnull' => true, ]); |
|
73 | 73 | } else { |
74 | 74 | $table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]); |
75 | 75 | } |
@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | foreach ($model->getProperties() as $key => $value) { |
78 | 78 | if ($key != 'id') { |
79 | 79 | $type = gettype($value); |
80 | - if($type == 'string'){ |
|
80 | + if ($type == 'string') { |
|
81 | 81 | $type = 'text'; |
82 | 82 | } |
83 | - $table->addColumn($key,$type , ['notnull' => false, 'comment' => $key]); |
|
83 | + $table->addColumn($key, $type, ['notnull' => false, 'comment' => $key]); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | return $table; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | try { |
134 | 134 | $this->getTable($table_name); |
135 | 135 | return true; |
136 | - }catch(TableDoesNotExist $e){ |
|
136 | + } catch (TableDoesNotExist $e) { |
|
137 | 137 | return false; |
138 | 138 | } |
139 | 139 | } |
@@ -133,7 +133,7 @@ |
||
133 | 133 | try { |
134 | 134 | $this->getTable($table_name); |
135 | 135 | return true; |
136 | - }catch(TableDoesNotExist $e){ |
|
136 | + } catch(TableDoesNotExist $e){ |
|
137 | 137 | return false; |
138 | 138 | } |
139 | 139 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | public static function connect(array $connectionParams): DB |
27 | 27 | { |
28 | 28 | |
29 | - $connection =new Connection($connectionParams); |
|
29 | + $connection = new Connection($connectionParams); |
|
30 | 30 | self::$database = new DB($connection); |
31 | 31 | return self::$database; |
32 | 32 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param mixed $id |
68 | 68 | * @return \Scrawler\Arca\Model |
69 | 69 | */ |
70 | - public static function getOne(string $table, mixed $id): Model|null |
|
70 | + public static function getOne(string $table, mixed $id): Model | null |
|
71 | 71 | { |
72 | 72 | return self::getDB()->getOne($table, $id); |
73 | 73 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param string $sql |
78 | 78 | * @return int|numeric-string |
79 | 79 | */ |
80 | - public static function exec(string $sql): int|string |
|
80 | + public static function exec(string $sql): int | string |
|
81 | 81 | { |
82 | 82 | return self::getDB()->exec($sql); |
83 | 83 | } |
@@ -15,12 +15,12 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @var array<string> |
17 | 17 | */ |
18 | - private array $relations= []; |
|
18 | + private array $relations = []; |
|
19 | 19 | |
20 | 20 | private AbstractSchemaManager $SchemaManager; |
21 | 21 | private ModelManager $modelManager; |
22 | 22 | |
23 | - public function __construct(\Doctrine\DBAL\Connection $connection,ModelManager $modelManager) |
|
23 | + public function __construct(\Doctrine\DBAL\Connection $connection, ModelManager $modelManager) |
|
24 | 24 | { |
25 | 25 | $this->modelManager = $modelManager; |
26 | 26 | $this->SchemaManager = $connection->createSchemaManager(); |
@@ -36,12 +36,12 @@ discard block |
||
36 | 36 | public function from($table, $alias = null): QueryBuilder |
37 | 37 | { |
38 | 38 | $this->table = $table; |
39 | - return parent::from($table,$alias); |
|
39 | + return parent::from($table, $alias); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function get(): Collection |
43 | 43 | { |
44 | - if(!$this->SchemaManager->tableExists($this->table)){ |
|
44 | + if (!$this->SchemaManager->tableExists($this->table)) { |
|
45 | 45 | return Collection::fromIterable([]); |
46 | 46 | } |
47 | 47 | $model = $this->modelManager->create($this->table); |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | ->map(static fn($value): Model => ($model)->setProperties($value)->with($relations)->setLoaded()); |
56 | 56 | } |
57 | 57 | |
58 | - public function first(): Model|null |
|
58 | + public function first(): Model | null |
|
59 | 59 | { |
60 | - if(!$this->SchemaManager->tableExists($this->table)){ |
|
60 | + if (!$this->SchemaManager->tableExists($this->table)) { |
|
61 | 61 | return null; |
62 | 62 | } |
63 | 63 | $relations = $this->relations; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param string $name |
37 | 37 | * @param Connection $connection |
38 | 38 | */ |
39 | - public function __construct(string $name,Connection $connection) |
|
39 | + public function __construct(string $name, Connection $connection) |
|
40 | 40 | { |
41 | 41 | |
42 | 42 | $this->table = $name; |
@@ -128,20 +128,20 @@ discard block |
||
128 | 128 | $parts = \Safe\preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY); |
129 | 129 | if (strtolower($parts[0]) == 'own') { |
130 | 130 | if (strtolower($parts[2]) == 'list') { |
131 | - return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get(); |
|
131 | + return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get(); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | if (strtolower($parts[0]) == 'shared') { |
135 | 135 | if (strtolower($parts[2]) == 'list') { |
136 | - $rel_table = $this->connection->getTableManager()->tableExists($this->table . '_' . strtolower($parts[1])) ? $this->table . '_' . strtolower($parts[1]) : strtolower($parts[1]) . '_' . $this->table; |
|
137 | - $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get(); |
|
136 | + $rel_table = $this->connection->getTableManager()->tableExists($this->table.'_'.strtolower($parts[1])) ? $this->table.'_'.strtolower($parts[1]) : strtolower($parts[1]).'_'.$this->table; |
|
137 | + $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get(); |
|
138 | 138 | $rel_ids = ''; |
139 | 139 | foreach ($relations as $relation) { |
140 | - $key = strtolower($parts[1]) . '_id'; |
|
141 | - $rel_ids .= "'" . $relation->$key . "',"; |
|
140 | + $key = strtolower($parts[1]).'_id'; |
|
141 | + $rel_ids .= "'".$relation->$key."',"; |
|
142 | 142 | } |
143 | 143 | $rel_ids = substr($rel_ids, 0, -1); |
144 | - return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN (' . $rel_ids . ')')->get(); |
|
144 | + return $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN ('.$rel_ids.')')->get(); |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | return $this->__properties[$key]; |
151 | 151 | } |
152 | 152 | |
153 | - if (array_key_exists($key . '_id', $this->__properties)) { |
|
154 | - return $this->connection->getRecordManager()->getById($key, $this->__properties[$key . '_id']); |
|
153 | + if (array_key_exists($key.'_id', $this->__properties)) { |
|
154 | + return $this->connection->getRecordManager()->getById($key, $this->__properties[$key.'_id']); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | throw new Exception\KeyNotFoundException(); |
@@ -69,16 +69,16 @@ |
||
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
72 | - * Get single record by id |
|
73 | - * @param string $table |
|
74 | - * @param mixed $id |
|
75 | - */ |
|
72 | + * Get single record by id |
|
73 | + * @param string $table |
|
74 | + * @param mixed $id |
|
75 | + */ |
|
76 | 76 | public function getById(string $table, mixed $id): Model|null |
77 | 77 | { |
78 | 78 | $query = (new QueryBuilder($this->connection,$this->modelManager)) |
79 | - ->select('*') |
|
80 | - ->from($table, 't') |
|
81 | - ->where("t.id = '".$id."'"); |
|
79 | + ->select('*') |
|
80 | + ->from($table, 't') |
|
81 | + ->where("t.id = '".$id."'"); |
|
82 | 82 | return $query->first(); |
83 | 83 | } |
84 | 84 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * Create RecordManager |
24 | 24 | */ |
25 | - public function __construct(Connection $connection, ModelManager $modelManager,bool $isUsingUUID = false) |
|
25 | + public function __construct(Connection $connection, ModelManager $modelManager, bool $isUsingUUID = false) |
|
26 | 26 | { |
27 | 27 | $this->connection = $connection; |
28 | 28 | $this->isUsingUUID = $isUsingUUID; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public function insert(Model $model) : mixed |
38 | 38 | { |
39 | 39 | if ($this->isUsingUUID) { |
40 | - $model->set('id',UUID::uuid4()->toString()); |
|
40 | + $model->set('id', UUID::uuid4()->toString()); |
|
41 | 41 | } |
42 | 42 | $this->connection->insert($model->getName(), $model->getProperties()); |
43 | 43 | if ($this->isUsingUUID) { |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | * @param string $table |
74 | 74 | * @param mixed $id |
75 | 75 | */ |
76 | - public function getById(string $table, mixed $id): Model|null |
|
76 | + public function getById(string $table, mixed $id): Model | null |
|
77 | 77 | { |
78 | - $query = (new QueryBuilder($this->connection,$this->modelManager)) |
|
78 | + $query = (new QueryBuilder($this->connection, $this->modelManager)) |
|
79 | 79 | ->select('*') |
80 | 80 | ->from($table, 't') |
81 | 81 | ->where("t.id = '".$id."'"); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function getAll(string $tableName): Collection |
91 | 91 | { |
92 | - return (new QueryBuilder($this->connection,$this->modelManager)) |
|
92 | + return (new QueryBuilder($this->connection, $this->modelManager)) |
|
93 | 93 | ->select('*') |
94 | 94 | ->from($tableName, 't') |
95 | 95 | ->get(); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function find(String $name) : QueryBuilder |
103 | 103 | { |
104 | - return (new QueryBuilder($this->connection,$this->modelManager)) |
|
104 | + return (new QueryBuilder($this->connection, $this->modelManager)) |
|
105 | 105 | ->select('*') |
106 | 106 | ->from($name, 't'); |
107 | 107 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | */ |
34 | 34 | function setConnection(Connection $connection): void |
35 | 35 | { |
36 | - $this->connection = $connection; |
|
36 | + $this->connection = $connection; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | } |
40 | 40 | \ No newline at end of file |
@@ -24,7 +24,7 @@ |
||
24 | 24 | */ |
25 | 25 | function create(string $name): Model |
26 | 26 | { |
27 | - return new Model($name,$this->connection); |
|
27 | + return new Model($name, $this->connection); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function registerEvents(): void |
40 | 40 | { |
41 | - Event::subscribeTo('system.model.save.'.$this->connection->getConnectionId(), function ($model) { |
|
41 | + Event::subscribeTo('system.model.save.'.$this->connection->getConnectionId(), function($model) { |
|
42 | 42 | return $this->save($model); |
43 | 43 | }); |
44 | - Event::subscribeTo('system.model.delete.'.$this->connection->getConnectionId(), function ($model) { |
|
44 | + Event::subscribeTo('system.model.delete.'.$this->connection->getConnectionId(), function($model) { |
|
45 | 45 | return $this->delete($model); |
46 | 46 | }); |
47 | 47 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param array<mixed> $params |
54 | 54 | * @return int|numeric-string |
55 | 55 | */ |
56 | - public function exec(string $sql, array $params=array()): int|string |
|
56 | + public function exec(string $sql, array $params = array()): int | string |
|
57 | 57 | { |
58 | 58 | return $this->connection->executeStatement($sql, $params); |
59 | 59 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param array<mixed> $params |
66 | 66 | * @return array<int,array<string,mixed>> |
67 | 67 | */ |
68 | - public function getAll(string $sql, array $params=[]): array |
|
68 | + public function getAll(string $sql, array $params = []): array |
|
69 | 69 | { |
70 | 70 | return $this->connection->executeQuery($sql, $params)->fetchAllAssociative(); |
71 | 71 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | try { |
100 | 100 | $id = $this->createRecords($model); |
101 | - $model->set('id',$id); |
|
101 | + $model->set('id', $id); |
|
102 | 102 | $model->setLoaded(); |
103 | 103 | $this->connection->commit(); |
104 | 104 | } catch (\Exception $e) { |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @param mixed $id |
273 | 273 | * @return Model |
274 | 274 | */ |
275 | - public function getOne(string $table, mixed $id) : Model|null |
|
275 | + public function getOne(string $table, mixed $id) : Model | null |
|
276 | 276 | { |
277 | 277 | return $this->connection->getRecordManager()->getById($table, $id); |
278 | 278 | } |